| | |
| | | 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.Base64; |
| | | import com.ruoyi.common.utils.sign.Md5Utils; |
| | | import com.ruoyi.project.domain.GiApi; |
| | | import com.ruoyi.project.domain.dto.ApiDTO; |
| | |
| | | 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; |
| | | |
| | |
| | | @PostMapping("/send") |
| | | public AjaxResult getApiList(@RequestBody SmsDTO DTO) { |
| | | if (ObjectUtils.isNotEmpty(DTO.getTel())&&ObjectUtils.isNotEmpty(DTO.getMessageContent())) { |
| | | String key= Md5Utils.hash(Md5Utils.hash(passWord.toLowerCase())+passWord.toLowerCase()+Md5Utils.hash(loginName.toLowerCase())); |
| | | 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.encode(content.getBytes()) ); |
| | | 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(); |
| | | } |
| | | |
| | | } |