Commit 6cd1184e authored by qinxunjia's avatar qinxunjia

dmhub发送短信验证码的接口

parent 494b7825
...@@ -25,17 +25,36 @@ public class DmHubApi { ...@@ -25,17 +25,36 @@ public class DmHubApi {
* @return * @return
*/ */
@PostMapping("/sms/template") @PostMapping("/sms/template")
public DmHubTemplateResponse template(@RequestBody DmHubTemplateRequest params) { public DmHubResponse template(@RequestBody DmHubTemplateRequest params) {
log.info("**********创建模板接口入参*******:{}", JSONObject.toJSONString(params)); log.info("**********创建模板接口入参*******:{}", JSONObject.toJSONString(params));
DmHubTemplateResponse template; DmHubResponse response;
try { try {
template = messageService.createTemplate(params); response = messageService.createTemplate(params);
} catch (Exception e) { } catch (Exception e) {
log.error("创建模板短信异常", e); log.error("创建模板短信异常", e);
template = new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR); response = new DmHubResponse("999", "创建模板短信异常");
} }
log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(template)); log.info("**********创建模板接口出参*******:{}", JSONObject.toJSONString(response));
return template; return response;
}
/**
* 发送短信验证码
*
* @return
*/
@PostMapping("/sms/verifyCode")
public DmHubResponse verifyCode(@RequestBody DmHubCodeRequest params) {
log.info("**********发送短信验证码*******:{}", JSONObject.toJSONString(params));
DmHubResponse response;
try {
response = messageService.sendCode(params);
} catch (Exception e) {
log.error("发送验证码短信异常", e);
response = new DmHubResponse("999", "发送验证码短信异常");
}
log.info("**********发送短信验证码出参*******:{}", JSONObject.toJSONString(response));
return response;
} }
...@@ -45,14 +64,14 @@ public class DmHubApi { ...@@ -45,14 +64,14 @@ public class DmHubApi {
* @return * @return
*/ */
@PostMapping("/sms/batch") @PostMapping("/sms/batch")
public DmHubSendResponse batch(@RequestBody DmHubBatchSendRequest request) { public DmHubResponse batch(@RequestBody DmHubBatchSendRequest request) {
log.info("**********批量发送入参*******:{}", JSONObject.toJSONString(request)); log.info("**********批量发送入参*******:{}", JSONObject.toJSONString(request));
DmHubSendResponse response; DmHubResponse response;
try { try {
response = messageService.batchSendOneByOne(request); response = messageService.batchSendOneByOne(request);
} catch (Exception e) { } catch (Exception e) {
log.error("发送批量短信异常", e); log.error("发送批量短信异常", e);
response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); response = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
log.info("**********批量发送出参*******:{}", response); log.info("**********批量发送出参*******:{}", response);
return response; return response;
...@@ -64,14 +83,14 @@ public class DmHubApi { ...@@ -64,14 +83,14 @@ public class DmHubApi {
* @return * @return
*/ */
@RequestMapping("/sms/send") @RequestMapping("/sms/send")
public DmHubSendResponse send(@RequestBody DmHubSendRequest request) { public DmHubResponse send(@RequestBody DmHubSendRequest request) {
log.info("**********单条发送入参*******:{}", JSONObject.toJSONString(request)); log.info("**********单条发送入参*******:{}", JSONObject.toJSONString(request));
DmHubSendResponse response; DmHubResponse response;
try { try {
response = messageService.send(request); response = messageService.send(request);
} catch (Exception e) { } catch (Exception e) {
log.error("发送单条短信异常", e); log.error("发送单条短信异常", e);
response = new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); response = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
log.info("**********单条发送出参*******:{}", JSONObject.toJSONString(response)); log.info("**********单条发送出参*******:{}", JSONObject.toJSONString(response));
return response; return response;
......
package com.bgy.sms.channel.dto; package com.bgy.sms.channel.dto;
import com.bgy.sms.config.ResponseCode;
import java.io.Serializable; import java.io.Serializable;
public class DmHubTemplateResponse implements Serializable { public class DmHubCodeRequest implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String mobile;
private String code; private String code;
public DmHubTemplateResponse() { public String getMobile() {
} return mobile;
public DmHubTemplateResponse(String code, String msg) {
this.code = code;
} }
public DmHubTemplateResponse(ResponseCode responseCode) { public void setMobile(String mobile) {
this.code = responseCode.getCode(); this.mobile = mobile;
} }
public String getCode() { public String getCode() {
......
...@@ -5,7 +5,7 @@ import com.bgy.sms.config.ResponseCode; ...@@ -5,7 +5,7 @@ import com.bgy.sms.config.ResponseCode;
import java.io.Serializable; import java.io.Serializable;
public class DmHubSendResponse implements Serializable { public class DmHubResponse implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -13,18 +13,18 @@ public class DmHubSendResponse implements Serializable { ...@@ -13,18 +13,18 @@ public class DmHubSendResponse implements Serializable {
private JSONObject error; private JSONObject error;
public DmHubSendResponse() { public DmHubResponse() {
} }
public DmHubSendResponse(ResponseCode responseCode) { public DmHubResponse(String code, String msg) {
this.code = responseCode.getCode(); error = new JSONObject();
error.put("errorCode", code);
error.put("message", msg);
this.code = code;
} }
public DmHubSendResponse(String errorCode, String errorMsg) { public DmHubResponse(ResponseCode responseCode) {
error = new JSONObject(); this.code = responseCode.getCode();
error.put("errorCode", errorCode);
error.put("message", errorMsg);
} }
public String getCode() { public String getCode() {
...@@ -42,12 +42,4 @@ public class DmHubSendResponse implements Serializable { ...@@ -42,12 +42,4 @@ public class DmHubSendResponse implements Serializable {
public void setError(JSONObject error) { public void setError(JSONObject error) {
this.error = error; this.error = error;
} }
@Override
public String toString() {
return "DmHubSendResponse{" +
"code='" + code + '\'' +
"error='" + error.toString() + '\'' +
'}';
}
} }
...@@ -10,7 +10,7 @@ public interface MessageService { ...@@ -10,7 +10,7 @@ public interface MessageService {
* @param requestDTO * @param requestDTO
* @return * @return
*/ */
DmHubTemplateResponse createTemplate(DmHubTemplateRequest requestDTO); DmHubResponse createTemplate(DmHubTemplateRequest requestDTO);
/** /**
* DM hub发送短信接口 * DM hub发送短信接口
...@@ -18,7 +18,7 @@ public interface MessageService { ...@@ -18,7 +18,7 @@ public interface MessageService {
* @param requestDTO * @param requestDTO
* @return * @return
*/ */
DmHubSendResponse send(DmHubSendRequest requestDTO); DmHubResponse send(DmHubSendRequest requestDTO);
/** /**
* DM hub批量发送短信接口 * DM hub批量发送短信接口
...@@ -26,7 +26,7 @@ public interface MessageService { ...@@ -26,7 +26,7 @@ public interface MessageService {
* @param requestDTO * @param requestDTO
* @return * @return
*/ */
DmHubSendResponse batchSend(DmHubBatchSendRequest requestDTO); DmHubResponse batchSend(DmHubBatchSendRequest requestDTO);
/** /**
* DM hub批量发送短信接口 * DM hub批量发送短信接口
...@@ -34,5 +34,7 @@ public interface MessageService { ...@@ -34,5 +34,7 @@ public interface MessageService {
* @param requestDTO * @param requestDTO
* @return * @return
*/ */
DmHubSendResponse batchSendOneByOne(DmHubBatchSendRequest requestDTO); DmHubResponse batchSendOneByOne(DmHubBatchSendRequest requestDTO);
DmHubResponse sendCode(DmHubCodeRequest params);
} }
...@@ -16,6 +16,7 @@ import com.bgy.sms.service.MessageService; ...@@ -16,6 +16,7 @@ import com.bgy.sms.service.MessageService;
import com.bgy.sms.service.SmsTemplateService; import com.bgy.sms.service.SmsTemplateService;
import com.bgy.sms.service.bean.TemplateChangeBean; import com.bgy.sms.service.bean.TemplateChangeBean;
import com.bgy.util.id.IdHandler; import com.bgy.util.id.IdHandler;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -50,10 +51,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -50,10 +51,10 @@ public class MessageServiceImpl implements MessageService {
* @return * @return
*/ */
@Override @Override
public DmHubTemplateResponse createTemplate(DmHubTemplateRequest requestDTO) { public DmHubResponse createTemplate(DmHubTemplateRequest requestDTO) {
log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO); log.info("进入创建短信模板业务逻辑,入参:{}", requestDTO);
DmHubTemplateResponse responseDTO = new DmHubTemplateResponse(ResponseCode.SUCCESS); DmHubResponse responseDTO = new DmHubResponse(ResponseCode.SUCCESS);
try { try {
String templateContent = requestDTO.getTemplateContent(); String templateContent = requestDTO.getTemplateContent();
String signature = requestDTO.getSignature(); String signature = requestDTO.getSignature();
...@@ -69,7 +70,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -69,7 +70,7 @@ public class MessageServiceImpl implements MessageService {
SmsTemplateInfo dbInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId)); SmsTemplateInfo dbInfo = smsTemplateService.selectOne(new EntityWrapper<SmsTemplateInfo>().eq("dm_template_id", templateId));
if (dbInfo != null) { if (dbInfo != null) {
log.error("Dm Hub请求创建模板,模板id已存在,模板id:【{}】", templateId); log.error("Dm Hub请求创建模板,模板id已存在,模板id:【{}】", templateId);
return new DmHubTemplateResponse(ResponseCode.TEMPLATE_ALREADY_EXISTED); return new DmHubResponse(ResponseCode.TEMPLATE_ALREADY_EXISTED);
} }
SmsTemplateInfo info = new SmsTemplateInfo(); SmsTemplateInfo info = new SmsTemplateInfo();
info.setContent(templateContent); info.setContent(templateContent);
...@@ -88,11 +89,11 @@ public class MessageServiceImpl implements MessageService { ...@@ -88,11 +89,11 @@ public class MessageServiceImpl implements MessageService {
if (!insert) { if (!insert) {
//TODO 发送告警 //TODO 发送告警
log.error("模板插入DB异常:【{}】", JSONObject.toJSONString(info)); log.error("模板插入DB异常:【{}】", JSONObject.toJSONString(info));
return new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR); return new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
} catch (Exception exception) { } catch (Exception exception) {
log.error("创建模板业务逻辑异常,错误信息", exception); log.error("创建模板业务逻辑异常,错误信息", exception);
responseDTO = new DmHubTemplateResponse(ResponseCode.SYSTEM_ERROR); responseDTO = new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
return responseDTO; return responseDTO;
...@@ -176,7 +177,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -176,7 +177,7 @@ 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 request) { public DmHubResponse send(DmHubSendRequest request) {
try { try {
String dmHubBatchId = request.getBatchId(); String dmHubBatchId = request.getBatchId();
String templateId = request.getTemplateId(); String templateId = request.getTemplateId();
...@@ -186,7 +187,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -186,7 +187,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) {
log.error("未获取到短信模板"); log.error("未获取到短信模板");
return new DmHubSendResponse("999", "未获取到短信模板"); return new DmHubResponse("999", "未获取到短信模板");
} }
// 2、根据请求信息获取用户的手机号码(此处不考虑配置DMHUB系统不是SMS的情况),直接拿请求体中的_audienceId字段值,该值为手机号码 // 2、根据请求信息获取用户的手机号码(此处不考虑配置DMHUB系统不是SMS的情况),直接拿请求体中的_audienceId字段值,该值为手机号码
// 模板参数占位符 // 模板参数占位符
...@@ -199,7 +200,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -199,7 +200,7 @@ public class MessageServiceImpl implements MessageService {
} else if ("marketing".equals(smsType)) { } else if ("marketing".equals(smsType)) {
areaId = BgySMSConfig.marketAreaId; areaId = BgySMSConfig.marketAreaId;
} else { } else {
return new DmHubSendResponse("999", "未获取到短信类型"); return new DmHubResponse("999", "未获取到短信类型");
} }
// 封装参数 // 封装参数
List<String> paramList = new ArrayList<>(); List<String> paramList = new ArrayList<>();
...@@ -255,13 +256,29 @@ public class MessageServiceImpl implements MessageService { ...@@ -255,13 +256,29 @@ public class MessageServiceImpl implements MessageService {
String code = response.getCode(); String code = response.getCode();
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
return new DmHubSendResponse(code, msg); return new DmHubResponse(ResponseCode.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
log.error("调用短信发送逻辑错误", e); log.error("调用短信发送逻辑错误", e);
return new DmHubSendResponse("999", "插件系统异常"); return new DmHubResponse("999", "插件系统异常");
} }
} }
@Override
public DmHubResponse sendCode(DmHubCodeRequest params) {
String notifyAreaId = BgySMSConfig.notifyAreaId;
String mobile = params.getMobile();
String code = params.getCode();
CLBizResponse response = new CLBizResponse();
String content = "您的验证码是:" + code;
try {
bgySmsService.sendSms(mobile, content, notifyAreaId);
} catch (Exception e) {
log.error("发送短信异常:", e);
}
return new DmHubResponse(ResponseCode.SUCCESS);
}
/** /**
* 获取可以直接用户发送的短信内容 * 获取可以直接用户发送的短信内容
* *
...@@ -277,7 +294,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -277,7 +294,7 @@ public class MessageServiceImpl implements MessageService {
} }
@Override @Override
public DmHubSendResponse batchSend(DmHubBatchSendRequest request) { public DmHubResponse batchSend(DmHubBatchSendRequest request) {
String batchId = request.getBatchId(); // DM hub 批次号 String batchId = request.getBatchId(); // DM hub 批次号
String templateId = request.getTemplateId(); // 此次短信对应的模板id String templateId = request.getTemplateId(); // 此次短信对应的模板id
String audienceIdType = request.getAudienceIdType(); String audienceIdType = request.getAudienceIdType();
...@@ -285,7 +302,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -285,7 +302,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 DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
// 模板参数占位符 // 模板参数占位符
String params = templateInfo.getParams(); String params = templateInfo.getParams();
...@@ -359,14 +376,14 @@ public class MessageServiceImpl implements MessageService { ...@@ -359,14 +376,14 @@ public class MessageServiceImpl implements MessageService {
String msg = response.getMsg(); String msg = response.getMsg();
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
if (ResponseCode.SUCCESS.getCode().equals(code)) { if (ResponseCode.SUCCESS.getCode().equals(code)) {
return new DmHubSendResponse(code, msg); return new DmHubResponse(ResponseCode.SUCCESS);
} else { } else {
return new DmHubSendResponse(code, msg); return new DmHubResponse(code, msg);
} }
} 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 DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
} else { } else {
// 固定短信 // 固定短信
...@@ -382,16 +399,16 @@ public class MessageServiceImpl implements MessageService { ...@@ -382,16 +399,16 @@ public class MessageServiceImpl implements MessageService {
// String msg = response.getMsg(); // String msg = response.getMsg();
// } // }
// TODO 待优化 // TODO 待优化
return new DmHubSendResponse(ResponseCode.SUCCESS); return new DmHubResponse(ResponseCode.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:", e); log.error("调用创蓝逻辑错误:", e);
return new DmHubSendResponse(ResponseCode.SYSTEM_ERROR); return new DmHubResponse(ResponseCode.SYSTEM_ERROR);
} }
} }
} }
@Override @Override
public DmHubSendResponse batchSendOneByOne(DmHubBatchSendRequest request) { public DmHubResponse batchSendOneByOne(DmHubBatchSendRequest request) {
String batchId = request.getBatchId(); // DM hub 批次号 String batchId = request.getBatchId(); // DM hub 批次号
String templateId = request.getTemplateId(); // 此次短信对应的模板id String templateId = request.getTemplateId(); // 此次短信对应的模板id
String audienceIdType = request.getAudienceIdType(); String audienceIdType = request.getAudienceIdType();
...@@ -399,7 +416,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -399,7 +416,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("999", "短信插件未获取到模板信息"); return new DmHubResponse("999", "短信插件未获取到模板信息");
} }
String smsType = templateInfo.getType(); String smsType = templateInfo.getType();
String areaId; String areaId;
...@@ -408,7 +425,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -408,7 +425,7 @@ public class MessageServiceImpl implements MessageService {
} else if ("marketing".equals(smsType)) { } else if ("marketing".equals(smsType)) {
areaId = BgySMSConfig.marketAreaId; areaId = BgySMSConfig.marketAreaId;
} else { } else {
return new DmHubSendResponse("999", "未获取到短信类型"); return new DmHubResponse("999", "未获取到短信类型");
} }
// 模板参数占位符 // 模板参数占位符
String params = templateInfo.getParams(); String params = templateInfo.getParams();
...@@ -487,7 +504,7 @@ public class MessageServiceImpl implements MessageService { ...@@ -487,7 +504,7 @@ public class MessageServiceImpl implements MessageService {
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误", e); log.error("调用创蓝逻辑错误", e);
// TODO 根据DM hub需要的返回数据封装 // TODO 根据DM hub需要的返回数据封装
return new DmHubSendResponse("999", "插件服务系统异常"); return new DmHubResponse("999", "插件服务系统异常");
} }
} else { } else {
// 变量短信 // 变量短信
...@@ -507,13 +524,13 @@ public class MessageServiceImpl implements MessageService { ...@@ -507,13 +524,13 @@ public class MessageServiceImpl implements MessageService {
} }
// TODO 待优化 // TODO 待优化
return new DmHubSendResponse(ResponseCode.SUCCESS); return new DmHubResponse(ResponseCode.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
log.error("调用创蓝逻辑错误:", e); log.error("调用创蓝逻辑错误:", e);
return new DmHubSendResponse("999", "插件服务系统异常"); return new DmHubResponse("999", "插件服务系统异常");
} }
} }
return new DmHubSendResponse(ResponseCode.SUCCESS); return new DmHubResponse(ResponseCode.SUCCESS);
} }
private String getKeyValue(Object value, StringBuilder keyBuffer) { private String getKeyValue(Object value, StringBuilder keyBuffer) {
......
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