Commit 6cd1184e authored by qinxunjia's avatar qinxunjia

dmhub发送短信验证码的接口

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