陈昶聿
昨天 a993043a20a6c9bccb0ab563e2d955b36a801408
ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/SmsController.java
@@ -1,23 +1,28 @@
package com.ruoyi.web.controller.common;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.ruoyi.common.annotation.AddOrgId;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.dx.MessageSend;
import com.ruoyi.common.enums.BusinessType;
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.ruoyi.common.utils.sms.SmsUtils;
import com.ruoyi.system.service.ISysConfigService;
import com.smartor.common.MtSubmitSmUtil;
import com.smartor.common.ShiyiSmsUtil;
import com.smartor.domain.ServiceOutPath;
import com.smartor.domain.ShiyiSmsRequest;
import com.smartor.domain.ShiyiSmsResponse;
import com.smartor.domain.smsVO;
import com.smartor.domain.*;
import com.smartor.mapper.UtilsMapper;
import com.smartor.service.IServiceOutPathService;
import com.smartor.service.IServiceSubtaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
@@ -71,6 +76,10 @@
    @Autowired
    private IServiceOutPathService iServiceOutPathService;
    @Autowired
    private IServiceSubtaskService iServiceSubtaskService;
    @Autowired
    private ISysConfigService configService;
    @Value("${spring.profiles.active}")
    private String active;
@@ -82,7 +91,7 @@
    @ApiOperation("短信发送")
    @PostMapping("/sendTest")
    public AjaxResult send(@RequestBody smsVO vo) {
        String sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), vo.getContent());
        String sendMsg = SmsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), vo.getContent());
        return AjaxResult.success(sendMsg);
    }
@@ -106,6 +115,12 @@
    @PostMapping("/send")
    public AjaxResult sendAsk(@RequestBody smsVO vo) throws UnsupportedEncodingException {
        String content = "";
        if (StringUtils.isNotEmpty(vo.getSubId())) {
            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
            if (serviceSubtask.getSendstate() == 4L) content = "该任务不执行";
            return AjaxResult.error(content);
        }
        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
@@ -121,7 +136,7 @@
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            String url = ip + ":" + req_path + "/wt?p=" + format;
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
@@ -132,7 +147,7 @@
        String sendMsg = "false";
        try {
            if (active.equals("hzszlyy")) {
                sendMsg = smsUtils.sendSms(xhsmsPath, xhsmsAccount, xhsmsPwd, vo.getPhone(), content);
                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")) {
@@ -193,8 +208,13 @@
     */
    @ApiOperation("微信发送")
    @PostMapping("/sendChat")
    public AjaxResult sendChat(@RequestBody smsVO vo) throws UnsupportedEncodingException {
    public AjaxResult sendChat(@RequestBody smsVO vo) {
        String sendMsg = "";
        if (StringUtils.isNotEmpty(vo.getSubId())) {
            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
            if (serviceSubtask.getSendstate() == 4L) sendMsg = "该任务不执行";
            return AjaxResult.error(sendMsg);
        }
        if (StringUtils.isNotEmpty(vo.getTaskId()) && StringUtils.isNotEmpty(vo.getPatId()) && StringUtils.isNotEmpty(vo.getSubId())) {
            RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
            String taskId = rsaPublicKeyExample.encryptedData(vo.getTaskId().toString(), pub_key);
@@ -211,8 +231,8 @@
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
            String url = ip + ":" + req_path + "/wt?p=" + format;
            sendMsg = smsUtils.sendChat(url, vo.getPhone(), vo.getIdCard());
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
            sendMsg = SmsUtils.sendChat(url, vo.getPhone(), vo.getIdCard());
        }
        return AjaxResult.success(sendMsg);
    }
@@ -240,13 +260,89 @@
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            String url = ip + ":" + req_path + "/wt?p=" + format;
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
//            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            content = url;
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        }
        if (StringUtils.isNotEmpty(vo.getSubId())) {
            ServiceSubtask serviceSubtask = iServiceSubtaskService.selectServiceSubtaskById(Long.valueOf(vo.getSubId()));
            if (serviceSubtask.getSendstate() == 4L) content = "该任务不执行";
        }
        return AjaxResult.success(content);
    }
    /**
     * @param
     * @return
     */
    @ApiOperation("短信发送")
    @AddOrgId
    @PostMapping("/sendYunMasSms")
    public AjaxResult sendYunMasSms(@RequestBody smsVO vo) throws Exception {
        String yunMasConfigJson = configService.selectConfigByKey("ls.msg.yunmas", vo.getOrgid());
        SmsUtils.YunMasConfig yunMasConfig = SmsUtils.YunMasConfig.of(yunMasConfigJson);
        SmsUtils.SmsResult smsResult = SmsUtils.sendYunMasSms(yunMasConfig, vo.getPhone(), vo.getContent());
        return AjaxResult.success(smsResult);
    }
    /**
     * 丽水妇幼 微信消息发送
     * <p>
     * 外部系统传入患者信息和通知内容,由本系统统一获取 token、解析模板并调用丽水微信 sendMessage 接口。
     *
     * @param request 微信消息请求
     * @return 发送结果
     */
    @Anonymous
    @ApiOperation(value = "丽水妇幼 微信消息发送", notes = "供丽水市妇幼保健院外部调用")
    @Log(title = "丽水妇幼微信消息发送", businessType = BusinessType.OTHER)
    @PostMapping("/sendChatFuyou")
    public AjaxResult sendChatFuyou(@RequestBody LishuiFuyouWxChatRequest request) {
        if (request == null) {
            return AjaxResult.error("请求参数不能为空");
        }
        try {
            SmsUtils.LsWxConfig config = SmsUtils.LsWxConfig.defaultLishui();
            SmsUtils.LsWxMessage message = new SmsUtils.LsWxMessage();
            message.setId(request.getTemplateId());
            message.setPatientId(request.getPatientId());
            message.setPatientName(request.getPatientName());
            message.setIdCard(request.getIdCard());
            message.setMobile(request.getMobile());
            message.setMedCardNo(request.getMedCardNo());
            message.setTitleName(request.getTitleName());
            message.setContent(request.getContent());
            message.setUrl(request.getUrl());
            log.info("【丽水妇幼微信】收到外部调用,手机号:{},模板ID:{}",
                    request.getMobile(), request.getTemplateId());
            String resp = SmsUtils.sendChatLs(config, message);
            log.info("【丽水妇幼微信】外部调用结果:{}", resp);
            JSONObject result;
            try {
                result = JSON.parseObject(resp);
            } catch (Exception e) {
                log.error("【丽水妇幼微信】第三方响应不是合法JSON:{}", resp, e);
                return AjaxResult.error("丽水妇幼微信发送失败:第三方响应异常", resp);
            }
            if (result == null) {
                return AjaxResult.error("丽水妇幼微信发送失败:第三方响应为空", resp);
            }
            if (result.getIntValue("code") != 0) {
                String msg = result.getString("msg");
                return AjaxResult.error("丽水妇幼微信发送失败:"
                        + (StringUtils.isEmpty(msg) ? "第三方接口返回失败" : msg), result);
            }
            return AjaxResult.success("发送成功", result);
        } catch (Exception e) {
            log.error("【丽水妇幼微信】外部调用异常,手机号:{}", request.getMobile(), e);
            return AjaxResult.error("丽水妇幼微信发送异常:" + e.getMessage());
        }
    }
}