陈昶聿
14 小时以前 f3434f830cfee5838211e58a3a361c73f7166342
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
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.smartor.domain.ServiceOutPath;
import com.smartor.domain.ShiyiSmsRequest;
import com.smartor.domain.ShiyiSmsResponse;
import com.smartor.domain.smsVO;
import com.smartor.mapper.UtilsMapper;
import com.smartor.service.IServiceOutPathService;
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.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
@RestController
@Api(description = "知信接口")
@RequestMapping("/sms")
@Slf4j
public class SmsController {
    @Value("${xhsmsPath}")
    private String xhsmsPath;
 
    @Autowired
    private MtSubmitSmUtil mtSubmitSmUtil;
 
    @Autowired
    private ShiyiSmsUtil shiyiSmsUtil;
 
    @Value("${xhsmsAccount}")
    private String xhsmsAccount;
 
    @Value("${xhsmsPwd}")
    private String xhsmsPwd;
    // 虚拟接入码
    @Value("${xhsmsjrm}")
    private String xhsmsjrm;
 
    @Value("${localIP}")
    private String ip;
 
    @Value("${req_path}")
    private String req_path;
 
    @Value("${pub_key}")
    private String pub_key;
 
    @Autowired
    private IServiceOutPathService iServiceOutPathService;
 
    @Value("${spring.profiles.active}")
    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);
    }
 
    @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());
        }
    }
 
    /**
     * @param
     * @return
     */
    @ApiOperation("短信发送")
    @PostMapping("/send")
    public AjaxResult sendAsk(@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 = ip + ":" + req_path + "/wt?p=" + format;
            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        }
 
        if (ObjectUtils.isNotEmpty(vo.getContent())) content = vo.getContent();
 
        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家医院,有点不方便,有空再接
                return AjaxResult.error("该短信功能还未开通");
            }
            log.info(sendMsg);
        } catch (Exception ex) {
            log.error(ex.getMessage());
        }
        return AjaxResult.success(sendMsg);
    }
 
    /**
     * @param
     * @return
     */
    @ApiOperation("微信发送")
    @PostMapping("/sendChat")
    public AjaxResult sendChat(@RequestBody smsVO vo) throws UnsupportedEncodingException {
        String 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 = ip + ":" + req_path + "/wt?p=" + format;
            sendMsg = smsUtils.sendChat(url, vo.getPhone(), vo.getIdCard());
        }
        return AjaxResult.success(sendMsg);
    }
 
    /**
     * @param
     * @return
     */
    @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 = ip + ":" + req_path + "/wt?p=" + format;
//            content = "您好,邀请您填写出院调查表,请点击" + url + "填写。感谢您配合!";
            content = url;
            serviceOutPath.setUrl(url);
            iServiceOutPathService.insertServiceOutPath(serviceOutPath);
        }
        return AjaxResult.success(content);
    }
 
}