144 lines
5.9 KiB
Java
144 lines
5.9 KiB
Java
package com.xkrs.sms;
|
|
|
|
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.xkrs.model.entity.FirePointEntity;
|
|
import com.xkrs.straw.model.entity.SysUserEntity;
|
|
import com.xkrs.utils.AliYunSmsUtils;
|
|
import com.xkrs.utils.HttpClientUtils;
|
|
import com.xkrs.utils.SMSUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@Component
|
|
public class SMSHelper {
|
|
|
|
public static Logger log = LoggerFactory.getLogger(SMSHelper.class);
|
|
|
|
public SMSHelper() {
|
|
}
|
|
|
|
public void dispatchSMSMessage(Map<String, List<SysUserEntity>> agentOrgNameGroupMap, String[] templateParamArray, FirePointEntity[] detailParamArray) {
|
|
for (Map.Entry<String, List<SysUserEntity>> entry : agentOrgNameGroupMap.entrySet()) {
|
|
String targetAgentOrgName = entry.getKey();
|
|
List<SysUserEntity> groupSmsReceiverList = entry.getValue();
|
|
if (groupSmsReceiverList != null && groupSmsReceiverList.size() > 0) {
|
|
String[] telephoneArray = new String[groupSmsReceiverList.size()];
|
|
for (int i = 0; i < groupSmsReceiverList.size(); i++) {
|
|
telephoneArray[i] = "86" + groupSmsReceiverList.get(i).getUserName();
|
|
}
|
|
if ("青岛星科瑞升信息科技有限公司".equals(targetAgentOrgName)) {
|
|
|
|
xingkeSMSMessage(telephoneArray, templateParamArray, detailParamArray);
|
|
|
|
} else if ("青岛华正信息技术股份有限公司".equals(targetAgentOrgName)) {
|
|
|
|
try {
|
|
huazhengSMSMessage(telephoneArray, templateParamArray, detailParamArray);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 星科瑞升向用户发送短信
|
|
*/
|
|
private void xingkeSMSMessage(String[] telephoneArray, String[] templateParamArray, FirePointEntity[] detailParamArray) {
|
|
int resValue = SMSUtils.sendSmsToUser(telephoneArray, "1425995", templateParamArray);
|
|
String sendResult = resValue == 0 ? "短信通知发送成功!" : "短信通知发送失败!";
|
|
//记录短信通知日志
|
|
StringBuilder stringBuilder = new StringBuilder("发送人:青岛星科瑞升信息科技有限公司\n");
|
|
for (String telephone : telephoneArray) {
|
|
stringBuilder.append("接收人:").append(telephone).append("\n");
|
|
}
|
|
for (String templateParam : templateParamArray) {
|
|
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
|
}
|
|
for (FirePointEntity detailParam : detailParamArray) {
|
|
stringBuilder.append("超级详细的参数:").append(detailParam.toString()).append("\n");
|
|
}
|
|
stringBuilder.append(sendResult);
|
|
log.info(stringBuilder.toString());
|
|
}
|
|
|
|
/**
|
|
* 华正信息向用户发送短信
|
|
*/
|
|
private void huazhengSMSMessage(String[] telephoneArray, String[] templateParamArray, FirePointEntity[] detailParamArray) throws Exception {
|
|
StringBuilder telephoneBuilder = new StringBuilder();
|
|
for (int i = 0; i < telephoneArray.length; i++) {
|
|
telephoneBuilder.append(telephoneArray[i]);
|
|
if (i < telephoneArray.length - 1) {
|
|
telephoneBuilder.append(",");
|
|
}
|
|
}
|
|
String telephoneContent = telephoneBuilder.toString();
|
|
String url = "http://58.56.128.186:10144/msg/msgSend";
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("receiver", telephoneContent);
|
|
map.put("msgContent", "{\"address\":\"" + templateParamArray[0] + "\"}");
|
|
map.put("templateUid", "27dbffdf8b0a492e");
|
|
HttpClientUtils.sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
|
|
|
|
//记录短信通知日志
|
|
StringBuilder stringBuilder = new StringBuilder("发送人:青岛华正信息技术股份有限公司\n");
|
|
for (String telephone : telephoneArray) {
|
|
stringBuilder.append("接收人:").append(telephone).append("\n");
|
|
}
|
|
for (String templateParam : templateParamArray) {
|
|
stringBuilder.append("模板参数:").append(templateParam).append("\n");
|
|
}
|
|
for (FirePointEntity detailParam : detailParamArray) {
|
|
stringBuilder.append("超级详细的参数:").append(detailParam.toString()).append("\n");
|
|
}
|
|
log.info(stringBuilder.toString());
|
|
}
|
|
|
|
public void dispatchSMSCode(String targetAgentOrgName, String telephone, String code) throws Exception {
|
|
|
|
if ("青岛星科瑞升信息科技有限公司".equals(targetAgentOrgName)) {
|
|
|
|
xingkeSMSCode(telephone, code);
|
|
|
|
} else if ("青岛华正信息技术股份有限公司".equals(targetAgentOrgName)) {
|
|
|
|
huazhengSMSCode(telephone, code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 星科瑞升向用户发送验证码
|
|
*/
|
|
private void xingkeSMSCode(String telephone, String code) throws Exception {
|
|
SendSmsResponse response = AliYunSmsUtils.sendCode(telephone, code);
|
|
}
|
|
|
|
/**
|
|
* 华正信息向用户发送验证码
|
|
*/
|
|
private void huazhengSMSCode(String telephone, String code) throws Exception {
|
|
|
|
String url = "http://58.56.128.186:10144/msg/msgSend";
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("receiver", telephone);
|
|
map.put("msgContent", "{\"code\":\"" + code + "\"}");
|
|
map.put("templateUid", "6f7672a4978542e2");
|
|
HttpClientUtils.sendHttpPost(url, new ObjectMapper().writeValueAsString(map));
|
|
//记录短信通知日志
|
|
String stringBuilder = "发送人:青岛华正信息技术股份有限公司\n" + "接收人:" + telephone + "\n" + "验证码:" + code + "\n";
|
|
log.info(stringBuilder);
|
|
}
|
|
|
|
}
|