Commit c9d1d951 authored by qinxunjia's avatar qinxunjia

短信

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