Commit fb268abd by YG8999

短信发送平台重新对接

parent a47d3b54
...@@ -11,27 +11,37 @@ import cn.hutool.core.util.StrUtil; ...@@ -11,27 +11,37 @@ import cn.hutool.core.util.StrUtil;
public enum SmsStatusEnum { public enum SmsStatusEnum {
SMS_STATUS_0(0, "成功"), SMS_STATUS_0(0, "成功"),
SMS_STATUS_2(2, "IP错误"), SMS_STATUS_1(1, "帐号名为空"),
SMS_STATUS_3(3, "账号密码错误"), SMS_STATUS_2(2, "帐号名或密码鉴权错误"),
SMS_STATUS_5(5, "其它错误"), SMS_STATUS_3(3, "帐号已被锁定"),
SMS_STATUS_6(5, "接入点错误"), SMS_STATUS_4(4, "此帐号业务未开通"),
SMS_STATUS_7(7, "账号状态异常"), SMS_STATUS_5(5, "帐号余额不足"),
SMS_STATUS_11(11, "系统内部错误,请联系管理员"), SMS_STATUS_6(6, "缺少发送号码"),
SMS_STATUS_30(30, "action=statis时:endTime<begin或 endTime-beginTime>180,结束时间不能小于开始时间,间隔不能大于180天; action=select时:date错, date大于当天日期, date不在过去180天内"), SMS_STATUS_7(7, "超过最大发送号码数"),
SMS_STATUS_31(31, "action=templateAdd或action=templateDelete时操作过于频繁,建议每10秒操作一次"), SMS_STATUS_8(8, "发送消息内容为空"),
SMS_STATUS_32(32, "condition错,只能为APMID或MOBILE"), SMS_STATUS_9(9, "无效的RCS模板ID"),
SMS_STATUS_33(33, "值列表过多,最多只能1000"), SMS_STATUS_10(10, "非法的IP地址,提交来源IP地址与帐号绑定IP不一致"),
SMS_STATUS_34(34, "请求参数有误"), SMS_STATUS_11(11, "24小时发送时间段限制"),
SMS_STATUS_35(35, "mobileEencryptionMode=aes时,解析后的正确号码数为0"), SMS_STATUS_12(12, "定时发送时间错误或超过15天"),
SMS_STATUS_36(36, "未找到模板"), SMS_STATUS_13(13, "请求过于频繁,每次获取数据最小间隔为30秒"),
SMS_STATUS_37(37, "模板状态有误"), SMS_STATUS_14(14, "错误的用户扩展码"),
SMS_STATUS_38(38, "模板时间不允许"), SMS_STATUS_16(16, "时间戳差异过大,与系统时间误差不得超过5分钟"),
SMS_STATUS_39(39, "不支持此接口"), SMS_STATUS_18(18, "帐号未进行实名认证"),
SMS_STATUS_100(100, "系统内部错误,请联系管理员"), SMS_STATUS_19(19, "帐号未开放回执状态"),
// SMS_RESULT_0(0, "成功"), SMS_STATUS_22(22, "缺少必填参数"),
SMS_RESULT_10(10, "原发号码错误,即extno错误"), SMS_STATUS_23(23, "用户帐号名重复"),
SMS_RESULT_15(15, "余额不足"), SMS_STATUS_24(24, "用户无签名限制"),
// SMS_RESULT_100(100, "系统内部错误,请联系管理员"), SMS_STATUS_25(25, "签名需要包含【】符"),
SMS_STATUS_50(50, "缺少模板标题"),
SMS_STATUS_51(51, "缺少模板内容"),
SMS_STATUS_52(52, "模板内容不全"),
SMS_STATUS_53(53, "不支持的模板帧类型"),
SMS_STATUS_54(54, "不支持的文件类型"),
SMS_STATUS_97(97, "此链接不支持GET请求"),
SMS_STATUS_98(98, "HTTP Content-Type错误, 请设置Content-Type: application/json"),
SMS_STATUS_99(99, "错误的请求JSON字符串"),
SMS_STATUS_500(500, "系统异常,请联系管理员"),
; ;
private Integer code; private Integer code;
......
...@@ -69,10 +69,21 @@ public class SmsUtil { ...@@ -69,10 +69,21 @@ public class SmsUtil {
return SecureUtil.md5(StrUtil.concat(true, password, extno, mobile, content)); return SecureUtil.md5(StrUtil.concat(true, password, extno, mobile, content));
} }
/**
* 短信签名
* @param userName 账号
* @param timestamp 时间戳
* @param password 密码
* @return
*/
public String sign(String userName, long timestamp, String password) {
return SecureUtil.md5(userName + timestamp + SecureUtil.md5(password));
}
public static void main(String[] args) { public static void main(String[] args) {
// Integer code = BaseUtil.randomCount(111111, 999999); Integer code = BaseUtil.randomCount(111111, 999999);
// String content = MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), "5"); String content = MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), "5");
// // 发送内容添加短信签名 // // 发送内容添加短信签名
// String smsContent = StrUtil.concat(true, "【凑角】", content); // String smsContent = StrUtil.concat(true, "【凑角】", content);
// String mobile = "13724108012"; // String mobile = "13724108012";
...@@ -86,36 +97,34 @@ public class SmsUtil { ...@@ -86,36 +97,34 @@ public class SmsUtil {
// param.put("content", smsContent); // param.put("content", smsContent);
// param.put("extno", "10690"); // param.put("extno", "10690");
//// param.put("atTime", ""); //// param.put("atTime", "");
// System.out.println(JSONUtil.toJsonStr(param));
// HttpHeaders headers = new HttpHeaders(); String smsContent = StrUtil.concat(true, "【凑角】", content);
// Long timestamp = DateUtil.date().getTime();
// headers.setContentType(MediaType.APPLICATION_JSON_UTF8); JSONObject param = JSONUtil.createObj();
// headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"); param.put("userName", "799046");
// param.put("sign",SecureUtil.md5("799046" + timestamp + SecureUtil.md5("mTPLoCadtv2V")));
// headers.add("Accept", MediaType.APPLICATION_JSON.toString()); param.put("timestamp", timestamp);
// // 短信发送集合messageList
// HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers); JSONObject sendParam = JSONUtil.createObj();
// RestTemplate restTemplate = new RestTemplate(); sendParam.put("phone", "18062577819");
// cn.hutool.json.JSONObject body = restTemplate.postForEntity("http://121.36.230.249:7862/smsv2", requestEntity, cn.hutool.json.JSONObject.class).getBody(); sendParam.put("content", smsContent);
// System.out.println(JSONUtil.toJsonStr(body)); JSONArray array = JSONUtil.createArray();
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> { array.add(sendParam);
// 模拟长时间运行的操作 param.put("messageList", array);
try {
Thread.sleep(2000); System.out.println(JSONUtil.toJsonStr(param));
System.out.println("hello h2t111"); HttpHeaders headers = new HttpHeaders();
} catch (InterruptedException e) {
e.printStackTrace(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
} headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
return "Result: " + 111;
}); headers.add("Accept", MediaType.APPLICATION_JSON.toString());
// System.out.println(future.join());
System.out.println("future.join()"); HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers);
try { RestTemplate restTemplate = new RestTemplate();
Thread.sleep(4000); cn.hutool.json.JSONObject body = restTemplate.postForEntity("http://43.137.43.203:8001/sms/api/sendMessageOne", requestEntity, cn.hutool.json.JSONObject.class).getBody();
System.out.println("hello h2t2211"); System.out.println(JSONUtil.toJsonStr(body));
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
......
...@@ -344,7 +344,9 @@ public class RedisTask { ...@@ -344,7 +344,9 @@ public class RedisTask {
StrUtil.toString(storeId)); StrUtil.toString(storeId));
if (redisUtil.getListSize(key2) > 0) { if (redisUtil.getListSize(key2) > 0) {
// 删除失败消息redis记录 // 删除失败消息redis记录
redisUtil.getRightPop(key2, 10L); Object deleteData = redisUtil.getRightPop(key2, 10L);
// 将失败的消息放到redis最后重新发送
redisUtil.lPush(key2, deleteData);
// 获取当前需要发送的消息 // 获取当前需要发送的消息
Object data = redisUtil.getIndex(key2, -1); Object data = redisUtil.getIndex(key2, -1);
if (null != data) { if (null != data) {
......
package share.system.service.impl; package share.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
...@@ -204,24 +205,21 @@ public class SmsServiceImpl implements SmsService { ...@@ -204,24 +205,21 @@ public class SmsServiceImpl implements SmsService {
private JSONObject sendGroupSms(List<String> phoneList, String content, String smsType) { private JSONObject sendGroupSms(List<String> phoneList, String content, String smsType) {
// 发送内容添加短信签名 // 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content); String smsContent = StrUtil.concat(true, signature, content);
String phoneStr = String.join(",", phoneList); Long timestamp = DateUtil.date().getTime();
JSONObject param = JSONUtil.createObj(); JSONObject param = JSONUtil.createObj();
param.set("action", "send"); param.set("userName", userName);
param.set("account", userName); param.set("password", smsUtil.sign(userName, timestamp, passWord));
param.set("password", smsUtil.md5Password(passWord, extno, phoneStr, smsContent)); param.set("phoneList", JSONUtil.parseArray(phoneList));
param.set("mobile", phoneStr);
// param.put("mobileEencryptionMode", "");
param.set("content", smsContent); param.set("content", smsContent);
param.set("extno", extno); param.set("timestamp", timestamp);
// param.put("atTime", "");
// 短信日志 // 短信日志
SmsLog smsLog = new SmsLog(); SmsLog smsLog = new SmsLog();
smsLog.setPhone(phoneStr); smsLog.setPhone(String.join(",", phoneList));
smsLog.setContent(content); smsLog.setContent(content);
smsLog.setSignature(signature); smsLog.setSignature(signature);
smsLog.setSmsType(smsType); smsLog.setSmsType(smsType);
try { try {
JSONObject jsonObject = smsUtil.postFrom(url, param); JSONObject jsonObject = smsUtil.postFrom(url + "/api/sendMessageMass", param);
smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject)); smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject));
checkResult(jsonObject, smsLog); checkResult(jsonObject, smsLog);
smsLogService.insertSmsLog(smsLog); smsLogService.insertSmsLog(smsLog);
...@@ -247,15 +245,19 @@ public class SmsServiceImpl implements SmsService { ...@@ -247,15 +245,19 @@ public class SmsServiceImpl implements SmsService {
private JSONObject sendOneSms(String phone, String content, String smsType, Long storeId, Long roomId) { private JSONObject sendOneSms(String phone, String content, String smsType, Long storeId, Long roomId) {
// 发送内容添加短信签名 // 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content); String smsContent = StrUtil.concat(true, signature, content);
Long timestamp = DateUtil.date().getTime();
JSONObject param = JSONUtil.createObj(); JSONObject param = JSONUtil.createObj();
param.set("action", "send"); param.set("userName", userName);
param.set("account", userName); param.set("sign", smsUtil.sign(userName, timestamp, passWord));
param.set("password", smsUtil.md5Password(passWord, extno, phone, smsContent)); param.set("timestamp", timestamp);
param.set("mobile", phone); // 短信发送集合messageList
// param.put("mobileEencryptionMode", ""); JSONObject sendParam = JSONUtil.createObj();
param.set("content", smsContent); sendParam.set("phone", phone);
param.set("extno", extno); sendParam.set("content", smsContent);
// param.put("atTime", ""); JSONArray array = JSONUtil.createArray();
array.add(sendParam);
param.set("messageList", array);
// 短信日志 // 短信日志
SmsLog smsLog = new SmsLog(); SmsLog smsLog = new SmsLog();
smsLog.setPhone(phone); smsLog.setPhone(phone);
...@@ -265,7 +267,7 @@ public class SmsServiceImpl implements SmsService { ...@@ -265,7 +267,7 @@ public class SmsServiceImpl implements SmsService {
smsLog.setStoreId(storeId); smsLog.setStoreId(storeId);
smsLog.setRoomId(roomId); smsLog.setRoomId(roomId);
try { try {
JSONObject jsonObject = smsUtil.postFrom(url, param); JSONObject jsonObject = smsUtil.postFrom(url + "/api/sendMessageOne", param);
smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject)); smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject));
checkResult(jsonObject, smsLog); checkResult(jsonObject, smsLog);
smsLogService.insertSmsLog(smsLog); smsLogService.insertSmsLog(smsLog);
...@@ -279,67 +281,21 @@ public class SmsServiceImpl implements SmsService { ...@@ -279,67 +281,21 @@ public class SmsServiceImpl implements SmsService {
return null; return null;
} }
/**
* 点对点发送
* @param map 手机号码:发送内容 {"15100000000":"【测试】test1","15100000001":"【测试】test2"}
* @return
*/
private JSONObject sendP2PSms(Map<String,String> map, String smsType) {
String content = "";
List<String> phoneList = new ArrayList<>();
if (map != null) {
for (Map.Entry<String,String> entry : map.entrySet()) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, entry.getValue());
map.put(entry.getKey(), smsContent);
content = StrUtil.concat(true, content, entry.getKey(), entry.getValue());
phoneList.add(entry.getKey());
}
}
JSONObject param = JSONUtil.createObj();
param.set("action", "p2p");
param.set("account", userName);
param.set("password", smsUtil.md5Password(passWord, extno, "", content));
param.set("mobileContentKvp", map);
// param.put("mobileEencryptionMode", "");
param.set("extno", extno);
// param.put("atTime", "");
// 短信日志
SmsLog smsLog = new SmsLog();
smsLog.setPhone(String.join(",", phoneList));
smsLog.setContent(content);
smsLog.setSignature(signature);
smsLog.setSmsType(smsType);
try {
JSONObject jsonObject = smsUtil.postFrom(url, param);
smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject));
checkResult(jsonObject, smsLog);
smsLogService.insertSmsLog(smsLog);
return jsonObject;
} catch (BaseException exception) {
// 异常日志
smsLog.setResult(0);
smsLog.setRemark(exception.getDefaultMessage());
smsLogService.insertSmsLog(smsLog);
}
return null;
}
private void checkResult(JSONObject result, SmsLog smsLog) { private void checkResult(JSONObject result, SmsLog smsLog) {
if (!SmsConts.SUCCESS_CODE.equals(result.getInt("status"))) { if (!SmsConts.SUCCESS_CODE.equals(result.getInt("code"))) {
smsLog.setResult(0); smsLog.setResult(0);
smsLog.setRemark(SmsStatusEnum.getNameStr(result.getInt("status"))); smsLog.setRemark(SmsStatusEnum.getNameStr(result.getInt("code")));
} else { } else {
JSONArray array = result.getJSONArray("list"); JSONArray array = result.getJSONArray("data");
if (array != null && array.size() > 0) { if (array != null && array.size() > 0) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
boolean isSuccess = Boolean.TRUE; boolean isSuccess = Boolean.TRUE;
for (Object o : array) { for (Object o : array) {
JSONObject json = JSONUtil.parseObj(o); JSONObject json = JSONUtil.parseObj(o);
sb.append(json.getStr("mobile")).append(": "); sb.append(json.getStr("phone")).append(": ");
sb.append(SmsStatusEnum.getNameStr(json.getInt("result"))).append(","); sb.append(SmsStatusEnum.getNameStr(json.getInt("code"))).append(",");
if (!SmsConts.SUCCESS_CODE.equals(json.getInt("result"))){ if (!SmsConts.SUCCESS_CODE.equals(json.getInt("code"))){
isSuccess = Boolean.FALSE; isSuccess = Boolean.FALSE;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment