liusheng
2026-10-10 0afac42fb2e9d6e5291304dd0044ce3042b45d2b
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
@@ -1,19 +1,17 @@
package com.ruoyi.web.controller.common;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.dx.MessageSend;
import com.ruoyi.common.utils.HttpUtil;
import com.ruoyi.common.utils.RSAPublicKeyExample;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.sms.smsUtils;
import com.smartor.common.MtSubmitSmUtil;
import com.smartor.common.ShiyiSmsUtil;
import com.ruoyi.message.SendResult;
import com.ruoyi.message.sms.SmsSendRequest;
import com.ruoyi.message.sms.SmsSenderFactory;
import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsRequest;
import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsResponse;
import com.ruoyi.message.sms.provider.shiyi.ShiyiSmsUtil;
import com.ruoyi.message.wechat.WechatSendRequest;
import com.ruoyi.message.wechat.WechatSenderFactory;
import com.smartor.domain.*;
import com.smartor.mapper.UtilsMapper;
import com.smartor.service.IServiceOutPathService;
import com.smartor.service.IServiceSubtaskService;
import io.swagger.annotations.Api;
@@ -28,35 +26,28 @@
import org.springframework.web.bind.annotation.RestController;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * 知信接口(对外短信 / 微信公众号发送入口)。
 * <p>
 * 说明:短信与公众号的站点差异(报文格式、签名、token、返回判定)已全部收口到
 * {@code ruoyi-message} 模块,本类只负责参数组装与按 {@code active} 路由。
 */
@RestController
@Api(description = "知信接口")
@RequestMapping("/sms")
@Slf4j
public class SmsController {
    @Value("${xhsmsPath}")
    private String xhsmsPath;
    @Autowired
    private MtSubmitSmUtil mtSubmitSmUtil;
    private SmsSenderFactory smsSenderFactory;
    @Autowired
    private WechatSenderFactory wechatSenderFactory;
    @Autowired
    private ShiyiSmsUtil shiyiSmsUtil;
    @Value("${xhsmsAccount}")
    private String xhsmsAccount;
    @Value("${xhsmsPwd}")
    private String xhsmsPwd;
    // 虚拟接入码
    @Value("${xhsmsjrm}")
    private String xhsmsjrm;
    @Value("${localIP}")
    private String ip;
@@ -76,14 +67,16 @@
    private String active;
    /**
     * @param
     * @return
     * 短信发送(测试)
     */
    @ApiOperation("短信发送")
    @PostMapping("/sendTest")
    public AjaxResult send(@RequestBody smsVO vo) {
        String sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), vo.getContent());
        return AjaxResult.success(sendMsg);
        //与原实现一致:测试接口固定走市一(smsUtils.sendSms,吴山签名)
        SmsSendRequest request = SmsSendRequest.of(vo.getPhone(), vo.getContent());
        request.setCampus("2");
        SendResult sendResult = smsSenderFactory.send("hzszlyy", request);
        return AjaxResult.success(sendResult.getRawResponse());
    }
    @ApiOperation("市一HIS短信XML测试")
@@ -99,8 +92,7 @@
    }
    /**
     * @param
     * @return
     * 短信发送
     */
    @ApiOperation("短信发送")
    @PostMapping("/send")
@@ -137,55 +129,14 @@
        String sendMsg = "false";
        try {
            if (active.equals("hzszlyy")) {
                sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), content);
            } else if (active.equals("nhfy")) {
                Map<String, Object> smsResult = mtSubmitSmUtil.submitSm(vo.getPhone(), content);
                if (smsResult != null && smsResult.get("result") != null && smsResult.get("result").toString().equals("0")) {
                    sendMsg = "true";
                }
            } else if (active.equals("sltd")) {
                String data = MessageSend.sendMsg(content, "6", vo.getPhone(), LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")));
                if (StringUtils.isNotEmpty(data)) {
                    ObjectMapper mapper = new ObjectMapper();
                    JsonNode root = mapper.readTree(data);
                    String status = root.get("result").get(0).get("status").asText();
                    if (status.equals("00000")) {
                        sendMsg = "true";
                    }
                }
            } else if (active.equals("xh")) {
//                Map<String, String> req = new HashMap<>();
//                req.put("phone", vo.getPhone());
//                req.put("content", vo.getContent());
//                Boolean result = HttpUtil.postJsonRequest(xhsmsPath, new Gson().toJson(req));
                Map<String, String> map2 = new HashMap<String, String>();
                map2.put("action", "send");
                map2.put("account", xhsmsAccount);
                map2.put("password", xhsmsPwd);
                map2.put("mobile", vo.getPhone());
                map2.put("content", vo.getContent());
                map2.put("extno", xhsmsjrm);
                map2.put("rt", "json");
                StringBuilder encodedParams = new StringBuilder();
                for (Map.Entry<String, String> entry : map2.entrySet()) {
                    if (encodedParams.length() > 0) {
                        encodedParams.append("&");
                    }
                    // 对键和值进行URL编码
                    String encodedKey = URLEncoder.encode(entry.getKey(), "UTF-8");
                    String encodedValue = URLEncoder.encode(entry.getValue(), "UTF-8");
                    encodedParams.append(encodedKey).append("=").append(encodedValue);
                }
                Boolean result = HttpUtils.sendPost(xhsmsPath, encodedParams.toString());
                if (result) {
                    sendMsg = "true";
                }
            } else if (active.equals("ls")) {
                //丽水13家医院,有点不方便,有空再接
            if ("ls".equals(active)) {
                //与原实现一致:丽水13家医院的短信功能标记为未开通
                return AjaxResult.error("该短信功能还未开通");
            }
            SmsSendRequest request = SmsSendRequest.of(vo.getPhone(), content, vo.getOrgid());
            //市一区分湖滨/吴山签名,此接口无院区信息,与原实现一致(非湖滨即吴山)
            SendResult sendResult = smsSenderFactory.send(active, request);
            sendMsg = sendResult.asLegacyFlag();
            log.info(sendMsg);
        } catch (Exception ex) {
            log.error(ex.getMessage());
@@ -194,8 +145,7 @@
    }
    /**
     * @param
     * @return
     * 微信发送
     */
    @ApiOperation("微信发送")
    @PostMapping("/sendChat")
@@ -223,14 +173,20 @@
            serviceOutPath.setOrgid(vo.getOrgid());
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
            sendMsg = smsUtils.sendChat(url, vo.getPhone(), vo.getIdCard());
            //与原实现一致:该接口固定走市一公众号
            WechatSendRequest request = new WechatSendRequest();
            request.setIdCard(vo.getIdCard());
            request.setPhone(vo.getPhone());
            request.setUrl(url);
            request.setOrgid(vo.getOrgid());
            SendResult sendResult = wechatSenderFactory.send("hzszlyy", request);
            sendMsg = sendResult.getRawResponse();
        }
        return AjaxResult.success(sendMsg);
    }
    /**
     * @param
     * @return
     * 生成外链
     */
    @ApiOperation("生成外链")
    @PostMapping("/getUrl")