Commit 405e88c0 authored by qinxunjia's avatar qinxunjia

一些优化

parent 81fdd480
package com.jz.sms.channel.chuanglan.config;
/**
* 内容枚举类
*/
public enum ContentEnum {
SMS_TYPE_NOTIFICATION("notification", "通知类短信标识"),
SMS_TYPE_MARKETING("marketing", "营销类短信标识"),
SMS_STATUS_SUCCESS("DELIVRD", "创蓝短信发送状态--成功"),
SMS_STATUS_UNKNOWN("UNKNOWN", "创蓝短信发送状态--未知"),
SMS_STATUS_REFUSE("REJECTD", "创蓝短信发送状态--短信中心拒绝"),
SMS_STATUS_MBBLACK("MBBLACK", "创蓝短信发送状态--黑名单号码"),
SMS_STATUS_REJECT("REJECT", "创蓝短信发送状态--驳回");
private final String value;
private final String desc;
ContentEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class CLNotifyRequest { import java.io.Serializable;
public class CLNotifyRequest implements Serializable {
private static final long serialVersionUID = 1L;
// 接口用户名 // 接口用户名
private String username; private String username;
// 十位时间戳 // 十位时间戳
......
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class CLSendFixedRequest { import java.io.Serializable;
public class CLSendFixedRequest implements Serializable {
private static final long serialVersionUID = 1L;
/** /**
* 创蓝API账号,必填 * 创蓝API账号,必填
......
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class CLSendSMSResponse { import java.io.Serializable;
public class CLSendSMSResponse implements Serializable {
private static final long serialVersionUID = 1L;
/** /**
* 响应时间 * 响应时间
*/ */
...@@ -23,9 +27,10 @@ public class CLSendSMSResponse { ...@@ -23,9 +27,10 @@ public class CLSendSMSResponse {
private String successNum; private String successNum;
public CLSendSMSResponse(){} public CLSendSMSResponse() {
}
public CLSendSMSResponse(String code, String errorMsg){ public CLSendSMSResponse(String code, String errorMsg) {
this.code = code; this.code = code;
this.errorMsg = errorMsg; this.errorMsg = errorMsg;
} }
......
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class CLSendVariableRequest { import java.io.Serializable;
public class CLSendVariableRequest implements Serializable {
private static final long serialVersionUID = 1L;
/** /**
......
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class CLSendVariableResponse { import java.io.Serializable;
public class CLSendVariableResponse implements Serializable {
private static final long serialVersionUID = 1L;
/** /**
* 响应时间 * 响应时间
*/ */
......
package com.jz.sms.channel.chuanglan.dto; package com.jz.sms.channel.chuanglan.dto;
public class ReportDto { import java.io.Serializable;
//receiver=admin public class ReportDto implements Serializable {
//&pswd=12345
//&msgid=17041010383624511 private static final long serialVersionUID = 1L;
//&reportTime=1704101038
//&mobile=15700000004
//&notifyTime=170410103838
//&uid=17041010383624511
//&length=1
//&status=DELIVRD
//&statusDesc=短信发送成功
private String receiver; private String receiver;
......
package com.jz.sms.channel.chuanglan.service; package com.jz.sms.channel.chuanglan.service;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.channel.chuanglan.dto.CLNotifyRequest; import com.jz.sms.channel.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.channel.chuanglan.dto.CLBizResponse; import com.jz.sms.channel.chuanglan.dto.CLBizResponse;
import com.jz.sms.channel.chuanglan.dto.ReportDto; import com.jz.sms.channel.chuanglan.dto.ReportDto;
...@@ -10,10 +11,10 @@ public interface ChuangLanSmsService { ...@@ -10,10 +11,10 @@ public interface ChuangLanSmsService {
CLBizResponse createTemplate(String content, String type) throws Exception; CLBizResponse createTemplate(String content, String type) throws Exception;
CLBizResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception; CLBizResponse sendByFixed(JSONObject uidJson, String content, String sendParams, String type) throws Exception;
CLBizResponse sendByVariable(String batchId, String content, String sendParams, String type) throws Exception; CLBizResponse sendByVariable(JSONObject uidJson, String content, String sendParams, String type) throws Exception;
CLBizResponse asyncNotify(CLNotifyRequest notifyInfo) throws Exception; CLBizResponse asyncNotify(CLNotifyRequest notifyInfo) throws Exception;
......
...@@ -4,6 +4,7 @@ package com.jz.sms.channel.chuanglan.service.impl; ...@@ -4,6 +4,7 @@ package com.jz.sms.channel.chuanglan.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.sms.channel.chuanglan.config.ContentEnum;
import com.jz.util.HttpUtil; import com.jz.util.HttpUtil;
import com.jz.sms.channel.chuanglan.dto.*; import com.jz.sms.channel.chuanglan.dto.*;
import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService; import com.jz.sms.channel.chuanglan.service.ChuangLanSmsService;
...@@ -30,9 +31,13 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -30,9 +31,13 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private static final Logger log = LoggerFactory.getLogger(ChuangLanSmsServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(ChuangLanSmsServiceImpl.class);
private static final String SUCCESS = "success"; private static final String SUCCESS = "success";
private static final String ERROR = "error"; private static final String sendSuccessCode = "0"; // 发送响应成功字段
private static final String CODE = "code"; private static final String createTemplateStatus = "status"; // 响应状态字段
private static final String DATA = "data"; private static final String retMsg = "msg"; // 响应描述
private static final String createTemplateData = "data"; // 创建模板响应数据
private static final String notificationId = "49"; // 创蓝通知类短信ID
private static final String marketingId = "52"; // 创蓝营销类短信ID
@Autowired @Autowired
private SmsTemplateService templateService; private SmsTemplateService templateService;
...@@ -46,10 +51,11 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -46,10 +51,11 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String appId; String appId;
String username = ChuangLanSMSConfig.interfaceUser; String username = ChuangLanSMSConfig.interfaceUser;
String password = ChuangLanSMSConfig.interfacePassword; String password = ChuangLanSMSConfig.interfacePassword;
if ("notification".equals(type)) { if (ContentEnum.SMS_TYPE_NOTIFICATION.getValue().equals(type)) {
appId = "49"; appId = notificationId;
} else if ("marketing".equals(type)) { } else if (ContentEnum.SMS_TYPE_MARKETING.getValue().equals(type)) {
appId = "52"; appId = marketingId;
// 两个系统模式不同,DMHUB会带上回TD退订,但是创蓝回自动追加回TD退订。只是营销类
content = content.replaceAll("回TD退订", ""); content = content.replaceAll("回TD退订", "");
} else { } else {
// TODO 发送警告 // TODO 发送警告
...@@ -69,36 +75,37 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -69,36 +75,37 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String retStr = HttpUtil.doPost(ChuangLanSMSConfig.addTemplate, requestMap); String retStr = HttpUtil.doPost(ChuangLanSMSConfig.addTemplate, requestMap);
log.info("请求创蓝创建短信模板的返回数据为:{}", retStr); log.info("请求创蓝创建短信模板的返回数据为:{}", retStr);
JSONObject retJson = JSONObject.parseObject(retStr); JSONObject retJson = JSONObject.parseObject(retStr);
String status = retJson.getString("status"); String status = retJson.getString(createTemplateStatus);
if (SUCCESS.equals(status)) { if (SUCCESS.equals(status)) {
JSONObject data = retJson.getJSONObject("data"); JSONObject data = retJson.getJSONObject(createTemplateData);
return new CLBizResponse(ResponseCode.SUCCESS, data); return new CLBizResponse(ResponseCode.SUCCESS, data);
} else { } else {
String msg = retJson.getString("msg"); String msg = retJson.getString(retMsg);
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), msg); return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), msg);
} }
} }
@Override @Override
public CLBizResponse sendByFixed(String batchId, String content, String sendParams, String type) throws Exception { public CLBizResponse sendByFixed(JSONObject uidJson, String content, String sendParams, String type) throws Exception {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if (ContentEnum.SMS_TYPE_NOTIFICATION.getValue().equals(type)) {
account = ChuangLanSMSConfig.notificationAccount; account = ChuangLanSMSConfig.notificationAccount;
password = ChuangLanSMSConfig.notificationPassword; password = ChuangLanSMSConfig.notificationPassword;
log.info("发送短信的模式为:{通知类}"); log.info("发送短信的模式为:{通知类}");
} else if ("marketing".equals(type)) { } else if (ContentEnum.SMS_TYPE_MARKETING.getValue().equals(type)) {
account = ChuangLanSMSConfig.marketingAccount; account = ChuangLanSMSConfig.marketingAccount;
password = ChuangLanSMSConfig.marketingPassword; password = ChuangLanSMSConfig.marketingPassword;
log.info("发送短信的模式为:{营销类}"); log.info("发送短信的模式为:{营销类}");
} else { } else {
log.info("发送短信的模式为:{未知类型}"); log.error("发送短信的模式为:{未知类型}");
throw new Exception("123"); return new CLBizResponse(ResponseCode.UNKNOWN_TEMPLATE_TYPE);
} }
CLSendFixedRequest request = new CLSendFixedRequest(account, password, content, sendParams, "true", batchId); CLSendFixedRequest request = new CLSendFixedRequest(account, password, content, sendParams, "true", uidJson.toJSONString());
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
String batchId = uidJson.getString("dmHubId");
log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendFixed, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendFixed, requestJson);
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson);
...@@ -111,7 +118,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -111,7 +118,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String code = response.getCode(); String code = response.getCode();
String errorMsg = response.getErrorMsg(); String errorMsg = response.getErrorMsg();
String msgId = response.getMsgId(); String msgId = response.getMsgId();
if (!"0".equals(code)) { if (!sendSuccessCode.equals(code)) {
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg); return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg);
} else { } else {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
...@@ -121,23 +128,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -121,23 +128,24 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
} }
@Override @Override
public CLBizResponse sendByVariable(String batchId, String content, String params, String type) throws Exception { public CLBizResponse sendByVariable(JSONObject uidJson, String content, String params, String type) throws Exception {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if (ContentEnum.SMS_TYPE_NOTIFICATION.getValue().equals(type)) {
account = ChuangLanSMSConfig.notificationAccount; account = ChuangLanSMSConfig.notificationAccount;
password = ChuangLanSMSConfig.notificationPassword; password = ChuangLanSMSConfig.notificationPassword;
log.info("发送短信的模式为:{通知类}"); log.info("发送短信的模式为:{通知类}");
} else if ("marketing".equals(type)) { } else if (ContentEnum.SMS_TYPE_MARKETING.getValue().equals(type)) {
account = ChuangLanSMSConfig.marketingAccount; account = ChuangLanSMSConfig.marketingAccount;
password = ChuangLanSMSConfig.marketingPassword; password = ChuangLanSMSConfig.marketingPassword;
log.info("发送短信的模式为:{营销类}"); log.info("发送短信的模式为:{营销类}");
} else { } else {
log.info("发送短信的模式为:{未知类型},type:{}", type); log.info("发送短信的模式为:{未知类型},type:{}", type);
throw new Exception("123"); return new CLBizResponse(ResponseCode.UNKNOWN_TEMPLATE_TYPE);
} }
CLSendVariableRequest request = new CLSendVariableRequest(account, password, content, params, "true", batchId); CLSendVariableRequest request = new CLSendVariableRequest(account, password, content, params, "true", uidJson.toJSONString());
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
String batchId = uidJson.getString("dmHubId");
log.info("【{}】发送变量内容短信,请求上游数据为:{},\r\n请求地址为:{}", batchId, requestJson, ChuangLanSMSConfig.sendVariable); log.info("【{}】发送变量内容短信,请求上游数据为:{},\r\n请求地址为:{}", batchId, requestJson, ChuangLanSMSConfig.sendVariable);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendVariable, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendVariable, requestJson);
log.info("【{}】发送变量内容短信,上游返回数据为:{}", batchId, responseStr); log.info("【{}】发送变量内容短信,上游返回数据为:{}", batchId, responseStr);
...@@ -151,7 +159,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -151,7 +159,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
String successNum = response.getSuccessNum(); String successNum = response.getSuccessNum();
String failNum = response.getFailNum(); String failNum = response.getFailNum();
String msgId = response.getMsgId(); String msgId = response.getMsgId();
if (!"0".equals(code)) { if (!sendSuccessCode.equals(code)) {
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg); return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), errorMsg);
} else { } else {
JSONObject data = new JSONObject(); JSONObject data = new JSONObject();
...@@ -174,7 +182,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService { ...@@ -174,7 +182,7 @@ public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
if (!"1".equals(status)) { if (!"1".equals(status)) {
String msg = notifyInfo.getAuditReason(); String msg = notifyInfo.getAuditReason();
boolean update = templateService.updateForSet("status = abnormal,up_reject_msg = " + msg, new EntityWrapper<SmsTemplateInfo>().eq("up_template_id", id)); boolean update = templateService.updateForSet("status = abnormal,up_reject_msg = " + msg, new EntityWrapper<SmsTemplateInfo>().eq("up_template_id", id));
// TODO 发送告警 // TODO 发送告警,模板审核未通过
log.error("短信模板审核不通过,原因:{}", msg); log.error("短信模板审核不通过,原因:{}", msg);
} }
return new CLBizResponse(ResponseCode.SUCCESS); return new CLBizResponse(ResponseCode.SUCCESS);
......
package com.jz.sms.channel.dmHub.service.impl; package com.jz.sms.channel.dmHub.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jz.sms.channel.chuanglan.config.ContentEnum;
import com.jz.sms.channel.chuanglan.dto.ReportDto; import com.jz.sms.channel.chuanglan.dto.ReportDto;
import com.jz.sms.channel.dmHub.config.DmHubConfig; import com.jz.sms.channel.dmHub.config.DmHubConfig;
import com.jz.sms.channel.dmHub.service.DmHubService; import com.jz.sms.channel.dmHub.service.DmHubService;
...@@ -30,16 +31,17 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -30,16 +31,17 @@ public class DmHubServiceImpl implements DmHubService {
private static final String TOKEN_KEY = "DM_HUB_API_TOKEN"; private static final String TOKEN_KEY = "DM_HUB_API_TOKEN";
@Autowired @Autowired
RedisTemplate redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Override @Override
public String getToken() { public String getToken() {
try { try {
String token = redisTemplate.opsForValue().get(TOKEN_KEY).toString(); Long expire = redisTemplate.getExpire(TOKEN_KEY, TimeUnit.SECONDS);
Long expire = redisTemplate.opsForValue().getOperations().getExpire(TOKEN_KEY); Object token = redisTemplate.opsForValue().get(TOKEN_KEY);
if (expire != null && expire > 0L) {
return token; if (expire != null && expire > 0L && token != null) {
return token.toString();
} else { } else {
String appid = DmHubConfig.applicationId; String appid = DmHubConfig.applicationId;
String secret = DmHubConfig.applicationKey; String secret = DmHubConfig.applicationKey;
...@@ -79,17 +81,21 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -79,17 +81,21 @@ public class DmHubServiceImpl implements DmHubService {
if (StringUtils.isBlank(token)) { if (StringUtils.isBlank(token)) {
return null; return null;
} }
String uidStr = dto.getUid();
JSONObject uidJson = JSONObject.parseObject(uidStr);
String dmHubBatchId = uidJson.getString("dmHubId");
String sysBatchId = uidJson.getString("sysBatchId");
DmhubReport report = new DmhubReport(); DmhubReport report = new DmhubReport();
report.setAccess_token(token); report.setAccess_token(token);
report.setType("sms"); report.setType("sms");
ReportDetail detail = new ReportDetail(); ReportDetail detail = new ReportDetail();
detail.setAudienceId(dto.getMobile()); detail.setAudienceId(dto.getMobile());
detail.setBatchId(dto.getUid()); detail.setBatchId(dmHubBatchId);
detail.setReportDate(dto.getReportTime()); detail.setReportDate(dto.getReportTime());
detail.setMobile(dto.getMobile()); detail.setMobile(dto.getMobile());
detail.setChargeNum(Integer.valueOf(dto.getLength())); detail.setChargeNum(Integer.valueOf(dto.getLength()));
detail.setSendDate(dto.getReportTime()); detail.setSendDate(dto.getReportTime());
if ("DELIVRD".equals(dto.getStatus())) { if (ContentEnum.SMS_STATUS_SUCCESS.getValue().equals(dto.getStatus())) {
detail.setIsReceive(true); detail.setIsReceive(true);
} else { } else {
detail.setIsReceive(false); detail.setIsReceive(false);
...@@ -100,7 +106,6 @@ public class DmHubServiceImpl implements DmHubService { ...@@ -100,7 +106,6 @@ public class DmHubServiceImpl implements DmHubService {
String retStr = HttpUtil.sendPost(DmHubConfig.report, JSONObject.toJSONString(report)); String retStr = HttpUtil.sendPost(DmHubConfig.report, JSONObject.toJSONString(report));
log.info("短信状态回执响应:{}", retStr); log.info("短信状态回执响应:{}", retStr);
//TODO 目前没有测试环境的请求地址 //TODO 目前没有测试环境的请求地址
} catch (Exception e) { } catch (Exception e) {
log.info("发送短信回执到DMHub异常\r\n短信信息:{},\r\n,异常:", dto, e); log.info("发送短信回执到DMHub异常\r\n短信信息:{},\r\n,异常:", dto, e);
} }
......
...@@ -2,9 +2,12 @@ package com.jz.sms.channel.dto; ...@@ -2,9 +2,12 @@ package com.jz.sms.channel.dto;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.io.Serializable;
import java.util.List; import java.util.List;
public class DmHubBatchSendRequest { public class DmHubBatchSendRequest implements Serializable {
private static final long serialVersionUID = 1L;
// 批量发送短信的模板id // 批量发送短信的模板id
...@@ -13,7 +16,7 @@ public class DmHubBatchSendRequest { ...@@ -13,7 +16,7 @@ public class DmHubBatchSendRequest {
// 批次号 // 批次号
private String batchId; private String batchId;
// 批次号 // 账号类型(mobile就传手机号)
private String audienceIdType; private String audienceIdType;
// 短信数据 // 短信数据
......
...@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto; ...@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
public class DmHubSendRequest { import java.io.Serializable;
public class DmHubSendRequest implements Serializable {
private static final long serialVersionUID = 1L;
// 发送短信的模板ID // 发送短信的模板ID
......
...@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto; ...@@ -2,7 +2,11 @@ package com.jz.sms.channel.dto;
import com.jz.sms.config.ResponseCode; import com.jz.sms.config.ResponseCode;
public class DmHubSendResponse { import java.io.Serializable;
public class DmHubSendResponse implements Serializable {
private static final long serialVersionUID = 1L;
private String code; private String code;
private String msg; private String msg;
......
package com.jz.sms.channel.dto; package com.jz.sms.channel.dto;
public class DmHubTemplateRequest { import java.io.Serializable;
public class DmHubTemplateRequest implements Serializable {
private static final long serialVersionUID = 1L;
private String tenantId; private String tenantId;
......
...@@ -2,7 +2,13 @@ package com.jz.sms.channel.dto; ...@@ -2,7 +2,13 @@ package com.jz.sms.channel.dto;
import com.jz.sms.config.ResponseCode; import com.jz.sms.config.ResponseCode;
public class DmHubTemplateResponse { import java.io.Serializable;
public class DmHubTemplateResponse implements Serializable {
private static final long serialVersionUID = 1L;
private String code; private String code;
private String msg; private String msg;
......
...@@ -9,10 +9,10 @@ import org.springframework.data.redis.core.RedisTemplate; ...@@ -9,10 +9,10 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration @Configuration
public class RedisConfig<K, V> { public class RedisConfig{
@Bean @Bean
public RedisTemplate<K, V> getRedisTemplate(RedisConnectionFactory redisConnectionFactory) { public RedisTemplate<String, Object> getRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<K, V> redisTemplate = new RedisTemplate<>(); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory); redisTemplate.setConnectionFactory(redisConnectionFactory);
//全局开启 //全局开启
......
...@@ -2,6 +2,7 @@ package com.jz.sms.config; ...@@ -2,6 +2,7 @@ package com.jz.sms.config;
public enum ResponseCode { public enum ResponseCode {
SUCCESS("200", "处理成功"), SUCCESS("200", "处理成功"),
UNKNOWN_TEMPLATE_TYPE("500", "未知模板类型"),
UPSTREAM_FAIL("US01", "渠道交易失败"), UPSTREAM_FAIL("US01", "渠道交易失败"),
UPSTREAM_UNKNOWN_MODEL("US01", "未知通知模式"), UPSTREAM_UNKNOWN_MODEL("US01", "未知通知模式"),
UPSTREAM_BLANK("US00", "渠道同步响应为空"), UPSTREAM_BLANK("US00", "渠道同步响应为空"),
......
...@@ -15,6 +15,7 @@ import com.jz.sms.service.MessageService; ...@@ -15,6 +15,7 @@ import com.jz.sms.service.MessageService;
import com.jz.sms.service.SmsTemplateService; import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.service.bean.TemplateChangeBean; import com.jz.sms.service.bean.TemplateChangeBean;
import com.jz.util.id.IdHandler; import com.jz.util.id.IdHandler;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -53,7 +54,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -53,7 +54,7 @@ public class MessageServiceImpl implements MessageService {
public DmHubTemplateResponse createTemplate(DmHubTemplateRequest requestDTO) { public DmHubTemplateResponse createTemplate(DmHubTemplateRequest requestDTO) {
log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO); log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO);
DmHubTemplateResponse responseDTO = new DmHubTemplateResponse("200", "成功"); DmHubTemplateResponse responseDTO = new DmHubTemplateResponse(ResponseCode.SUCCESS);
try { try {
String templateContent = requestDTO.getTemplateContent(); String templateContent = requestDTO.getTemplateContent();
String signature = requestDTO.getSignature(); String signature = requestDTO.getSignature();
...@@ -82,8 +83,8 @@ public class MessageServiceImpl implements MessageService { ...@@ -82,8 +83,8 @@ public class MessageServiceImpl implements MessageService {
info.setParams(params); info.setParams(params);
boolean insert = smsTemplateService.insert(info); boolean insert = smsTemplateService.insert(info);
if (!insert) { if (!insert) {
return new DmHubTemplateResponse("500", "系统异常");
//TODO 发送告警 //TODO 发送告警
return new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR);
} }
String chaunglanCreate = dmHub2ChuangLanCreate(chuanglanSend); String chaunglanCreate = dmHub2ChuangLanCreate(chuanglanSend);
CLBizResponse template = chuangLanSmsService.createTemplate(chaunglanCreate, smsType); CLBizResponse template = chuangLanSmsService.createTemplate(chaunglanCreate, smsType);
...@@ -100,7 +101,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -100,7 +101,7 @@ public class MessageServiceImpl implements MessageService {
} }
} catch (Exception exception) { } catch (Exception exception) {
log.error("创建模板业务逻辑异常,错误信息", exception); log.error("创建模板业务逻辑异常,错误信息", exception);
responseDTO = new DmHubTemplateResponse("500", "系统异常"); responseDTO = new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR);
} }
return responseDTO; return responseDTO;
...@@ -209,7 +210,8 @@ public class MessageServiceImpl implements MessageService { ...@@ -209,7 +210,8 @@ public class MessageServiceImpl implements MessageService {
// 3、记录批次信息 // 3、记录批次信息
SysBatchInfo sysBatchInfo = new SysBatchInfo(); SysBatchInfo sysBatchInfo = new SysBatchInfo();
sysBatchInfo.setBatchId(IdHandler.nextId()); long sysBatchId = IdHandler.nextId();
sysBatchInfo.setBatchId(sysBatchId);
sysBatchInfo.setDmBatchId(dmHubBatchId); sysBatchInfo.setDmBatchId(dmHubBatchId);
sysBatchInfo.setId(IdHandler.nextId()); sysBatchInfo.setId(IdHandler.nextId());
sysBatchInfo.setDmTemplateId(templateId); sysBatchInfo.setDmTemplateId(templateId);
...@@ -221,8 +223,11 @@ public class MessageServiceImpl implements MessageService { ...@@ -221,8 +223,11 @@ public class MessageServiceImpl implements MessageService {
CLBizResponse response; CLBizResponse response;
// 判断模板是固定短信还是变量短信 // 判断模板是固定短信还是变量短信
JSONObject uidJson = new JSONObject();
uidJson.put("sysBatchId", String.valueOf(sysBatchId));
uidJson.put("dmHubId", dmHubBatchId);
if (paramsArr == null || paramsArr.isEmpty()) { if (paramsArr == null || paramsArr.isEmpty()) {
response = chuangLanSmsService.sendByFixed(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type); response = chuangLanSmsService.sendByFixed(uidJson, templateInfo.getUpContent(), sendParams.toString(), type);
String code = response.getCode(); String code = response.getCode();
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
...@@ -232,7 +237,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -232,7 +237,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubSendResponse(code, msg); return new DmHubSendResponse(code, msg);
} }
} else { } else {
response = chuangLanSmsService.sendByVariable(dmHubBatchId, templateInfo.getUpContent(), sendParams.toString(), type); response = chuangLanSmsService.sendByVariable(uidJson, templateInfo.getUpContent(), sendParams.toString(), type);
String code = response.getCode(); String code = response.getCode();
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
...@@ -244,8 +249,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -244,8 +249,7 @@ public class MessageServiceImpl implements MessageService {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误", e);
log.error("调用创蓝逻辑错误:{}", e);
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
} }
...@@ -253,16 +257,15 @@ public class MessageServiceImpl implements MessageService { ...@@ -253,16 +257,15 @@ public class MessageServiceImpl implements MessageService {
@Override @Override
public DmHubSendResponse batchSend(DmHubBatchSendRequest request) { public DmHubSendResponse batchSend(DmHubBatchSendRequest request) {
String batchId = request.getBatchId(); String batchId = request.getBatchId(); // DM hub 批次号
String templateId = request.getTemplateId(); String templateId = request.getTemplateId(); // 此次短信对应的模板id
String audienceIdType = request.getAudienceIdType(); String audienceIdType = request.getAudienceIdType();
List<JSONObject> data = request.getData(); List<JSONObject> data = request.getData();
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId)); SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) { if (null == templateInfo) {
return new DmHubSendResponse("500", "模板不存在"); return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
// 模板参数占位符 // 模板参数占位符
String params = templateInfo.getParams(); String params = templateInfo.getParams();
JSONArray paramsArr = JSONArray.parseArray(params); JSONArray paramsArr = JSONArray.parseArray(params);
...@@ -325,9 +328,12 @@ public class MessageServiceImpl implements MessageService { ...@@ -325,9 +328,12 @@ public class MessageServiceImpl implements MessageService {
sysBatchService.insert(info); sysBatchService.insert(info);
CLBizResponse response; CLBizResponse response;
JSONObject uidJson = new JSONObject();
uidJson.put("sysBatchId", String.valueOf(sysBatchId));
uidJson.put("dmHubId", batchId);
if (paramsArr == null || paramsArr.isEmpty()) { if (paramsArr == null || paramsArr.isEmpty()) {
try { try {
response = chuangLanSmsService.sendByFixed(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType()); response = chuangLanSmsService.sendByFixed(uidJson, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType());
String code = response.getCode(); String code = response.getCode();
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
...@@ -337,14 +343,14 @@ public class MessageServiceImpl implements MessageService { ...@@ -337,14 +343,14 @@ public class MessageServiceImpl implements MessageService {
return new DmHubSendResponse(code, msg); return new DmHubSendResponse(code, msg);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:{}", e); log.error("调用创蓝逻辑错误", e);
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
} else { } else {
try { try {
response = chuangLanSmsService.sendByVariable(batchId, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType()); response = chuangLanSmsService.sendByVariable(uidJson, templateInfo.getUpContent(), sendParams.toString(), templateInfo.getType());
String code = response.getCode(); String code = response.getCode();
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
...@@ -354,7 +360,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -354,7 +360,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubSendResponse(code, msg); return new DmHubSendResponse(code, msg);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:{}", e); log.error("调用创蓝逻辑错误:", e);
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
} }
} }
......
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