Commit e32b047a authored by qinxunjia's avatar qinxunjia

修改包名和一些配置

parent b9c0ae9a
package com.jz.sms.api;
import com.alibaba.fastjson.JSONObject;
import com.jz.sms.dto.DmHubBatchSendRequest;
import com.jz.sms.dto.DmHubBatchSendResponse;
import com.jz.sms.dto.DmHubTemplateRequest;
import com.jz.sms.dto.DmHubTemplateResponse;
import com.jz.sms.service.MessageService;
......@@ -42,10 +44,11 @@ public class BizController {
* @return
*/
@PostMapping("/sms/batch")
public String batch(@RequestParam Map<String, Object> params) {
log.info("**********批量发送入参*******:{}", params);
return "success";
public String batch(@RequestBody DmHubBatchSendRequest request) {
log.info("**********批量发送入参*******:{}", JSONObject.toJSONString(request));
DmHubBatchSendResponse response = messageService.batchSend(request);
// log.info("**********批量发送入参*******:{}", response);
return "fail";
}
......@@ -55,10 +58,10 @@ public class BizController {
* @return
*/
@RequestMapping("/sms/send")
public String send(@RequestParam Map<String, Object> params) {
public String send(@RequestBody Map<String, Object> params) {
log.info("**********单条发送入参*******:{}", params);
return "success";
log.info("**********单条发送入参*******:{}", JSONObject.toJSONString(params));
return "fail";
}
......
......@@ -2,7 +2,7 @@ package com.jz.sms.api;
import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -11,22 +11,33 @@ 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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@RequestMapping("/test/chuanglan")
@RestController
public class ChuangLanApi {
public static void main(String[] args) {
String regex = "\\$\\{([^'}]*)'\\}";
Pattern pattern = Pattern.compile (regex);
Matcher matcher = pattern.matcher ("你需要${a522}匹${555'}配的字符串");
while (matcher.find ())
{
System.out.println (matcher.group ());
}
}
private static final Logger log = LoggerFactory.getLogger(ChuangLanApi.class);
@Autowired
private ChuanLanSmsService chuanLanSmsService;
private ChuangLanSmsService chuangLanSmsService;
@PostMapping("/notify")
public String notify(@RequestParam CLNotifyRequest notifyInfo) {
log.info("创蓝异步通知接口入参:{}", notifyInfo);
chuanLanSmsService.asyncNotify(notifyInfo);
chuangLanSmsService.asyncNotify(notifyInfo);
String response = "success";
......
......@@ -34,57 +34,57 @@ public class ChuangLanSMSConfig {
public static String interfacePassword;
@Value("${system.config.chuanlan.notificationAccount}")
@Value("${system.config.chuanglan.notificationAccount}")
public void setNotificationAccount(String notificationAccount) {
ChuangLanSMSConfig.notificationAccount = notificationAccount;
}
@Value("${system.config.chuanlan.notificationPassword}")
@Value("${system.config.chuanglan.notificationPassword}")
public void setNotificationPassword(String notificationPassword) {
ChuangLanSMSConfig.notificationPassword = notificationPassword;
}
@Value("${system.config.chuanlan.marketingAccount}")
@Value("${system.config.chuanglan.marketingAccount}")
public void setMarketingAccount(String marketingAccount) {
ChuangLanSMSConfig.marketingAccount = marketingAccount;
}
@Value("${system.config.chuanlan.marketingPassword}")
@Value("${system.config.chuanglan.marketingPassword}")
public void setMarketingPassword(String marketingPassword) {
ChuangLanSMSConfig.marketingPassword = marketingPassword;
}
@Value("${system.config.chuanlan.sendFixed}")
@Value("${system.config.chuanglan.sendFixed}")
public void setSendFixed(String sendFixed) {
ChuangLanSMSConfig.sendFixed = sendFixed;
}
@Value("${system.config.chuanlan.sendVariable}")
@Value("${system.config.chuanglan.sendVariable}")
public void setSendVariable(String sendVariable) {
ChuangLanSMSConfig.sendVariable = sendVariable;
}
@Value("${system.config.chuanlan.reportUrl}")
@Value("${system.config.chuanglan.reportUrl}")
public void setReportUrl(String reportUrl) {
ChuangLanSMSConfig.reportUrl = reportUrl;
}
@Value("${system.config.chuanlan.pullReport}")
@Value("${system.config.chuanglan.pullReport}")
public void setPullReport(String pullReport) {
ChuangLanSMSConfig.pullReport = pullReport;
}
@Value("${system.config.chuanlan.addTemplate}")
@Value("${system.config.chuanglan.addTemplate}")
public void setAddTemplate(String addTemplate) {
ChuangLanSMSConfig.addTemplate = addTemplate;
}
@Value("${system.config.chuanlan.interfaceUser}")
@Value("${system.config.chuanglan.interfaceUser}")
public void setInterfaceUser(String interfaceUser) {
ChuangLanSMSConfig.interfaceUser = interfaceUser;
}
@Value("${system.config.chuanlan.interfacePassword}")
@Value("${system.config.chuanglan.interfacePassword}")
public void setInterfacePassword(String interfacePassword) {
ChuangLanSMSConfig.interfacePassword = interfacePassword;
}
......
......@@ -7,7 +7,7 @@ import com.jz.sms.dto.*;
import java.util.List;
public interface ChuanLanSmsService {
public interface ChuangLanSmsService {
CLTemplateResponse createTemplate(String content, String type) throws Exception;
......
......@@ -9,7 +9,7 @@ import com.jz.sms.chuanglan.dto.CLNotifyRequest;
import com.jz.sms.chuanglan.dto.CLSendFixedRequest;
import com.jz.sms.chuanglan.dto.CLSendFixedResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.chuanglan.utils.ChuangLanSmsUtil;
import com.jz.sms.chuanglan.config.ChuangLanSMSConfig;
import com.jz.sms.config.ResponseCode;
......@@ -31,7 +31,7 @@ import java.util.Map;
@SuppressWarnings("DuplicatedCode")
@Service
public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
public class ChuangLanSmsServiceImpl implements ChuangLanSmsService {
private static final Logger log = LoggerFactory.getLogger(BizController.class);
private static final String SUCCESS = "success";
......@@ -44,6 +44,7 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
@Override
public CLTemplateResponse createTemplate(String content, String type) throws Exception {
int i = 1 / 0;
log.info("进入创蓝创建短信接口模板的逻辑:{}", content);
Map<String, Object> requestMap = new HashMap<>();
String appId;
......@@ -59,12 +60,14 @@ public class ChuanLanSmsServiceImpl implements ChuanLanSmsService {
return new CLTemplateResponse(ResponseCode.SYSTEM_ERROR, "未知的模板类型:" + type, 0);
}
content = content.replaceAll("回TD退订", "");
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String encrypt = Md5Util.encrypt(new StringBuffer(username).append(password).append(timestamp).toString());
requestMap.put("username", username);
requestMap.put("timestamp", timestamp);
requestMap.put("signature", encrypt);
requestMap.put("appid", appId);
requestMap.put("unsubscribe", "回TD退订");
requestMap.put("content", content);
log.info("请求创蓝创建短信模板的请求参数为:{}", requestMap);
String retStr = HttpUtil.doPost(ChuangLanSMSConfig.addTemplate, requestMap);
......
......@@ -13,6 +13,9 @@ public class DmHubBatchSendRequest {
// 批次号
private String batchId;
// 批次号
private String audienceIdType;
// 短信数据
private List<JSONObject> data;
......@@ -40,4 +43,12 @@ public class DmHubBatchSendRequest {
public void setData(List<JSONObject> data) {
this.data = data;
}
public String getAudienceIdType() {
return audienceIdType;
}
public void setAudienceIdType(String audienceIdType) {
this.audienceIdType = audienceIdType;
}
}
package com.jz.sms.dto;
public class DmHubBatchSendResponse {
private String code;
private String msg;
public DmHubBatchSendResponse() {
}
public DmHubBatchSendResponse(String code, String msg) {
this.code = code;
this.msg = msg;
}
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;
}
}
......@@ -38,6 +38,7 @@ public class SmsTemplateInfo {
private String upTemplateId;
private String upRejectMsg;
private String params;
public SmsTemplateInfo() {
......@@ -152,4 +153,12 @@ public class SmsTemplateInfo {
public void setUpRejectMsg(String upRejectMsg) {
this.upRejectMsg = upRejectMsg;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
}
package com.jz.sms.service.bean;
import com.alibaba.fastjson.JSONArray;
import java.util.List;
public class TemplateChangeBean {
private String newStr;
private List<String> params;
public TemplateChangeBean() {
}
public TemplateChangeBean(String newStr, List<String> params) {
this.newStr = newStr;
this.params = params;
}
public String getNewStr() {
return newStr;
}
public void setNewStr(String newStr) {
this.newStr = newStr;
}
public List<String> getParams() {
return params;
}
public void setParams(List<String> params) {
this.params = params;
}
}
package com.jz.sms.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jz.sms.chuanglan.dto.CLSendFixedResponse;
import com.jz.sms.chuanglan.dto.CLTemplateResponse;
import com.jz.sms.chuanglan.service.ChuanLanSmsService;
import com.jz.sms.chuanglan.service.ChuangLanSmsService;
import com.jz.sms.config.ResponseCode;
import com.jz.sms.dto.*;
import com.jz.sms.repository.domain.SmsTemplateInfo;
import com.jz.sms.repository.domain.SysBatchInfo;
import com.jz.sms.service.MessageService;
import com.jz.sms.service.SmsTemplateService;
import com.jz.sms.service.bean.TemplateChangeBean;
import com.jz.sms.util.id.IdHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -35,9 +37,7 @@ public class MessageServiceImpl implements MessageService {
private SmsTemplateService smsTemplateService;
@Autowired
private ChuanLanSmsService chuanLanSmsService;
String a = "亲爱的${name@6!\"\"},您的手机号码:${mobile@12!\"\"}参与了优惠活动,详见: ${surl!'https://www.baidu.com/?cl_sr=短消息'} 回TD退订";
private ChuangLanSmsService chuangLanSmsService;
/**
* 短信模板创建
......@@ -59,7 +59,9 @@ public class MessageServiceImpl implements MessageService {
String templateName = requestDTO.getTemplateName();
// 替换模板格式,保存适合创蓝发送短信的模板,避免发送时修改模板格式
String chuanlanSend = dmHub2ChuanLanSend(templateContent);
TemplateChangeBean bean = dmHub2ChuangLanSend(templateContent);
String chuanglanSend = bean.getNewStr();
String params = bean.getParams().toString();
SmsTemplateInfo info = new SmsTemplateInfo();
info.setContent(templateContent);
......@@ -71,14 +73,16 @@ public class MessageServiceImpl implements MessageService {
info.setTemplateName(templateName);
info.setDateCreated(new Date());
info.setLastUpdated(new Date());
info.setUpContent(chuanlanSend);
info.setLastUpdated(new Date());
info.setUpContent(chuanglanSend);
info.setParams(params);
boolean insert = smsTemplateService.insert(info);
if (!insert) {
return new DmHubTemplateResponse("500", "系统异常");
//TODO 发送告警
}
String chaunglanCreate = dmHub2ChuanLanCreate(chuanlanSend);
CLTemplateResponse template = chuanLanSmsService.createTemplate(chaunglanCreate, smsType);
String chaunglanCreate = dmHub2ChuangLanCreate(chuanglanSend);
CLTemplateResponse template = chuangLanSmsService.createTemplate(chaunglanCreate, smsType);
if (ResponseCode.SUCCESS.getCode().equals(template.getCode())) {
String id = template.getId();
SmsTemplateInfo updateInfo = new SmsTemplateInfo();
......@@ -100,16 +104,13 @@ public class MessageServiceImpl implements MessageService {
}
public String dmHub2ChuanLanSend(String content) {
boolean flag = false;
if (content.contains("${surl!")) {
content = content.replaceAll("\\$\\{surl!'", "");
flag = true;
}
String upContent = content;
/**
* 将DM HUb的模板装成可以直接用在创蓝发送短信时的模板
*
* @param content
* @return
*/
public TemplateChangeBean dmHub2ChuangLanSend(String content) {
String regex = "\\$\\{[^}]+\\}";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(content);
......@@ -119,38 +120,41 @@ public class MessageServiceImpl implements MessageService {
String group = matcher.group();
groups.add(group);
}
if (groups.isEmpty()) {
return new TemplateChangeBean(content, groups);
}
int idx = content.indexOf("${surl!'");
if (idx >= 0) {
String substring = content.substring(idx);
System.out.println(substring);
int i1 = substring.indexOf("'}");
System.out.println(i1);
String substring1 = substring.substring(0, i1 + 2);
System.out.println(substring1);
System.out.println(content);
substring1 = Matcher.quoteReplacement(substring1);
substring1 = escapeRegex(substring1);
content = content.replaceAll(substring1, "\\{\\$var\\}");
}
for (String g : groups) {
String t = g;
g = Matcher.quoteReplacement(g);
g = escapeRegex(g);
if (g.contains("\\$\\{surl!")) {
int i = content.indexOf("${surl!");
String[] split = content.split(g);
StringBuilder sb = new StringBuilder();
String TmpContent = content.substring(i + "${surl!'".length(), i + t.length() - 2);
sb.append(split[0]).append(TmpContent).append(split[1]);
content = sb.toString();
}
content = content.replaceAll(g, "\\{\\$var\\}");
}
if (flag) {
content = content.replaceAll("'\\}", "");
return new TemplateChangeBean(content, groups);
}
// System.out.println(content);
return content;
}
public String dmHub2ChuanLanCreate(String content) {
public String dmHub2ChuangLanCreate(String content) {
content = content.replaceAll("\\{\\$var\\}", "\\{s20\\}");
return content;
}
public String escapeRegex(String s) {
public static String escapeRegex(String s) {
String[] symbols = new String[]{"\\/", "\\[", "\\]", "\\(", "\\)", "\\{", "\\}", "\\?", "\\+", "\\*", "\\|", "\\.", "\\^", "\\-", "\\^"};
if (s != null) {
for (String sym : symbols) {
......@@ -216,12 +220,12 @@ public class MessageServiceImpl implements MessageService {
for (String str : list) {
}
CLSendFixedResponse chuanglanResponse = chuanLanSmsService.sendByFixed(dmHubBatchId, content, phoneList, type);
CLSendFixedResponse chuanglanResponse = chuangLanSmsService.sendByFixed(dmHubBatchId, content, phoneList, type);
} else {
// 固定模板
// 4、封裝數據
chuanLanSmsService.sendByVariable(dmHubBatchId, content, phoneList, type);
chuangLanSmsService.sendByVariable(dmHubBatchId, content, phoneList, type);
}
......@@ -233,9 +237,39 @@ public class MessageServiceImpl implements MessageService {
}
@Override
public DmHubBatchSendResponse batchSend(DmHubBatchSendRequest requestDTO) {
public DmHubBatchSendResponse batchSend(DmHubBatchSendRequest request) {
String batchId = request.getBatchId();
String templateId = request.getTemplateId();
String audienceIdType = request.getAudienceIdType();
List<JSONObject> data = request.getData();
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) {
return new DmHubBatchSendResponse("500", "模板不存在");
}
for (JSONObject json : data) {
Set<String> keys = json.keySet();
StringBuilder sb = new StringBuilder();
String mobile = json.getString("_audienceId");
json.remove("name");
json.remove("id");
json.remove("_audienceId");
sb.append(mobile);
if (!json.isEmpty()) {
for (String key : keys) {
String value = json.getString(key);
}
}
}
return null;
}
}
......@@ -17,7 +17,7 @@ spring:
system:
config:
chuanlan:
chuanglan:
notificationAccount: N0767543 # 通知类短信账号
notificationPassword: N0767543 # 通知类短信密码
marketingAccount: M7603731 # 营销类短信账号
......
......@@ -18,7 +18,7 @@ spring:
system:
config:
chuanlan:
chuanglan:
notificationAccount: N0767543 # 通知类短信账号
notificationPassword: DaejS7P5ixaeee # 通知类短信密码
marketingAccount: M7603731 # 营销类短信账号
......
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