|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+package com.ruoyi.wisdomarbitrate.service.shortmessage.impl;
|
|
|
2
|
+
|
|
|
3
|
+import cn.hutool.json.JSONObject;
|
|
|
4
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
5
|
+import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
6
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
7
|
+import com.ruoyi.common.enums.SMSStatusEnum;
|
|
|
8
|
+import com.ruoyi.common.utils.SmsUtils;
|
|
|
9
|
+import com.ruoyi.system.domain.entity.shortmessage.EncryptendInfo;
|
|
|
10
|
+import com.ruoyi.system.domain.entity.shortmessage.MsSmsSendHistoryRecord;
|
|
|
11
|
+import com.ruoyi.system.mapper.shortmessage.EncryptendInfoMapper;
|
|
|
12
|
+import com.ruoyi.system.mapper.shortmessage.MsSmsSendHistoryRecordMapper;
|
|
|
13
|
+import com.ruoyi.wisdomarbitrate.domain.dto.sendrecord.SmsSendRecord;
|
|
|
14
|
+import com.ruoyi.wisdomarbitrate.domain.vo.secret.SecretInfo;
|
|
|
15
|
+import com.ruoyi.wisdomarbitrate.service.shortmessage.ShortMessageService;
|
|
|
16
|
+import org.springframework.beans.BeanUtils;
|
|
|
17
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
18
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
19
|
+import org.springframework.stereotype.Service;
|
|
|
20
|
+
|
|
|
21
|
+import java.util.UUID;
|
|
|
22
|
+
|
|
|
23
|
+import static com.ruoyi.common.utils.EncryptUtils.sm4Decrypt;
|
|
|
24
|
+import static com.ruoyi.common.utils.EncryptUtils.sm4Encrypt;
|
|
|
25
|
+
|
|
|
26
|
+@Service
|
|
|
27
|
+public class ShortMessageServiceImpl implements ShortMessageService {
|
|
|
28
|
+ @Value("${shortMessageKey}")
|
|
|
29
|
+ private String shortMessageKey;
|
|
|
30
|
+ @Autowired
|
|
|
31
|
+ MsSmsSendHistoryRecordMapper msSmsSendHistoryRecordMapper;
|
|
|
32
|
+ @Autowired
|
|
|
33
|
+ EncryptendInfoMapper encryptendInfoMapper;
|
|
|
34
|
+
|
|
|
35
|
+ /**
|
|
|
36
|
+ * 新增发送历史记录
|
|
|
37
|
+ *
|
|
|
38
|
+ * @param smsSendRecord
|
|
|
39
|
+ */
|
|
|
40
|
+ @Override
|
|
|
41
|
+ public void insertShortMessageHistoryRecord(SmsSendRecord smsSendRecord) {
|
|
|
42
|
+ if (smsSendRecord != null) {
|
|
|
43
|
+ MsSmsSendHistoryRecord historyRecord = new MsSmsSendHistoryRecord();
|
|
|
44
|
+ BeanUtils.copyProperties(smsSendRecord, historyRecord);
|
|
|
45
|
+ historyRecord.setId(null);
|
|
|
46
|
+ historyRecord.setParentId(smsSendRecord.getId());
|
|
|
47
|
+ msSmsSendHistoryRecordMapper.insert(historyRecord);
|
|
|
48
|
+ }
|
|
|
49
|
+ }
|
|
|
50
|
+
|
|
|
51
|
+ /**
|
|
|
52
|
+ * 重新发送短信
|
|
|
53
|
+ *
|
|
|
54
|
+ * @param smsSendRecord
|
|
|
55
|
+ */
|
|
|
56
|
+ @Override
|
|
|
57
|
+ public AjaxResult reSendShortMessage(SmsSendRecord smsSendRecord) {
|
|
|
58
|
+ SmsUtils.SendSmsRequest request = new SmsUtils.SendSmsRequest();
|
|
|
59
|
+ //TODO 模版id待替换
|
|
|
60
|
+ request.setTemplateId("1955047");
|
|
|
61
|
+ request.setPhone(smsSendRecord.getPhone());
|
|
|
62
|
+ request.setTemplateParamSet(new String[]{smsSendRecord.getSendContent()});
|
|
|
63
|
+ JSONObject resultObj = SmsUtils.sendSms(request);
|
|
|
64
|
+ if (resultObj.get("status") != null && !resultObj.get("status").equals(SMSStatusEnum.FAIL.getCode())) {
|
|
|
65
|
+ return AjaxResult.success("短信发送成功");
|
|
|
66
|
+ } else {
|
|
|
67
|
+ return AjaxResult.warn("短信发送失败");
|
|
|
68
|
+ }
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ /**
|
|
|
72
|
+ * 根据信息生成加密信息记录
|
|
|
73
|
+ *
|
|
|
74
|
+ * @param secretInfo
|
|
|
75
|
+ * @return
|
|
|
76
|
+ */
|
|
|
77
|
+ @Override
|
|
|
78
|
+ public String buildEncryptInfoRecord(SecretInfo secretInfo) {
|
|
|
79
|
+ String privateKey = shortMessageKey;
|
|
|
80
|
+ ObjectNode param = new ObjectMapper().createObjectNode();
|
|
|
81
|
+ param.put("userName", secretInfo.getUserName());
|
|
|
82
|
+ param.put("caseNo", secretInfo.getCaseNo());
|
|
|
83
|
+ param.put("userId", secretInfo.getUserId());
|
|
|
84
|
+ param.put("roomId", secretInfo.getRoomId());
|
|
|
85
|
+ param.put("systemType", secretInfo.getSystemType());
|
|
|
86
|
+ String encryptString = sm4Encrypt(param.toString(), privateKey);
|
|
|
87
|
+ String uid = UUID.randomUUID().toString().replace("-", "");
|
|
|
88
|
+ EncryptendInfo encryptendInfo = new EncryptendInfo();
|
|
|
89
|
+ encryptendInfo.setUid(uid);
|
|
|
90
|
+ encryptendInfo.setEncryptedContent(encryptString);
|
|
|
91
|
+ encryptendInfoMapper.insertSelective(encryptendInfo);
|
|
|
92
|
+ System.out.println("加密后的字符串:" + encryptString);
|
|
|
93
|
+ return uid;
|
|
|
94
|
+ }
|
|
|
95
|
+
|
|
|
96
|
+ /**
|
|
|
97
|
+ * 通过UID查询加密信息并解密成明文对象
|
|
|
98
|
+ *
|
|
|
99
|
+ * @param uid
|
|
|
100
|
+ */
|
|
|
101
|
+ @Override
|
|
|
102
|
+ public Object getEncryptInfoByUid(String uid) {
|
|
|
103
|
+ EncryptendInfo encryptendInfo = encryptendInfoMapper.selectByPrimaryKey(uid);
|
|
|
104
|
+ if (encryptendInfo != null) {
|
|
|
105
|
+ return sm4Decrypt(encryptendInfo.getEncryptedContent(), shortMessageKey);
|
|
|
106
|
+ }
|
|
|
107
|
+ return null;
|
|
|
108
|
+ }
|
|
|
109
|
+}
|