Commit f0999109 authored by fuwanli's avatar fuwanli

"模板优化"

parent dc422fdc
package com.bgy.sms.channel.bgy.service; package com.bgy.sms.channel.bgy.service;
import com.alibaba.fastjson.JSONObject;
import com.bgy.sms.channel.bgy.dto.CLBizResponse; import com.bgy.sms.channel.bgy.dto.CLBizResponse;
import com.bgy.sms.channel.bgy.dto.TemplateNotify; import com.bgy.sms.channel.bgy.dto.TemplateNotify;
public interface BgySmsService { public interface BgySmsService {
CLBizResponse sendSms(String mobile, String content, String areaId) throws Exception; CLBizResponse sendSms(String mobile, String content, String areaId,String api) throws Exception;
CLBizResponse sendbatchSms(String mobile, String areaId) throws Exception; CLBizResponse sendbatchSms(String mobile, String areaId,String api) throws Exception;
CLBizResponse createTemplate(String content,String account,String templateType,String pkID) throws Exception;
void asyncNotify(TemplateNotify templateNotify); void asyncNotify(TemplateNotify templateNotify);
......
...@@ -12,12 +12,14 @@ import com.bgy.sms.channel.dmHub.service.DmHubService; ...@@ -12,12 +12,14 @@ import com.bgy.sms.channel.dmHub.service.DmHubService;
import com.bgy.sms.config.ResponseCode; import com.bgy.sms.config.ResponseCode;
import com.bgy.sms.repository.domain.SmsTemplateInfo; import com.bgy.sms.repository.domain.SmsTemplateInfo;
import com.bgy.sms.service.SmsTemplateService; import com.bgy.sms.service.SmsTemplateService;
import com.bgy.util.HttpUtil;
import com.bgy.util.Md5Util; import com.bgy.util.Md5Util;
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;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -43,14 +45,17 @@ public class BgySmsServiceImpl implements BgySmsService { ...@@ -43,14 +45,17 @@ public class BgySmsServiceImpl implements BgySmsService {
@Autowired @Autowired
private SmsTemplateService smsTemplateService; private SmsTemplateService smsTemplateService;
@Override @Override
public CLBizResponse sendSms(String mobile, String content, String areaId) throws Exception { public CLBizResponse sendSms(String mobile, String content, String areaId,String api) throws Exception {
log.info("进入碧桂园短信发送接口"); log.info("进入碧桂园短信发送接口");
String appId = BgySMSConfig.appId; String appId = BgySMSConfig.appId;
// String areaId = BgySMSConfig.areaId; // String areaId = BgySMSConfig.areaId;
String securityCode = BgySMSConfig.securityCode; String securityCode = BgySMSConfig.securityCode;
String url = BgySMSConfig.url; String url = BgySMSConfig.url;
String api = BgySMSConfig.api; if (api==null) {
api = BgySMSConfig.api;
}
Map<String, String> requestParams = new HashMap<>(); Map<String, String> requestParams = new HashMap<>();
requestParams.put("api", api); requestParams.put("api", api);
requestParams.put("appId", appId); requestParams.put("appId", appId);
...@@ -79,13 +84,13 @@ public class BgySmsServiceImpl implements BgySmsService { ...@@ -79,13 +84,13 @@ public class BgySmsServiceImpl implements BgySmsService {
} }
@Override @Override
public CLBizResponse sendbatchSms(String data, String areaId) throws Exception { public CLBizResponse sendbatchSms(String data, String areaId,String api) throws Exception {
log.info("进入碧桂园短信发送接口"); log.info("进入碧桂园短信发送接口");
String appId = BgySMSConfig.appId; String appId = BgySMSConfig.appId;
// String areaId = BgySMSConfig.areaId; // String areaId = BgySMSConfig.areaId;
String securityCode = BgySMSConfig.securityCode; String securityCode = BgySMSConfig.securityCode;
String url = BgySMSConfig.url; String url = BgySMSConfig.url;
String api = BgySMSConfig.api; // String api = BgySMSConfig.api;
Map<String, String> requestParams = new HashMap<>(); Map<String, String> requestParams = new HashMap<>();
requestParams.put("api", api); requestParams.put("api", api);
requestParams.put("appId", appId); requestParams.put("appId", appId);
...@@ -119,26 +124,72 @@ public class BgySmsServiceImpl implements BgySmsService { ...@@ -119,26 +124,72 @@ public class BgySmsServiceImpl implements BgySmsService {
*/ */
@Override @Override
public void asyncNotify(TemplateNotify templateNotify) { public void asyncNotify(TemplateNotify templateNotify) {
log.info("碧桂园短信模板审核通知接口入参:{}",templateNotify); log.info("碧桂园短信模板审核通知接口入参:{}", templateNotify);
//模板流水号 //模板流水号
String templateRecordId = templateNotify.getData(); String templateRecordId = templateNotify.getData();
String status = templateNotify.getAuditStatus(); String status = templateNotify.getAuditStatus();
String auditReason = templateNotify.getAuditReason(); String auditReason = templateNotify.getAuditReason();
SmsTemplateInfo smsTemplateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("template_record_id",templateRecordId)); SmsTemplateInfo smsTemplateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("template_record_id", templateRecordId));
if (smsTemplateInfo == null){ if (smsTemplateInfo == null) {
throw new RuntimeException(ResponseCode.NO_TEMPLATE.getMsg()); throw new RuntimeException(ResponseCode.NO_TEMPLATE.getMsg());
} }
if ("1".equals(status)){ if ("1".equals(status)) {
smsTemplateInfo.setStatus("normal"); smsTemplateInfo.setStatus("normal");
}else { smsTemplateInfo.setLastUpdated(new Date());
} else {
smsTemplateInfo.setStatus("abnormal"); smsTemplateInfo.setStatus("abnormal");
} }
smsTemplateInfo.setUpRejectMsg(auditReason); smsTemplateInfo.setUpRejectMsg(auditReason);
smsTemplateInfo.setLastUpdated(new Date());
smsTemplateService.updateById(smsTemplateInfo); smsTemplateService.updateById(smsTemplateInfo);
} }
@Override
public CLBizResponse createTemplate(String content, String account, String templateType, String pkID) throws Exception {
log.info("进入碧桂园创建模板接口");
String appId = BgySMSConfig.appId;
// String areaId = BgySMSConfig.areaId;
String securityCode = BgySMSConfig.securityCode;
Map<String, String> param = new HashMap<>();
param.put("api", "AddTemplate");//TODO
param.put("appid", appId);
param.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase()));
param.put("content", content);
param.put("areaid", "XXJSB");
param.put("pkID", pkID);
param.put("slxtID", account);
param.put("templateType", templateType);
log.info("碧桂园创建模板接口参数:{}", param);
String retStr = HttpUtil.sendPost(BgySMSConfig.url, JSONObject.toJSONString(param));
log.info("碧桂园创建模板接口返回信息:{}", retStr);
if (retStr == null) {
return new CLBizResponse(ResponseCode.UPSTREAM_BLANK);
}
JSONObject retJson = JSONObject.parseObject(retStr);
String err = retJson.getString("err");
String retPack = retJson.getString("package");
String retCode = retJson.getString("ret");
if (!sendSuccessCode.equals(retCode)) {
if (err.contains("成功")) {
JSONObject Json = JSONObject.parseObject(retPack);
String data = Json.getString("data");
return new CLBizResponse(ResponseCode.SUCCESS.getCode(), data);
}
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), err);
} else {
JSONObject Json = JSONObject.parseObject(retPack);
String data = Json.getString("data");
return new CLBizResponse(ResponseCode.SUCCESS.getCode(), data);
}
}
public static void main(String[] args) { public static void main(String[] args) {
...@@ -147,7 +198,7 @@ public class BgySmsServiceImpl implements BgySmsService { ...@@ -147,7 +198,7 @@ public class BgySmsServiceImpl implements BgySmsService {
System.out.println(a); System.out.println(a);
System.out.println(appId); System.out.println(appId);
if (1==1) { if (1 == 1) {
return; return;
} }
// String areaId = BgySMSConfig.areaId; // String areaId = BgySMSConfig.areaId;
......
...@@ -98,43 +98,30 @@ public class MessageServiceImpl implements MessageService { ...@@ -98,43 +98,30 @@ public class MessageServiceImpl implements MessageService {
String securityCode = BgySMSConfig.securityCode; String securityCode = BgySMSConfig.securityCode;
String pkID = info.getId() + ""; String pkID = info.getId() + "";
String content = info.getContent(); String content = info.getContent();
String TEMPLATETYPE = "52";
JSONObject param = new JSONObject(); String TEMPLATETYPE = "";
param.put("api", "AddTemplate"); if ("marketing".equals(smsType)) {
param.put("appid", appId); TEMPLATETYPE = "52";
param.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase())); } else {
param.put("content", content); TEMPLATETYPE = "49";
param.put("areaid", "FHY"); }
param.put("pkID", pkID); String account = "SZH003";
param.put("account", "SZH003"); CLBizResponse response = new CLBizResponse();
param.put("templateType", TEMPLATETYPE);
response = bgySmsService.createTemplate(content, account, TEMPLATETYPE, pkID);
String retStr = HttpUtil.sendPost(BgySMSConfig.url, JSONObject.toJSONString(param));
JSONObject retJson = JSONObject.parseObject(retStr); String code = response.getCode();
String reePackage = retJson.getString("package"); String msg = response.getMsg();
String err = retJson.getString("err"); if (code.equals(ResponseCode.SUCCESS.getCode())) {
String retCode = retJson.getString("ret");
info.setTemplateRecordId(msg);
if ("0".equals(retCode)) {
if (err.contains("成功")) {
JSONObject Json = JSONObject.parseObject(reePackage);
String data = Json.getString("data");
info.setTemplateRecordId(data);
info.setId(Long.parseLong(pkID)); info.setId(Long.parseLong(pkID));
smsTemplateService.updateById(info); smsTemplateService.updateById(info);
responseDTO.setCode(ResponseCode.SUCCESS.getCode()); return new DmHubResponse(ResponseCode.SUCCESS);
responseDTO.setError(JSONObject.parseObject(JSONObject.toJSONString(err)));
return responseDTO;
}
responseDTO.setCode(ResponseCode.SYSTEM_ERROR.getCode());
responseDTO.setError(retJson);
return responseDTO;
} else { } else {
responseDTO.setCode(ResponseCode.SYSTEM_ERROR.getCode());
responseDTO.setError(retJson);
return responseDTO;
}
return new DmHubResponse(code, msg);
}
} }
} catch (Exception exception) { } catch (Exception exception) {
log.error("创建模板业务逻辑异常,错误信息", exception); log.error("创建模板业务逻辑异常,错误信息", exception);
...@@ -296,7 +283,15 @@ public class MessageServiceImpl implements MessageService { ...@@ -296,7 +283,15 @@ public class MessageServiceImpl implements MessageService {
String upContent = templateInfo.getUpContent(); String upContent = templateInfo.getUpContent();
content = getMsg(upContent, paramList); content = getMsg(upContent, paramList);
} }
response = bgySmsService.sendSms(mobile, content, areaId);
String api = "";
if ("marketing".equals(smsType)) {
api = "SendYXSMS";
} else {
api = "SendNotifySMS";
}
response = bgySmsService.sendSms(mobile, content, areaId,api);
//4.短信发送记录 //4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo(); SysRecordInfo sysRecordInfo = new SysRecordInfo();
...@@ -348,7 +343,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -348,7 +343,7 @@ public class MessageServiceImpl implements MessageService {
codeInfo.setMobile(mobile); codeInfo.setMobile(mobile);
codeInfo.setDateCreated(new Date()); codeInfo.setDateCreated(new Date());
dmCodeService.insert(codeInfo); dmCodeService.insert(codeInfo);
response = bgySmsService.sendSms(mobile, content, BgySMSConfig.areaId); response = bgySmsService.sendSms(mobile, content, BgySMSConfig.areaId,null);
String retCode = response.getCode(); String retCode = response.getCode();
if (retCode.equals(ResponseCode.SUCCESS.getCode())) { if (retCode.equals(ResponseCode.SUCCESS.getCode())) {
return new DmHubResponse(ResponseCode.SUCCESS); return new DmHubResponse(ResponseCode.SUCCESS);
...@@ -387,6 +382,14 @@ public class MessageServiceImpl implements MessageService { ...@@ -387,6 +382,14 @@ public class MessageServiceImpl implements MessageService {
if (null == templateInfo) { if (null == templateInfo) {
return new DmHubResponse("999", "短信插件未获取到模板信息"); return new DmHubResponse("999", "短信插件未获取到模板信息");
} }
String api = "";
if ("marketing".equals(templateInfo.getType())) {
api = "SendYXSMS";
} else {
api = "SendNotifySMS";
}
String smsType = templateInfo.getType(); String smsType = templateInfo.getType();
String templateName = templateInfo.getTemplateName(); String templateName = templateInfo.getTemplateName();
String[] split = templateName.split("_"); String[] split = templateName.split("_");
...@@ -476,18 +479,18 @@ public class MessageServiceImpl implements MessageService { ...@@ -476,18 +479,18 @@ public class MessageServiceImpl implements MessageService {
String content = templateInfo.getUpContent(); String content = templateInfo.getUpContent();
for (String mobile : mobileList) { for (String mobile : mobileList) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
mobiles.append(mobile+","); mobiles.append(mobile + ",");
jsonObject.put("mobile", mobile); jsonObject.put("mobile", mobile);
jsonObject.put("content", content); jsonObject.put("content", content);
list.add(jsonObject); list.add(jsonObject);
} }
try { try {
if (!list.isEmpty()) { if (!list.isEmpty()) {
response = bgySmsService.sendbatchSms(list.toString(), areaId); response = bgySmsService.sendbatchSms(list.toString(), areaId,api);
String code = response.getCode(); String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) { if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size()); sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length()-1).toString()); sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length() - 1).toString());
sysRecordInfo.setContent(content); sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode()); sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode());
...@@ -497,7 +500,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -497,7 +500,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg()); return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
} else { } else {
sysRecordInfo.setChargeNum(list.size()); sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length()-1).toString()); sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length() - 1).toString());
sysRecordInfo.setContent(content); sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode()); sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode());
...@@ -525,18 +528,18 @@ public class MessageServiceImpl implements MessageService { ...@@ -525,18 +528,18 @@ public class MessageServiceImpl implements MessageService {
String sendMsg = getMsg(templateInfo.getUpContent(), paramsList); String sendMsg = getMsg(templateInfo.getUpContent(), paramsList);
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
mobiles.append(mobile+","); mobiles.append(mobile + ",");
jsonObject.put("mobile", mobile); jsonObject.put("mobile", mobile);
jsonObject.put("content", sendMsg); jsonObject.put("content", sendMsg);
list.add(jsonObject); list.add(jsonObject);
} }
try { try {
response = bgySmsService.sendbatchSms(list.toString(), areaId); response = bgySmsService.sendbatchSms(list.toString(), areaId,api);
String code = response.getCode(); String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) { if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size()); sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length()-1).toString()); sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length() - 1).toString());
sysRecordInfo.setContent(content); sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode()); sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode());
...@@ -546,7 +549,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -546,7 +549,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg()); return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
} else { } else {
sysRecordInfo.setChargeNum(list.size()); sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length()-1).toString()); sysRecordInfo.setMobile(mobiles.deleteCharAt(mobiles.length() - 1).toString());
sysRecordInfo.setContent(content); sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode()); sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode());
......
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