| | |
| | | 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 com.ruoyi.common.utils.SmsUtils; |
| | | 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) { |
| | | public AjaxResult Send(@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); |
| | | SmsUtils sms=new SmsUtils(); |
| | | return AjaxResult.success(sms.send(DTO.getTel(),DTO.getMessageContent())); |
| | | } 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(); |
| | | } |
| | | |
| | | } |