| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.web.controller.common; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.http.HttpUtils; |
| | | import com.ruoyi.common.utils.sign.Md5Utils; |
| | | import com.ruoyi.project.domain.GiApi; |
| | | import com.ruoyi.project.domain.dto.ApiDTO; |
| | | import com.ruoyi.project.domain.dto.SmsDTO; |
| | | import com.ruoyi.project.service.IApiService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.ArrayList; |
| | | import java.util.Base64; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Api(description = "çä¿¡æå¡") |
| | | @RestController |
| | | @RequestMapping("/sms") |
| | | public class SmsController { |
| | | private String url="http://103.21.119.249:3131/http/send.aspx"; |
| | | private String loginName="qddxfsyy"; |
| | | private String passWord="Qyfy_0718"; |
| | | @ApiOperation("çä¿¡æå¡->åéçä¿¡") |
| | | @PostMapping("/send") |
| | | public AjaxResult getApiList(@RequestBody SmsDTO DTO) { |
| | | if (ObjectUtils.isNotEmpty(DTO.getTel())&&ObjectUtils.isNotEmpty(DTO.getMessageContent())) { |
| | | String key= keyForMd5(loginName.toLowerCase(),passWord.toLowerCase()); |
| | | key="5b2d0edb45ac3583543fbf55d8af1e6d"; |
| | | String content="{\"LoginName\":\""+loginName+"\",\"PassWord\":\""+passWord+"\"," + |
| | | "\"Key\":\""+key+"\"," + |
| | | "\"Tel\":\""+DTO.getTel()+"\",\"MessageContent\":\""+DTO.getMessageContent()+"\"}"; |
| | | String result= HttpUtils.sendPost(url, Base64.getEncoder().encodeToString(content.getBytes()) ); |
| | | return AjaxResult.success(result); |
| | | } else { |
| | | return AjaxResult.error("çµè¯åæ¶æ¯ä¸è½ä¸ºç©º"); |
| | | } |
| | | } |
| | | public String keyForMd5(String name, String pass) |
| | | { |
| | | return md5(md5(pass) + pass + md5(name)); |
| | | } |
| | | |
| | | |
| | | public static String md5(String str) { |
| | | |
| | | return hashPasswordForStoring(str,"MD5"); |
| | | } |
| | | |
| | | public static String SHA1(String str) { |
| | | |
| | | return hashPasswordForStoring(str,"SHA1"); |
| | | } |
| | | |
| | | public static String hashPasswordForStoring(String password, String algorithm) { |
| | | try { |
| | | // 1. è·ååå¸ç®æ³å®ä¾ |
| | | MessageDigest md = MessageDigest.getInstance(algorithm); |
| | | // 2. å¯ç 转 UTF-8 åèï¼å .NET å®å
¨ä¸è´ï¼ |
| | | byte[] passwordBytes = password.getBytes(StandardCharsets.UTF_8); |
| | | // 3. 计ç®åå¸ |
| | | byte[] hashBytes = md.digest(passwordBytes); |
| | | // 4. 转为大ååå
è¿å¶å符串ï¼å .NET è¾åºæ ¼å¼ä¸è´ï¼ |
| | | return bytesToHexUpperCase(hashBytes); |
| | | |
| | | } catch (NoSuchAlgorithmException e) { |
| | | throw new RuntimeException("䏿¯æçåå¸ç®æ³: " + algorithm, e); |
| | | } |
| | | } |
| | | private static String bytesToHexUpperCase(byte[] bytes) { |
| | | StringBuilder sb = new StringBuilder(); |
| | | for (byte b : bytes) { |
| | | // 转两ä½å¤§ååå
è¿å¶ |
| | | sb.append(String.format("%02X", b)); |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | |
| | | } |