Commit c9d1d951 authored by qinxunjia's avatar qinxunjia

短信

parent e3aa6c8a
package com.bgy.sms.channel.dto;
import com.alibaba.fastjson.JSONObject;
import com.bgy.sms.config.ResponseCode;
import java.io.Serializable;
......@@ -10,18 +11,22 @@ public class DmHubSendResponse implements Serializable {
private String code;
private JSONObject error;
public DmHubSendResponse() {
}
public DmHubSendResponse(String code, String msg) {
this.code = code;
}
public DmHubSendResponse(ResponseCode responseCode) {
this.code = responseCode.getCode();
}
public DmHubSendResponse(String errorCode, String errorMsg) {
error = new JSONObject();
error.put("errorCode", errorCode);
error.put("message", errorMsg);
}
public String getCode() {
return code;
}
......@@ -30,11 +35,19 @@ public class DmHubSendResponse implements Serializable {
this.code = code;
}
public JSONObject getError() {
return error;
}
public void setError(JSONObject error) {
this.error = error;
}
@Override
public String toString() {
return "DmHubSendResponse{" +
"code='" + code + '\'' +
"error='" + error.toString() + '\'' +
'}';
}
}
......@@ -6,6 +6,8 @@ public enum ResponseCode {
UNKNOWN_TEMPLATE_TYPE("500", "未知模板类型"),
TEMPLATE_ALREADY_EXISTED("500", "DM Hub模板ID冲突"),
SYSTEM_ERROR("99", "系统异常:"),
NO_TEMPLATE("error", "未找到短信模板"),
DMHUB_NO_DATA("error", "没有请求数据"),
// 渠道异常错误
UPSTREAM_FAIL("US01", "渠道交易失败"),
......
......@@ -175,16 +175,17 @@ public class MessageServiceImpl implements MessageService {
@Override
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
public DmHubSendResponse send(DmHubSendRequest requestDTO) {
public DmHubSendResponse send(DmHubSendRequest request) {
try {
String dmHubBatchId = requestDTO.getBatchId();
String templateId = requestDTO.getTemplateId();
String audienceIdType = requestDTO.getAudienceIdType();
JSONObject data = requestDTO.getData();
String dmHubBatchId = request.getBatchId();
String templateId = request.getTemplateId();
String audienceIdType = request.getAudienceIdType();
JSONObject data = request.getData();
// 1、获取模板信息
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) {
return null;
log.error("未获取到短信模板");
return new DmHubSendResponse("999", "未获取到短信模板");
}
// 2、根据请求信息获取用户的手机号码(此处不考虑配置DMHUB系统不是SMS的情况),直接拿请求体中的_audienceId字段值,该值为手机号码
// 模板参数占位符
......@@ -199,6 +200,7 @@ public class MessageServiceImpl implements MessageService {
data.remove("id");
data.remove("_audienceId");
log.info("data信息:{}", data);
if (!data.isEmpty()) {
for (Object parm : paramsArr) {
String s = parm.toString();
......@@ -215,8 +217,6 @@ public class MessageServiceImpl implements MessageService {
}
}
}
} else {
return null;
}
String type = templateInfo.getType();
// 3、记录批次信息
......@@ -249,7 +249,7 @@ public class MessageServiceImpl implements MessageService {
return new DmHubSendResponse(code, msg);
} catch (Exception e) {
log.error("调用短信发送逻辑错误", e);
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
return new DmHubSendResponse("999", "插件系统异常");
}
}
......@@ -390,7 +390,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo templateInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (null == templateInfo) {
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
return new DmHubSendResponse("999", "短信插件未获取到模板信息");
}
// 模板参数占位符
String params = templateInfo.getParams();
......@@ -407,7 +407,7 @@ public class MessageServiceImpl implements MessageService {
json.remove("name");
json.remove("id");
json.remove("_audienceId");
mobileList.add(mobile);
if (!json.isEmpty()) {
for (Object parm : paramsArr) {
List<String> list = new ArrayList<>();
......@@ -459,24 +459,33 @@ public class MessageServiceImpl implements MessageService {
if (paramsArr == null || paramsArr.isEmpty()) {
try {
for (String mobile : mobileList) {
response = bgySmsService.sendSms("", templateInfo.getUpContent());
try {
response = bgySmsService.sendSms(mobile, templateInfo.getUpContent());
} catch (Exception e) {
log.error("除0");
}
}
} catch (Exception e) {
log.error("调用创蓝逻辑错误", e);
// TODO 根据DM hub需要的返回数据封装
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR);
return new DmHubSendResponse("999", "插件服务系统异常");
}
} else {
// 变量短信
Set<Map.Entry<String, List<String>>> entries = paramsMap.entrySet();
try {
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);
String code = response.getCode();
String msg = response.getMsg();
} catch (Exception e) {
log.error("chu0");
}
}
// TODO 待优化
return new DmHubSendResponse(ResponseCode.SUCCESS);
......
......@@ -12,8 +12,8 @@ spring:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://119.23.32.151:3306/dmhub_plugin?characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.cj.jdbc.Driver
username: bu00310
password: pwd$BU00310
username: dmp
password: Ioubuy@2019@!
hikari:
maxLifetime: 1765000
maximumPoolSize: 20
......
......@@ -10,7 +10,6 @@ server:
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
# url: jdbc:mysql://119.23.32.151:3306/dmhub_plugin?characterEncoding=utf8&useSSL=false
url: jdbc:mysql://my09457h.mysql.db.pcloud.localdomain:3070/dmhub_plugin?characterEncoding=utf8&useSSL=false
driver-class-name: com.mysql.cj.jdbc.Driver
username: bu00310
......@@ -41,4 +40,3 @@ system:
applicationKey: 4017078e9dfd593b2d9a0ede58eff589644fbe50
tokenUrl: https://api.convertlab.com/security/accesstoken
report: https://api.convertlab.com/v1/sms/report
......@@ -19,7 +19,7 @@ mybatis-plus:
logging:
level: debug
level.com.jz: debug # 单独指定包下的日志级别
level.com.bgy: debug # 单独指定包下的日志级别
config: classpath:logback-spring.xml
file:
path: logs.log
\ No newline at end of file
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