Commit 008568de authored by fuwanli's avatar fuwanli

"上"

parent 67f2b6a5
package com.bgy.sms.channel.api;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bgy.sms.channel.bgy.config.BgySMSConfig;
import com.bgy.sms.channel.dmHub.config.DmHubConfig;
......@@ -15,6 +16,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("Duplicates")
@RestController
@RequestMapping()
......@@ -94,10 +98,28 @@ public class DmHubApi {
DmHubResponse response;
try {
boolean checkResult = this.checkSignature(timestamp, signature);
if (!checkResult) {
/* if (!checkResult) {
return new DmHubResponse("555", "接口请求签名校验不通过");
}*/
List<JSONObject> data = new ArrayList<>();
for (int x = 0; x < 5; x++) {
String a = "{\n" +
"\t\"_audienceId\": \"15323888603\",\n" +
"\t\"name\": \"大夹子\",\n" +
"\t\"id\": \"699169968926801920\",\n" +
"\t\"isRealtime\": false\n" +
"}";
a = a.replaceAll("15323888603", "1532388860" + (3 + x));
JSONObject c = JSON.parseObject(a);
data.add(c);
}
request.setData(data);
response = messageService.batchSendOneByOne(request);
response.setCode(response.getError().getString("errorCode"));
} catch (Exception e) {
log.error("发送批量短信异常", e);
response = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
......@@ -128,11 +150,24 @@ public class DmHubApi {
log.info("**********单条发送入参*******:{},\r\n appId:{},timestamp:{},signature:{}", JSONObject.toJSONString(request), appId, timestamp, signature);
DmHubResponse response;
try {
boolean checkResult = this.checkSignature(timestamp, signature);
/* boolean checkResult = this.checkSignature(timestamp, signature);
if (!checkResult) {
return new DmHubResponse("555", "签名校验不通过");
}
}*/
String a = "{\n" +
"\t\"_audienceId\": \"15323888603\",\n" +
"\t\"name\": \"大夹子\",\n" +
"\t\"id\": \"699169968926801920\",\n" +
"\t\"isRealtime\": false\n" +
"}";
JSONObject c = JSON.parseObject(a);
request.setData(c);
response = messageService.send(request);
response.setCode(response.getError().getString("errorCode"));
} catch (Exception e) {
log.error("发送单条短信异常", e);
response = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
......
......@@ -8,6 +8,8 @@ public interface BgySmsService {
CLBizResponse sendSms(String mobile, String content, String areaId) throws Exception;
CLBizResponse sendbatchSms(String mobile, String areaId) throws Exception;
void asyncNotify(TemplateNotify templateNotify);
}
......@@ -78,6 +78,40 @@ public class BgySmsServiceImpl implements BgySmsService {
}
}
@Override
public CLBizResponse sendbatchSms(String data, String areaId) throws Exception {
log.info("进入碧桂园短信发送接口");
String appId = BgySMSConfig.appId;
// String areaId = BgySMSConfig.areaId;
String securityCode = BgySMSConfig.securityCode;
String url = BgySMSConfig.url;
String api = BgySMSConfig.api;
Map<String, String> requestParams = new HashMap<>();
requestParams.put("api", api);
requestParams.put("appId", appId);
requestParams.put("security", Md5Util.encrypt(appId + securityCode.toUpperCase()));
requestParams.put("areaId", areaId);
requestParams.put("data", data);
log.info("碧桂园短信接口参数:{}", requestParams);
String retStr = SendSmsUtil.sendSmsByPost(url, JSONObject.toJSONString(requestParams));
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("成功")) {
return new CLBizResponse(ResponseCode.SUCCESS);
}
return new CLBizResponse(ResponseCode.UPSTREAM_FAIL.getCode(), err);
} else {
return new CLBizResponse(ResponseCode.SUCCESS);
}
}
/**
* 处理短信模板的通知
*
......
package com.bgy.sms.repository.domain;
import com.baomidou.mybatisplus.annotations.TableName;
import java.util.Date;
@TableName("sms_record")
public class SysRecordInfo {
private Long id;
private Long sysBatchId;
private String mobile;
private String msgId;
private Integer chargeNum;
private String content;
private String params;
private String status;
private String statusDesc;
private Date dateCreated;
private Date lastUpdated;
private String areaId;
public String getAreaId() {
return areaId;
}
public void setAreaId(String areaId) {
this.areaId = areaId;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getSysBatchId() {
return sysBatchId;
}
public void setSysBatchId(Long sysBatchId) {
this.sysBatchId = sysBatchId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getMsgId() {
return msgId;
}
public void setMsgId(String msgId) {
this.msgId = msgId;
}
public Integer getChargeNum() {
return chargeNum;
}
public void setChargeNum(Integer chargeNum) {
this.chargeNum = chargeNum;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getStatusDesc() {
return statusDesc;
}
public void setStatusDesc(String statusDesc) {
this.statusDesc = statusDesc;
}
public Date getDateCreated() {
return dateCreated;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public Date getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
}
package com.bgy.sms.repository.mapper;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.bgy.sms.repository.domain.SysRecordInfo;
public interface SysRecordMapper extends BaseMapper<SysRecordInfo> {
}
package com.bgy.sms.service;
import com.baomidou.mybatisplus.service.IService;
import com.bgy.sms.repository.domain.SysRecordInfo;
public interface SysRecordService extends IService<SysRecordInfo> {
}
......@@ -8,14 +8,8 @@ import com.bgy.sms.channel.bgy.dto.CLBizResponse;
import com.bgy.sms.channel.bgy.service.BgySmsService;
import com.bgy.sms.channel.dto.*;
import com.bgy.sms.config.ResponseCode;
import com.bgy.sms.repository.domain.DmBatchInfo;
import com.bgy.sms.repository.domain.DmCodeInfo;
import com.bgy.sms.repository.domain.SmsTemplateInfo;
import com.bgy.sms.repository.domain.SysBatchInfo;
import com.bgy.sms.service.DmBatchService;
import com.bgy.sms.service.DmCodeService;
import com.bgy.sms.service.MessageService;
import com.bgy.sms.service.SmsTemplateService;
import com.bgy.sms.repository.domain.*;
import com.bgy.sms.service.*;
import com.bgy.sms.service.bean.TemplateChangeBean;
import com.bgy.util.HttpUtil;
import com.bgy.util.Md5Util;
......@@ -49,6 +43,9 @@ public class MessageServiceImpl implements MessageService {
@Autowired
private DmCodeService dmCodeService;
@Autowired
private SysRecordService sysRecordService;
/**
* 短信模板创建
*
......@@ -96,11 +93,12 @@ public class MessageServiceImpl implements MessageService {
if (!insert) {
log.error("模板插入DB异常:【{}】", JSONObject.toJSONString(info));
return new DmHubResponse(ResponseCode.SYSTEM_ERROR);
}else {
} else {
String appId = BgySMSConfig.appId;
String securityCode = BgySMSConfig.securityCode;
String pkID = info.getId()+"";
String pkID = info.getId() + "";
String content = info.getContent();
String TEMPLATETYPE = "52";
JSONObject param = new JSONObject();
param.put("api", "AddTemplate");
param.put("appid", appId);
......@@ -109,7 +107,7 @@ public class MessageServiceImpl implements MessageService {
param.put("areaid", "FHY");
param.put("pkID", pkID);
param.put("account", "SZH003");
param.put("templateType", "");
param.put("templateType", TEMPLATETYPE);
String retStr = HttpUtil.sendPost(BgySMSConfig.url, JSONObject.toJSONString(param));
JSONObject retJson = JSONObject.parseObject(retStr);
......@@ -122,16 +120,21 @@ public class MessageServiceImpl implements MessageService {
JSONObject Json = JSONObject.parseObject(reePackage);
String data = Json.getString("data");
info.setTemplateRecordId(data);
info.setStatus("normal");
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;
} else {
responseDTO.setCode(ResponseCode.SYSTEM_ERROR.getCode());
responseDTO.setError(retJson);
return responseDTO;
}
responseDTO.setCode(ResponseCode.SUCCESS.getCode());
responseDTO.setError(JSONObject.parseObject(JSONObject.toJSONString(info)));
return responseDTO;
}
} catch (Exception exception) {
log.error("创建模板业务逻辑异常,错误信息", exception);
......@@ -169,7 +172,7 @@ public class MessageServiceImpl implements MessageService {
g = Matcher.quoteReplacement(g);
g = escapeRegex(g);
// upSendStr = upSendStr.replaceAll(g, "\\{\\$var\\}");
upSendStr = upSendStr.replaceAll(g, "\\{\\$\\$\\}");
upSendStr = upSendStr.replaceAll(g, "\\$\\$");
if (t.contains("${surl!")) {
// 短链没传长度,固定长度20
upCreateStr = upCreateStr.replaceAll(g, "\\{s20\\}");
......@@ -221,6 +224,7 @@ public class MessageServiceImpl implements MessageService {
public DmHubResponse send(DmHubSendRequest request) {
try {
String dmHubBatchId = request.getBatchId();
String channelAccount = request.getChannelAccount();
String templateId = request.getTemplateId();
String audienceIdType = request.getAudienceIdType();
JSONObject data = request.getData();
......@@ -293,10 +297,34 @@ public class MessageServiceImpl implements MessageService {
content = getMsg(upContent, paramList);
}
response = bgySmsService.sendSms(mobile, content, areaId);
//4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo();
sysRecordInfo.setId(IdHandler.nextId());
long sysRecordInfoBatchId = IdHandler.nextId();
sysRecordInfo.setSysBatchId(sysRecordInfoBatchId);
sysRecordInfo.setMobile(mobile);
//sysRecordInfo.setMsgId();
sysRecordInfo.setChargeNum(1);
sysRecordInfo.setContent(content);
//sysRecordInfo.setParams();
Date date = new Date();
sysRecordInfo.setDateCreated(date);
sysRecordInfo.setLastUpdated(date);
sysRecordInfo.setAreaId(channelAccount);
String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(ResponseCode.SUCCESS);
} else {
sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
boolean a = sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(code, response.getMsg());
}
......@@ -354,7 +382,7 @@ public class MessageServiceImpl implements MessageService {
String batchId = request.getBatchId(); // DM hub 批次号
String templateId = request.getTemplateId(); // 此次短信对应的模板id
List<JSONObject> data = request.getData();
String channelAccount = request.getChannelAccount();
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) {
return new DmHubResponse("999", "短信插件未获取到模板信息");
......@@ -401,7 +429,6 @@ public class MessageServiceImpl implements MessageService {
}
paramsMap.put(mobile, list);
}
} else {
if (i != data.size()) {
paramsMap.put(mobile, new ArrayList<>());
......@@ -409,7 +436,6 @@ public class MessageServiceImpl implements MessageService {
}
}
DmBatchInfo dmInfo = new DmBatchInfo();
dmInfo.setDmBatchId(batchId);
dmInfo.setDmTemplateId(templateId);
......@@ -431,43 +457,111 @@ public class MessageServiceImpl implements MessageService {
sysBatchService.insert(info);
CLBizResponse response = new CLBizResponse();
//4.短信发送记录
SysRecordInfo sysRecordInfo = new SysRecordInfo();
sysRecordInfo.setId(IdHandler.nextId());
long sysRecordInfoBatchId = IdHandler.nextId();
sysRecordInfo.setSysBatchId(sysRecordInfoBatchId);
//sysRecordInfo.setMsgId();
//sysRecordInfo.setParams();
Date date = new Date();
sysRecordInfo.setDateCreated(date);
sysRecordInfo.setLastUpdated(date);
sysRecordInfo.setAreaId(channelAccount);
if (paramsArr == null || paramsArr.isEmpty()) {
try {
List<JSONObject> list = new ArrayList<>();
StringBuilder mobiles = new StringBuilder();
String content = templateInfo.getUpContent();
for (String mobile : mobileList) {
JSONObject jsonObject = new JSONObject();
mobiles.append("," + mobile);
jsonObject.put("mobile", mobile);
jsonObject.put("content", content);
list.add(jsonObject);
}
try {
response = bgySmsService.sendSms(mobile, templateInfo.getUpContent(), areaId);
} catch (Exception e) {
log.error("短信发送异常", e);
if (!list.isEmpty()) {
response = bgySmsService.sendbatchSms(list.toString(), areaId);
String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.toString());
sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
} else {
sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.toString());
sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
boolean a = sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(code, response.getMsg());
}
}
} catch (Exception e) {
log.error("调用碧桂园逻辑错误", e);
return new DmHubResponse("999", "插件服务系统异常");
}
} else {
// 变量短信
Set<Map.Entry<String, List<String>>> entries = paramsMap.entrySet();
try {
List<JSONObject> list = new ArrayList<>();
StringBuilder mobiles = new StringBuilder();
String content = templateInfo.getUpContent();
for (Map.Entry<String, List<String>> entry : entries) {
try {
String mobile = entry.getKey().toString();
List<String> paramsList = entry.getValue();
String sendMsg = getMsg(templateInfo.getUpContent(), paramsList);
response = bgySmsService.sendSms(mobile, sendMsg, areaId);
String code = response.getCode();
String msg = response.getMsg();
} catch (Exception e) {
log.error("chu0");
JSONObject jsonObject = new JSONObject();
mobiles.append("," + mobile);
jsonObject.put("mobile", mobile);
jsonObject.put("content", sendMsg);
list.add(jsonObject);
}
try {
response = bgySmsService.sendbatchSms(list.toString(), areaId);
String code = response.getCode();
if (code.equals(ResponseCode.SUCCESS.getCode())) {
sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.toString());
sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.SUCCESS.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg());
} else {
sysRecordInfo.setChargeNum(list.size());
sysRecordInfo.setMobile(mobiles.toString());
sysRecordInfo.setContent(content);
sysRecordInfo.setStatus(ResponseCode.UPSTREAM_FAIL.getCode());
sysRecordInfo.setStatusDesc(response.getMsg());
boolean a = sysRecordService.insert(sysRecordInfo);
return new DmHubResponse(code, response.getMsg());
}
return new DmHubResponse(ResponseCode.SUCCESS);
} catch (Exception e) {
log.error("调用碧桂园逻辑错误:", e);
return new DmHubResponse("999", "插件服务系统异常");
}
}
return new DmHubResponse(ResponseCode.SUCCESS);
return new DmHubResponse("999", "插件服务系统异常");
}
private static void getKeyAndValue(JSONObject json, List<String> keyList, StringBuffer keyBuffer, Map<String, String> paramsMap) {
......
package com.bgy.sms.service.impl;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bgy.sms.repository.domain.SysRecordInfo;
import com.bgy.sms.repository.mapper.SysRecordMapper;
import com.bgy.sms.service.SysRecordService;
import org.springframework.stereotype.Service;
@Service
public class SysRecordServiceImpl extends ServiceImpl<SysRecordMapper, SysRecordInfo> implements SysRecordService {
}
......@@ -34,7 +34,7 @@ system:
securityCode: 930844c7-7985-435b-af47-142b59b299c3 # 鉴权码
url: https://xstest.bgy.com.cn/ApiBgyTest/Open/Sms.ashx
areaId: XXJSB
api: SendSms
api: SendSmS
dmHub:
applicationId: cl0300171a6012c21
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
......
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