Commit fb268abd by YG8999

短信发送平台重新对接

parent a47d3b54
......@@ -11,27 +11,37 @@ import cn.hutool.core.util.StrUtil;
public enum SmsStatusEnum {
SMS_STATUS_0(0, "成功"),
SMS_STATUS_2(2, "IP错误"),
SMS_STATUS_3(3, "账号密码错误"),
SMS_STATUS_5(5, "其它错误"),
SMS_STATUS_6(5, "接入点错误"),
SMS_STATUS_7(7, "账号状态异常"),
SMS_STATUS_11(11, "系统内部错误,请联系管理员"),
SMS_STATUS_30(30, "action=statis时:endTime<begin或 endTime-beginTime>180,结束时间不能小于开始时间,间隔不能大于180天; action=select时:date错, date大于当天日期, date不在过去180天内"),
SMS_STATUS_31(31, "action=templateAdd或action=templateDelete时操作过于频繁,建议每10秒操作一次"),
SMS_STATUS_32(32, "condition错,只能为APMID或MOBILE"),
SMS_STATUS_33(33, "值列表过多,最多只能1000"),
SMS_STATUS_34(34, "请求参数有误"),
SMS_STATUS_35(35, "mobileEencryptionMode=aes时,解析后的正确号码数为0"),
SMS_STATUS_36(36, "未找到模板"),
SMS_STATUS_37(37, "模板状态有误"),
SMS_STATUS_38(38, "模板时间不允许"),
SMS_STATUS_39(39, "不支持此接口"),
SMS_STATUS_100(100, "系统内部错误,请联系管理员"),
// SMS_RESULT_0(0, "成功"),
SMS_RESULT_10(10, "原发号码错误,即extno错误"),
SMS_RESULT_15(15, "余额不足"),
// SMS_RESULT_100(100, "系统内部错误,请联系管理员"),
SMS_STATUS_1(1, "帐号名为空"),
SMS_STATUS_2(2, "帐号名或密码鉴权错误"),
SMS_STATUS_3(3, "帐号已被锁定"),
SMS_STATUS_4(4, "此帐号业务未开通"),
SMS_STATUS_5(5, "帐号余额不足"),
SMS_STATUS_6(6, "缺少发送号码"),
SMS_STATUS_7(7, "超过最大发送号码数"),
SMS_STATUS_8(8, "发送消息内容为空"),
SMS_STATUS_9(9, "无效的RCS模板ID"),
SMS_STATUS_10(10, "非法的IP地址,提交来源IP地址与帐号绑定IP不一致"),
SMS_STATUS_11(11, "24小时发送时间段限制"),
SMS_STATUS_12(12, "定时发送时间错误或超过15天"),
SMS_STATUS_13(13, "请求过于频繁,每次获取数据最小间隔为30秒"),
SMS_STATUS_14(14, "错误的用户扩展码"),
SMS_STATUS_16(16, "时间戳差异过大,与系统时间误差不得超过5分钟"),
SMS_STATUS_18(18, "帐号未进行实名认证"),
SMS_STATUS_19(19, "帐号未开放回执状态"),
SMS_STATUS_22(22, "缺少必填参数"),
SMS_STATUS_23(23, "用户帐号名重复"),
SMS_STATUS_24(24, "用户无签名限制"),
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;
......
......@@ -69,10 +69,21 @@ public class SmsUtil {
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) {
// Integer code = BaseUtil.randomCount(111111, 999999);
// String content = MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), "5");
Integer code = BaseUtil.randomCount(111111, 999999);
String content = MessageFormat.format(SmsConts.smsCodeTemp, code.toString(), "5");
// // 发送内容添加短信签名
// String smsContent = StrUtil.concat(true, "【凑角】", content);
// String mobile = "13724108012";
......@@ -86,36 +97,34 @@ public class SmsUtil {
// param.put("content", smsContent);
// param.put("extno", "10690");
//// param.put("atTime", "");
// System.out.println(JSONUtil.toJsonStr(param));
// HttpHeaders headers = new HttpHeaders();
//
// 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");
//
// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
//
// HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers);
// RestTemplate restTemplate = new RestTemplate();
// cn.hutool.json.JSONObject body = restTemplate.postForEntity("http://121.36.230.249:7862/smsv2", requestEntity, cn.hutool.json.JSONObject.class).getBody();
// System.out.println(JSONUtil.toJsonStr(body));
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
// 模拟长时间运行的操作
try {
Thread.sleep(2000);
System.out.println("hello h2t111");
} catch (InterruptedException e) {
e.printStackTrace();
}
return "Result: " + 111;
});
// System.out.println(future.join());
System.out.println("future.join()");
try {
Thread.sleep(4000);
System.out.println("hello h2t2211");
} catch (InterruptedException e) {
e.printStackTrace();
}
String smsContent = StrUtil.concat(true, "【凑角】", content);
Long timestamp = DateUtil.date().getTime();
JSONObject param = JSONUtil.createObj();
param.put("userName", "799046");
param.put("sign",SecureUtil.md5("799046" + timestamp + SecureUtil.md5("mTPLoCadtv2V")));
param.put("timestamp", timestamp);
// 短信发送集合messageList
JSONObject sendParam = JSONUtil.createObj();
sendParam.put("phone", "18062577819");
sendParam.put("content", smsContent);
JSONArray array = JSONUtil.createArray();
array.add(sendParam);
param.put("messageList", array);
System.out.println(JSONUtil.toJsonStr(param));
HttpHeaders headers = new HttpHeaders();
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");
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
HttpEntity<JSONObject> requestEntity = new HttpEntity<>(param, headers);
RestTemplate restTemplate = new RestTemplate();
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(JSONUtil.toJsonStr(body));
}
......
......@@ -344,7 +344,9 @@ public class RedisTask {
StrUtil.toString(storeId));
if (redisUtil.getListSize(key2) > 0) {
// 删除失败消息redis记录
redisUtil.getRightPop(key2, 10L);
Object deleteData = redisUtil.getRightPop(key2, 10L);
// 将失败的消息放到redis最后重新发送
redisUtil.lPush(key2, deleteData);
// 获取当前需要发送的消息
Object data = redisUtil.getIndex(key2, -1);
if (null != data) {
......
package share.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
......@@ -204,24 +205,21 @@ public class SmsServiceImpl implements SmsService {
private JSONObject sendGroupSms(List<String> phoneList, String content, String smsType) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content);
String phoneStr = String.join(",", phoneList);
Long timestamp = DateUtil.date().getTime();
JSONObject param = JSONUtil.createObj();
param.set("action", "send");
param.set("account", userName);
param.set("password", smsUtil.md5Password(passWord, extno, phoneStr, smsContent));
param.set("mobile", phoneStr);
// param.put("mobileEencryptionMode", "");
param.set("userName", userName);
param.set("password", smsUtil.sign(userName, timestamp, passWord));
param.set("phoneList", JSONUtil.parseArray(phoneList));
param.set("content", smsContent);
param.set("extno", extno);
// param.put("atTime", "");
param.set("timestamp", timestamp);
// 短信日志
SmsLog smsLog = new SmsLog();
smsLog.setPhone(phoneStr);
smsLog.setPhone(String.join(",", phoneList));
smsLog.setContent(content);
smsLog.setSignature(signature);
smsLog.setSmsType(smsType);
try {
JSONObject jsonObject = smsUtil.postFrom(url, param);
JSONObject jsonObject = smsUtil.postFrom(url + "/api/sendMessageMass", param);
smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject));
checkResult(jsonObject, smsLog);
smsLogService.insertSmsLog(smsLog);
......@@ -247,15 +245,19 @@ public class SmsServiceImpl implements SmsService {
private JSONObject sendOneSms(String phone, String content, String smsType, Long storeId, Long roomId) {
// 发送内容添加短信签名
String smsContent = StrUtil.concat(true, signature, content);
Long timestamp = DateUtil.date().getTime();
JSONObject param = JSONUtil.createObj();
param.set("action", "send");
param.set("account", userName);
param.set("password", smsUtil.md5Password(passWord, extno, phone, smsContent));
param.set("mobile", phone);
// param.put("mobileEencryptionMode", "");
param.set("content", smsContent);
param.set("extno", extno);
// param.put("atTime", "");
param.set("userName", userName);
param.set("sign", smsUtil.sign(userName, timestamp, passWord));
param.set("timestamp", timestamp);
// 短信发送集合messageList
JSONObject sendParam = JSONUtil.createObj();
sendParam.set("phone", phone);
sendParam.set("content", smsContent);
JSONArray array = JSONUtil.createArray();
array.add(sendParam);
param.set("messageList", array);
// 短信日志
SmsLog smsLog = new SmsLog();
smsLog.setPhone(phone);
......@@ -265,7 +267,7 @@ public class SmsServiceImpl implements SmsService {
smsLog.setStoreId(storeId);
smsLog.setRoomId(roomId);
try {
JSONObject jsonObject = smsUtil.postFrom(url, param);
JSONObject jsonObject = smsUtil.postFrom(url + "/api/sendMessageOne", param);
smsLog.setResultParam(JSONUtil.toJsonStr(jsonObject));
checkResult(jsonObject, smsLog);
smsLogService.insertSmsLog(smsLog);
......@@ -279,67 +281,21 @@ public class SmsServiceImpl implements SmsService {
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) {
if (!SmsConts.SUCCESS_CODE.equals(result.getInt("status"))) {
if (!SmsConts.SUCCESS_CODE.equals(result.getInt("code"))) {
smsLog.setResult(0);
smsLog.setRemark(SmsStatusEnum.getNameStr(result.getInt("status")));
smsLog.setRemark(SmsStatusEnum.getNameStr(result.getInt("code")));
} else {
JSONArray array = result.getJSONArray("list");
JSONArray array = result.getJSONArray("data");
if (array != null && array.size() > 0) {
StringBuilder sb = new StringBuilder();
boolean isSuccess = Boolean.TRUE;
for (Object o : array) {
JSONObject json = JSONUtil.parseObj(o);
sb.append(json.getStr("mobile")).append(": ");
sb.append(SmsStatusEnum.getNameStr(json.getInt("result"))).append(",");
if (!SmsConts.SUCCESS_CODE.equals(json.getInt("result"))){
sb.append(json.getStr("phone")).append(": ");
sb.append(SmsStatusEnum.getNameStr(json.getInt("code"))).append(",");
if (!SmsConts.SUCCESS_CODE.equals(json.getInt("code"))){
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