Commit f0999109 authored by fuwanli's avatar fuwanli

"模板优化"

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