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() + '\'' +
'}';
}
}
......@@ -2,7 +2,7 @@ package com.bgy.sms.service;
import com.bgy.sms.channel.dto.*;
public interface MessageService {
public interface MessageService {
/**
* DM hub创建模板同步插件接口
......@@ -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);
}
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