liusheng
8 天以前 a1e256f64930865ae2d170e333ee3f1a773c6c49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.ruoyi.web.controller.common;
 
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.RSAPublicKeyExample;
import com.ruoyi.common.utils.StringUtils;
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.service.IServiceOutPathService;
import com.smartor.service.IServiceSubtaskService;
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.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.UnsupportedEncodingException;
import java.util.Date;
 
/**
 * 知信接口(对外短信 / 微信公众号发送入口)。
 * <p>
 * 说明:短信与公众号的站点差异(报文格式、签名、token、返回判定)已全部收口到
 * {@code ruoyi-message} 模块,本类只负责参数组装与按 {@code active} 路由。
 */
@RestController
@Api(description = "知信接口")
@RequestMapping("/sms")
@Slf4j
public class SmsController {
 
    @Autowired
    private SmsSenderFactory smsSenderFactory;
 
    @Autowired
    private WechatSenderFactory wechatSenderFactory;
 
    @Autowired
    private ShiyiSmsUtil shiyiSmsUtil;
 
    @Value("${localIP}")
    private String ip;
 
    @Value("${req_path}")
    private String req_path;
 
    @Value("${pub_key}")
    private String pub_key;
 
    @Autowired
    private IServiceOutPathService iServiceOutPathService;
    @Autowired
    private IServiceSubtaskService iServiceSubtaskService;
 
    @Value("${spring.profiles.active}")
    private String active;
 
    /**
     * 短信发送(测试)
     */
    @ApiOperation("短信发送")
    @PostMapping("/sendTest")
    public AjaxResult send(@RequestBody smsVO vo) {
        //与原实现一致:测试接口固定走市一(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测试")
    @PostMapping("/sendShiyiTest")
    public AjaxResult sendShiyiTest(@RequestBody ShiyiSmsRequest request) {
        try {
            ShiyiSmsResponse response = shiyiSmsUtil.sendSms(request);
            return AjaxResult.success(response);
        } catch (Exception e) {
            log.error("市一HIS短信XML测试失败", e);
            return AjaxResult.error("市一HIS短信XML测试失败: " + e.getMessage());
        }
    }
 
    /**
     * 短信发送
     */
    @ApiOperation("短信发送")
    @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);
            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
            Integer radix = iServiceOutPathService.selectAutoId();
            String format = String.format("%03X", radix);
            ServiceOutPath serviceOutPath = new ServiceOutPath();
            serviceOutPath.setParam1(taskId);
            serviceOutPath.setParam2(patid);
            serviceOutPath.setParam3(vo.getTaskName());
            serviceOutPath.setParam6(subId);
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        }
 
        if (ObjectUtils.isNotEmpty(vo.getContent())) content = vo.getContent();
 
        String sendMsg = "false";
        try {
            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());
        }
        return AjaxResult.success(sendMsg);
    }
 
    /**
     * 微信发送
     */
    @ApiOperation("微信发送")
    @PostMapping("/sendChat")
    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);
            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
            Integer radix = iServiceOutPathService.selectAutoId();
            String format = String.format("%03X", radix);
            ServiceOutPath serviceOutPath = new ServiceOutPath();
            serviceOutPath.setParam1(taskId);
            serviceOutPath.setParam2(patid);
            serviceOutPath.setParam3(vo.getTaskName());
            serviceOutPath.setParam6(subId);
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
            String url = StringUtils.isNotEmpty(req_path) ? ip + ":" + req_path + "/wt?p=" + format : ip + "/wt?p=" + format;
            //与原实现一致:该接口固定走市一公众号
            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);
    }
 
    /**
     * 生成外链
     */
    @ApiOperation("生成外链")
    @PostMapping("/getUrl")
    public AjaxResult getUrl(@RequestBody smsVO vo) throws UnsupportedEncodingException {
        String 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);
            String patid = rsaPublicKeyExample.encryptedData(vo.getPatId().toString(), pub_key);
            String subId = rsaPublicKeyExample.encryptedData(vo.getSubId().toString(), pub_key);
            Integer radix = iServiceOutPathService.selectAutoId();
            String format = String.format("%03X", radix);
            ServiceOutPath serviceOutPath = new ServiceOutPath();
            serviceOutPath.setParam1(taskId);
            serviceOutPath.setParam2(patid);
            serviceOutPath.setParam3(vo.getTaskName());
            serviceOutPath.setParam6(subId);
            serviceOutPath.setRadix(format);
            serviceOutPath.setCreateTime(new Date());
            serviceOutPath.setOrgid(vo.getOrgid());
            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);
    }
 
}