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