Commit b9c0ae9a authored by qinxunjia's avatar qinxunjia

创建模板的逻辑

parent e42d6120
...@@ -28,11 +28,11 @@ public class BizController { ...@@ -28,11 +28,11 @@ public class BizController {
* @return * @return
*/ */
@PostMapping("/sms/template") @PostMapping("/sms/template")
public String template(@RequestBody DmHubTemplateRequest params) { public DmHubTemplateResponse template(@RequestBody DmHubTemplateRequest params) {
log.info("**********创建模板入参*******:{}", JSONObject.toJSONString(params)); log.info("**********创建模板接口入参*******:{}", JSONObject.toJSONString(params));
DmHubTemplateResponse template = messageService.createTemplate(params); DmHubTemplateResponse template = messageService.createTemplate(params);
log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(template));
return "ok"; return template;
} }
......
package com.jz.sms.api;
import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RequestMapping("/test/chuanglan")
@RestController
public class ChuangLanApi {
private static final Logger log = LoggerFactory.getLogger(ChuangLanApi.class);
@Autowired
private ChuanLanSmsService chuanLanSmsService;
@PostMapping("/notify")
public String notify(@RequestParam CLNotifyRequest notifyInfo) {
log.info("创蓝异步通知接口入参:{}", notifyInfo);
chuanLanSmsService.asyncNotify(notifyInfo);
String response = "success";
log.info("创蓝异步通知接口出参:{}", response);
return response;
}
}
package com.jz.sms.config; package com.jz.sms.chuanglan.config;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component; ...@@ -7,7 +7,7 @@ import org.springframework.stereotype.Component;
* 短信参数配置 * 短信参数配置
*/ */
@Component @Component
public class SMSConfig { public class ChuangLanSMSConfig {
// 通知类短信账号 // 通知类短信账号
...@@ -28,50 +28,64 @@ public class SMSConfig { ...@@ -28,50 +28,64 @@ public class SMSConfig {
public static String pullReport; public static String pullReport;
// 创建短信模板 // 创建短信模板
public static String addTemplate; public static String addTemplate;
// 接口用户名
public static String interfaceUser;
// 接口密码
public static String interfacePassword;
@Value("${system.config.chuanlan.notificationAccount}") @Value("${system.config.chuanlan.notificationAccount}")
public void setNotificationAccount(String notificationAccount) { public void setNotificationAccount(String notificationAccount) {
SMSConfig.notificationAccount = notificationAccount; ChuangLanSMSConfig.notificationAccount = notificationAccount;
} }
@Value("${system.config.chuanlan.notificationPassword}") @Value("${system.config.chuanlan.notificationPassword}")
public void setNotificationPassword(String notificationPassword) { public void setNotificationPassword(String notificationPassword) {
SMSConfig.notificationPassword = notificationPassword; ChuangLanSMSConfig.notificationPassword = notificationPassword;
} }
@Value("${system.config.chuanlan.marketingAccount}") @Value("${system.config.chuanlan.marketingAccount}")
public void setMarketingAccount(String marketingAccount) { public void setMarketingAccount(String marketingAccount) {
SMSConfig.marketingAccount = marketingAccount; ChuangLanSMSConfig.marketingAccount = marketingAccount;
} }
@Value("${system.config.chuanlan.marketingPassword}") @Value("${system.config.chuanlan.marketingPassword}")
public void setMarketingPassword(String marketingPassword) { public void setMarketingPassword(String marketingPassword) {
SMSConfig.marketingPassword = marketingPassword; ChuangLanSMSConfig.marketingPassword = marketingPassword;
} }
@Value("${system.config.chuanlan.sendFixed}") @Value("${system.config.chuanlan.sendFixed}")
public void setSendFixed(String sendFixed) { public void setSendFixed(String sendFixed) {
SMSConfig.sendFixed = sendFixed; ChuangLanSMSConfig.sendFixed = sendFixed;
} }
@Value("${system.config.chuanlan.sendVariable}") @Value("${system.config.chuanlan.sendVariable}")
public void setSendVariable(String sendVariable) { public void setSendVariable(String sendVariable) {
SMSConfig.sendVariable = sendVariable; ChuangLanSMSConfig.sendVariable = sendVariable;
} }
@Value("${system.config.chuanlan.reportUrl}") @Value("${system.config.chuanlan.reportUrl}")
public void setReportUrl(String reportUrl) { public void setReportUrl(String reportUrl) {
SMSConfig.reportUrl = reportUrl; ChuangLanSMSConfig.reportUrl = reportUrl;
} }
@Value("${system.config.chuanlan.pullReport}") @Value("${system.config.chuanlan.pullReport}")
public void setPullReport(String pullReport) { public void setPullReport(String pullReport) {
SMSConfig.pullReport = pullReport; ChuangLanSMSConfig.pullReport = pullReport;
} }
@Value("${system.config.chuanlan.addTemplate}") @Value("${system.config.chuanlan.addTemplate}")
public void setAddTemplate(String addTemplate) { public void setAddTemplate(String addTemplate) {
SMSConfig.addTemplate = addTemplate; ChuangLanSMSConfig.addTemplate = addTemplate;
}
@Value("${system.config.chuanlan.interfaceUser}")
public void setInterfaceUser(String interfaceUser) {
ChuangLanSMSConfig.interfaceUser = interfaceUser;
}
@Value("${system.config.chuanlan.interfacePassword}")
public void setInterfacePassword(String interfacePassword) {
ChuangLanSMSConfig.interfacePassword = interfacePassword;
} }
} }
package com.jz.sms.chuanglan.dto;
public class CLNotifyRequest {
// 接口用户名
private String username;
// 十位时间戳
private String timestamp;
// 签名串
private String signature;
// 模块
private String action;
// 模板id
private String id;
// 审核状态(模板(1审核,2驳回),签名(2通过,3驳回))
private String auditStatus;
// 驳回原因
private String auditReason;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getAuditStatus() {
return auditStatus;
}
public void setAuditStatus(String auditStatus) {
this.auditStatus = auditStatus;
}
public String getAuditReason() {
return auditReason;
}
public void setAuditReason(String auditReason) {
this.auditReason = auditReason;
}
}
package com.jz.sms.chuanlan.dto; package com.jz.sms.chuanglan.dto;
public class CLSendFixedRequest { public class CLSendFixedRequest {
......
package com.jz.sms.chuanlan.dto; package com.jz.sms.chuanglan.dto;
import com.jz.sms.util.DateUtil;
import java.text.DateFormat;
public class CLSendFixedResponse { public class CLSendFixedResponse {
/** /**
......
package com.jz.sms.chuanlan.dto; package com.jz.sms.chuanglan.dto;
public class CLSendVariableRequest { public class CLSendVariableRequest {
......
package com.jz.sms.chuanlan.dto; package com.jz.sms.chuanglan.dto;
public class CLSendVariableResponse { public class CLSendVariableResponse {
/** /**
......
package com.jz.sms.chuanlan.dto; package com.jz.sms.chuanglan.dto;
public class CLTemplateRequest { public class CLTemplateRequest {
} }
package com.jz.sms.chuanglan.dto;
import com.jz.sms.config.ResponseCode;
import java.io.Serializable;
public class CLTemplateResponse implements Serializable {
private String code;
private String msg;
private String id;
public CLTemplateResponse() {
}
public CLTemplateResponse(ResponseCode responseCode, String id) {
this.code = responseCode.getCode();
this.msg = responseCode.getMsg();
this.id = id;
}
public CLTemplateResponse(ResponseCode responseCode, String msg,int nullInfo) {
this.code = responseCode.getCode();
this.msg = responseCode.getMsg()+msg;
}
public CLTemplateResponse(String code, String msg) {
this.code = code;
this.msg = msg;
}
public CLTemplateResponse(String code, String msg, String id) {
this.code = code;
this.msg = msg;
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package com.jz.sms.chuanlan.service; package com.jz.sms.chuanglan.service;
import com.jz.sms.chuanlan.dto.CLSendFixedResponse; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanlan.dto.CLTemplateResponse; import com.jz.sms.chuanglan.dto.CLSendFixedResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.dto.*; import com.jz.sms.dto.*;
import java.util.List; import java.util.List;
...@@ -23,4 +24,5 @@ public interface ChuanLanSmsService { ...@@ -23,4 +24,5 @@ public interface ChuanLanSmsService {
DmHubBatchSendResponse sendBatchByVariable(DmHubBatchSendRequest requestDTO); DmHubBatchSendResponse sendBatchByVariable(DmHubBatchSendRequest requestDTO);
void asyncNotify(CLNotifyRequest notifyInfo);
} }
package com.jz.sms.chuanlan.service.impl; package com.jz.sms.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.jz.sms.api.BizController; import com.jz.sms.api.BizController;
import com.jz.sms.chuanlan.dto.CLSendFixedRequest; import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanlan.dto.CLSendFixedResponse; import com.jz.sms.chuanglan.dto.CLSendFixedRequest;
import com.jz.sms.chuanlan.dto.CLTemplateResponse; import com.jz.sms.chuanglan.dto.CLSendFixedResponse;
import com.jz.sms.chuanlan.service.ChuanLanSmsService; import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanlan.utils.ChuangLanSmsUtil; import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import com.jz.sms.config.SMSConfig; import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.chuanglan.config.ChuangLanSMSConfig;
import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*; import com.jz.sms.dto.*;
import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.util.HttpUtil; import com.jz.sms.util.HttpUtil;
import com.jz.sms.util.Md5Util; import com.jz.sms.util.Md5Util;
import org.apache.commons.lang3.StringUtils; 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.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -29,25 +34,29 @@ import java.util.Map; ...@@ -29,25 +34,29 @@ import java.util.Map;
public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
private static final Logger log = LoggerFactory.getLogger(BizController.class); private static final Logger log = LoggerFactory.getLogger(BizController.class);
private static final String SUCCESS = "success";
private static final String ERROR = "error";
private static final String CODE = "code";
private static final String DATA = "data";
@Autowired
private SmsTemplateService templateService;
@Override @Override
public CLTemplateResponse createTemplate(String content, String type) throws Exception { public CLTemplateResponse createTemplate(String content, String type) throws Exception {
log.info("进入创蓝创建短信接口模板的逻辑:{}", content); log.info("进入创蓝创建短信接口模板的逻辑:{}", content);
Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> requestMap = new HashMap<>();
String appId; String appId;
String username; String username = ChuangLanSMSConfig.interfaceUser;
String password; String password = ChuangLanSMSConfig.interfacePassword;
if ("notification".equals(type)) { if ("notification".equals(type)) {
appId = "49"; appId = "49";
username = SMSConfig.notificationAccount;
password = SMSConfig.notificationPassword;
} else if ("marketing".equals(type)) { } else if ("marketing".equals(type)) {
appId = "52"; appId = "52";
username = SMSConfig.marketingAccount;
password = SMSConfig.notificationPassword;
} else { } else {
// TODO 自定义异常 // TODO 自定义异常,发送警告
throw new Exception(""); log.error("错误,传入的模板类型未知,类型为:{}", type);
return new CLTemplateResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0);
} }
String timestamp = String.valueOf(System.currentTimeMillis() / 1000); String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
...@@ -58,10 +67,18 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -58,10 +67,18 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
requestMap.put("appid", appId); requestMap.put("appid", appId);
requestMap.put("content", content); requestMap.put("content", content);
log.info("请求创蓝创建短信模板的请求参数为:{}", requestMap); log.info("请求创蓝创建短信模板的请求参数为:{}", requestMap);
String retStr = HttpUtil.doPost(SMSConfig.addTemplate, requestMap); String retStr = HttpUtil.doPost(ChuangLanSMSConfig.addTemplate, requestMap);
log.info("请求创蓝创建短信模板的返回数据为:{}", retStr); log.info("请求创蓝创建短信模板的返回数据为:{}", retStr);
JSONObject retJson = JSONObject.parseObject(retStr);
return new CLTemplateResponse(); String status = retJson.getString("status");
if (SUCCESS.equals(status)) {
JSONObject data = retJson.getJSONObject("data");
String id = data.getString("id");
return new CLTemplateResponse(ResponseCode.SUCCESS, id);
} else {
String msg = retJson.getString("msg");
return new CLTemplateResponse(ResponseCode.UPSTREAM_FAIL.getCode(), msg);
}
} }
@Override @Override
...@@ -69,12 +86,12 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -69,12 +86,12 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if ("notification".equals(type)) {
account = SMSConfig.notificationAccount; account = ChuangLanSMSConfig.notificationAccount;
password = SMSConfig.notificationPassword; password = ChuangLanSMSConfig.notificationPassword;
log.info("发送短信的模式为:{通知类}"); log.info("发送短信的模式为:{通知类}");
} else if ("marketing".equals(type)) { } else if ("marketing".equals(type)) {
account = SMSConfig.marketingAccount; account = ChuangLanSMSConfig.marketingAccount;
password = SMSConfig.marketingPassword; password = ChuangLanSMSConfig.marketingPassword;
log.info("发送短信的模式为:{营销类}"); log.info("发送短信的模式为:{营销类}");
} else { } else {
log.info("发送短信的模式为:{未知类型}"); log.info("发送短信的模式为:{未知类型}");
...@@ -85,7 +102,7 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -85,7 +102,7 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(SMSConfig.sendFixed, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendFixed, requestJson);
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson);
if (StringUtils.isBlank(responseStr)) { if (StringUtils.isBlank(responseStr)) {
...@@ -100,23 +117,17 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -100,23 +117,17 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
return s; return s;
} }
public static void main(String[] args) {
List<String> arr = new ArrayList<>();
arr.add("aa,444");
System.out.printf(arr.toString());
}
@Override @Override
public CLSendFixedResponse sendByVariable(String batchId, String content, List<String> params, String type) throws Exception { public CLSendFixedResponse sendByVariable(String batchId, String content, List<String> params, String type) throws Exception {
String account; String account;
String password; String password;
if ("notification".equals(type)) { if ("notification".equals(type)) {
account = SMSConfig.notificationAccount; account = ChuangLanSMSConfig.notificationAccount;
password = SMSConfig.notificationPassword; password = ChuangLanSMSConfig.notificationPassword;
log.info("发送短信的模式为:{通知类}"); log.info("发送短信的模式为:{通知类}");
} else if ("marketing".equals(type)) { } else if ("marketing".equals(type)) {
account = SMSConfig.marketingAccount; account = ChuangLanSMSConfig.marketingAccount;
password = SMSConfig.marketingPassword; password = ChuangLanSMSConfig.marketingPassword;
log.info("发送短信的模式为:{营销类}"); log.info("发送短信的模式为:{营销类}");
} else { } else {
log.info("发送短信的模式为:{未知类型}"); log.info("发送短信的模式为:{未知类型}");
...@@ -127,7 +138,7 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -127,7 +138,7 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
String requestJson = JSONObject.toJSONString(request); String requestJson = JSONObject.toJSONString(request);
log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,请求上游数据为:{}", batchId, requestJson);
String responseStr = ChuangLanSmsUtil.sendSmsByPost(SMSConfig.sendFixed, requestJson); String responseStr = ChuangLanSmsUtil.sendSmsByPost(ChuangLanSMSConfig.sendFixed, requestJson);
log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson); log.info("【{}】发送固定内容短信,上游返回数据为:{}", batchId, requestJson);
if (StringUtils.isBlank(responseStr)) { if (StringUtils.isBlank(responseStr)) {
...@@ -146,4 +157,22 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService { ...@@ -146,4 +157,22 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
public DmHubBatchSendResponse sendBatchByVariable(DmHubBatchSendRequest requestDTO) { public DmHubBatchSendResponse sendBatchByVariable(DmHubBatchSendRequest requestDTO) {
return null; return null;
} }
@Override
public void asyncNotify(CLNotifyRequest notifyInfo) {
String action = notifyInfo.getAction();
if (!"messageModel".equals(action)) {
return;
}
String id = notifyInfo.getId();
String status = notifyInfo.getAuditStatus();
if (!"1".equals(status)) {
String msg = notifyInfo.getAuditReason();
boolean update = templateService.updateForSet("status = abnormal,up_reject_msg = " + msg, new EntityWrapper<SmsTemplateInfo>().eq("up_template_id", id));
// TODO 发送钉钉告警
log.error("短信模板审核不通过,原因:{}", msg);
}
}
} }
package com.jz.sms.chuanlan.utils; package com.jz.sms.chuanglan.utils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
......
package com.jz.sms.chuanlan.dto;
public class CLTemplateResponse {
}
package com.jz.sms.config;
public enum ResponseCode {
SUCCESS("200", "处理成功"),
UPSTREAM_FAIL("UF01", "渠道交易失败"),
SYSTEM_ERROR("99", "系统异常:");
private String code;
private String msg;
ResponseCode(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
...@@ -36,6 +36,9 @@ public class SmsTemplateInfo { ...@@ -36,6 +36,9 @@ public class SmsTemplateInfo {
private String templateName; private String templateName;
private String upTemplateId;
private String upRejectMsg;
public SmsTemplateInfo() { public SmsTemplateInfo() {
} }
...@@ -133,4 +136,20 @@ public class SmsTemplateInfo { ...@@ -133,4 +136,20 @@ public class SmsTemplateInfo {
public void setLastUpdated(Date lastUpdated) { public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated; this.lastUpdated = lastUpdated;
} }
public String getUpTemplateId() {
return upTemplateId;
}
public void setUpTemplateId(String upTemplateId) {
this.upTemplateId = upTemplateId;
}
public String getUpRejectMsg() {
return upRejectMsg;
}
public void setUpRejectMsg(String upRejectMsg) {
this.upRejectMsg = upRejectMsg;
}
} }
...@@ -2,9 +2,10 @@ package com.jz.sms.service.impl; ...@@ -2,9 +2,10 @@ package com.jz.sms.service.impl;
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.chuanlan.dto.CLSendFixedResponse; import com.jz.sms.chuanglan.dto.CLSendFixedResponse;
import com.jz.sms.chuanlan.dto.CLTemplateResponse; import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanlan.service.ChuanLanSmsService; import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*; import com.jz.sms.dto.*;
import com.jz.sms.repository.domain.SmsTemplateInfo; import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.repository.domain.SysBatchInfo; import com.jz.sms.repository.domain.SysBatchInfo;
...@@ -36,6 +37,8 @@ public class MessageServiceImpl implements MessageService { ...@@ -36,6 +37,8 @@ public class MessageServiceImpl implements MessageService {
@Autowired @Autowired
private ChuanLanSmsService chuanLanSmsService; private ChuanLanSmsService chuanLanSmsService;
String a = "亲爱的${name@6!\"\"},您的手机号码:${mobile@12!\"\"}参与了优惠活动,详见: ${surl!'https://www.baidu.com/?cl_sr=短消息'} 回TD退订";
/** /**
* 短信模板创建 * 短信模板创建
* *
...@@ -56,7 +59,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -56,7 +59,7 @@ public class MessageServiceImpl implements MessageService {
String templateName = requestDTO.getTemplateName(); String templateName = requestDTO.getTemplateName();
// 替换模板格式,保存适合创蓝发送短信的模板,避免发送时修改模板格式 // 替换模板格式,保存适合创蓝发送短信的模板,避免发送时修改模板格式
String upContent = dmHub2ChuanLan(templateContent); String chuanlanSend = dmHub2ChuanLanSend(templateContent);
SmsTemplateInfo info = new SmsTemplateInfo(); SmsTemplateInfo info = new SmsTemplateInfo();
info.setContent(templateContent); info.setContent(templateContent);
...@@ -68,13 +71,26 @@ public class MessageServiceImpl implements MessageService { ...@@ -68,13 +71,26 @@ public class MessageServiceImpl implements MessageService {
info.setTemplateName(templateName); info.setTemplateName(templateName);
info.setDateCreated(new Date()); info.setDateCreated(new Date());
info.setLastUpdated(new Date()); info.setLastUpdated(new Date());
info.setUpContent(upContent); info.setUpContent(chuanlanSend);
boolean insert = smsTemplateService.insert(info); boolean insert = smsTemplateService.insert(info);
if (!insert) { if (!insert) {
return new DmHubTemplateResponse("500", "系统异常");
//TODO 发送告警 //TODO 发送告警
} }
CLTemplateResponse template = chuanLanSmsService.createTemplate(templateContent, smsType); String chaunglanCreate = dmHub2ChuanLanCreate(chuanlanSend);
CLTemplateResponse template = chuanLanSmsService.createTemplate(chaunglanCreate, smsType);
if (ResponseCode.SUCCESS.getCode().equals(template.getCode())) {
String id = template.getId();
SmsTemplateInfo updateInfo = new SmsTemplateInfo();
updateInfo.setId(info.getId());
updateInfo.setUpTemplateId(id);
smsTemplateService.updateById(updateInfo);
return responseDTO;
} else {
//TODO 发送告警,模板添加失败。
return new DmHubTemplateResponse(template.getCode(), template.getMsg());
}
} catch (Exception exception) { } catch (Exception exception) {
log.error("错误信息", exception); log.error("错误信息", exception);
responseDTO = new DmHubTemplateResponse("500", "系统异常"); responseDTO = new DmHubTemplateResponse("500", "系统异常");
...@@ -84,13 +100,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -84,13 +100,7 @@ public class MessageServiceImpl implements MessageService {
} }
public String dmHub2ChuanLan(String content) { public String dmHub2ChuanLanSend(String content) {
// String content = "亲爱的${name@0!\"\"},您好!点击以下链接可以获取10元优惠券哦! ${surl!'https://www.baidu.com/?abcdesf=${name}&cl_sr=短消息'}";
// String content = "亲爱的${name@6!\"\"},您的手机号码:${mobile@12!\"\"}参与了优惠活动,详见: ${surl!'https://www.baidu.com/?cl_sr=短消息'} 回TD退订";
// String content = "感谢你的关注";
// String content = "亲爱的${name@0!\"\"},您好!点击以下链接可以获取10元优惠券哦! ${surl!'https://www.baidu.com/?abcdesf=${name}&cl_sr=短消息'}";
//
boolean flag = false; boolean flag = false;
if (content.contains("${surl!")) { if (content.contains("${surl!")) {
...@@ -134,6 +144,12 @@ public class MessageServiceImpl implements MessageService { ...@@ -134,6 +144,12 @@ public class MessageServiceImpl implements MessageService {
} }
public String dmHub2ChuanLanCreate(String content) {
content = content.replaceAll("\\{\\$var\\}", "\\{s20\\}");
return content;
}
public String escapeRegex(String s) { public String escapeRegex(String s) {
String[] symbols = new String[]{"\\/", "\\[", "\\]", "\\(", "\\)", "\\{", "\\}", "\\?", "\\+", "\\*", "\\|", "\\.", "\\^", "\\-", "\\^"}; String[] symbols = new String[]{"\\/", "\\[", "\\]", "\\(", "\\)", "\\{", "\\}", "\\?", "\\+", "\\*", "\\|", "\\.", "\\^", "\\-", "\\^"};
if (s != null) { if (s != null) {
......
...@@ -27,3 +27,5 @@ system: ...@@ -27,3 +27,5 @@ system:
reportUrl: http://test.9z.com/msg/report # 短信报告 reportUrl: http://test.9z.com/msg/report # 短信报告
pullReport: http://smssh1.253.com/msg/pull/report # 拉取短信报告 pullReport: http://smssh1.253.com/msg/pull/report # 拉取短信报告
addTemplate: https://zz.253.com/apis/template/add # 创建短信模板 addTemplate: https://zz.253.com/apis/template/add # 创建短信模板
interfaceUser: admin001 # 接口用户名
interfacePassword: 9zdata0423 # 接口密码
\ No newline at end of file
...@@ -28,4 +28,6 @@ system: ...@@ -28,4 +28,6 @@ system:
reportUrl: http://test.9z.com/msg/report # 短信报告 reportUrl: http://test.9z.com/msg/report # 短信报告
pullReport: http://smssh1.253.com/msg/pull/report # 拉取短信报告 pullReport: http://smssh1.253.com/msg/pull/report # 拉取短信报告
addTemplate: https://zz.253.com/apis/template/add # 创建短信模板 addTemplate: https://zz.253.com/apis/template/add # 创建短信模板
interfaceUser: admin001 # 接口用户名
interfacePassword: 9zdata0423 # 接口密码
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