定义短信回调的结果
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.sms;
|
||||
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.framework.sms.core.enums.SmsChannelEnum;
|
||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Api(tags = "短信回调")
|
||||
@RestController
|
||||
@RequestMapping("/system/sms/callback")
|
||||
public class SmsCallbackController {
|
||||
|
||||
@Resource
|
||||
private SysSmsService smsService;
|
||||
|
||||
@PostMapping("/sms/yunpian")
|
||||
@ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档")
|
||||
@ApiImplicitParam(name = "sms_status", value = "发送状态", required = true, example = "[{具体内容}]", dataTypeClass = Long.class)
|
||||
public CommonResult<Boolean> receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable {
|
||||
String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode
|
||||
smsService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text);
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package cn.iocoder.dashboard.modules.system.controller.sms;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
||||
/**
|
||||
* 短信默认回调接口
|
||||
*
|
||||
* @author zzf
|
||||
* @date 2021/3/5 8:59
|
||||
*/
|
||||
@Api(tags = "短信回调api")
|
||||
@RestController
|
||||
@RequestMapping("/sms/callback")
|
||||
public class SmsDefaultCallbackController {
|
||||
|
||||
@Resource
|
||||
private SysSmsService smsService;
|
||||
|
||||
|
||||
@ApiOperation(value = "短信发送回调接口")
|
||||
@PostMapping("/sms-send")
|
||||
public Object sendSmsCallback(ServletRequest request) {
|
||||
return smsService.smsSendCallbackHandle(request);
|
||||
}
|
||||
|
||||
/*
|
||||
@Resource
|
||||
private SmsSendStreamProducer smsSendStreamProducer;
|
||||
|
||||
@ApiOperation("redis stream测试")
|
||||
@GetMapping("/test/redis/stream")
|
||||
public void test() {
|
||||
SmsBody smsBody = new SmsBody();
|
||||
smsBody.setSmsLogId(1L);
|
||||
smsBody.setTemplateCode("sdf");
|
||||
smsBody.setTemplateContent("sdf");
|
||||
smsSendStreamProducer.sendSmsSendMessage(smsBody, "18216466755");
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package cn.iocoder.dashboard.modules.system.service.sms;
|
||||
|
||||
import cn.iocoder.dashboard.modules.system.mq.message.sms.SysSmsSendMessage;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -24,11 +23,12 @@ public interface SysSmsService {
|
||||
void doSendSms(SysSmsSendMessage message);
|
||||
|
||||
/**
|
||||
* 处理短信发送回调函数
|
||||
* 接收短信的接收结果
|
||||
*
|
||||
* @param request 请求
|
||||
* @return 响应数据
|
||||
* @param channelCode 渠道编码
|
||||
* @param text 结果内容
|
||||
* @throws Throwable 处理失败时,抛出异常
|
||||
*/
|
||||
Object smsSendCallbackHandle(ServletRequest request);
|
||||
void receiveSmsStatus(String channelCode, String text) throws Throwable;
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||
import cn.iocoder.dashboard.framework.sms.core.client.SmsClient;
|
||||
import cn.iocoder.dashboard.framework.sms.core.client.SmsClientFactory;
|
||||
import cn.iocoder.dashboard.framework.sms.core.client.SmsCommonResult;
|
||||
import cn.iocoder.dashboard.framework.sms.core.client.dto.SmsReceiveRespDTO;
|
||||
import cn.iocoder.dashboard.framework.sms.core.client.dto.SmsSendRespDTO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO;
|
||||
@@ -21,7 +22,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -139,7 +139,7 @@ public class SysSmsServiceImpl implements SysSmsService {
|
||||
SmsClient smsClient = smsClientFactory.getSmsClient(message.getChannelId());
|
||||
Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", message.getChannelId()));
|
||||
// 发送短信
|
||||
SmsCommonResult<SmsSendRespDTO> sendResult = smsClient.send(message.getLogId(), message.getMobile(),
|
||||
SmsCommonResult<SmsSendRespDTO> sendResult = smsClient.sendSms(message.getLogId(), message.getMobile(),
|
||||
message.getApiTemplateId(), message.getTemplateParams());
|
||||
smsLogService.updateSmsSendResult(message.getLogId(), sendResult.getCode(), sendResult.getMsg(),
|
||||
sendResult.getApiCode(), sendResult.getApiMsg(), sendResult.getApiRequestId(),
|
||||
@@ -147,11 +147,12 @@ public class SysSmsServiceImpl implements SysSmsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object smsSendCallbackHandle(ServletRequest request) {
|
||||
// SmsResultDetail smsResultDetail = smsClientFactory.getSmsResultDetailFromCallbackQuery(request);
|
||||
// logService.updateSendLogByResultDetail(smsResultDetail);
|
||||
// return smsResultDetail.getCallbackResponseBody();
|
||||
return null;
|
||||
public void receiveSmsStatus(String channelCode, String text) throws Throwable {
|
||||
// 获得渠道对应的 SmsClient 客户端
|
||||
SmsClient smsClient = smsClientFactory.getSmsClient(channelCode);
|
||||
Assert.notNull(smsClient, String.format("短信客户端(%s) 不存在", channelCode));
|
||||
// 解析内容
|
||||
SmsCommonResult<SmsReceiveRespDTO> receiveResult = smsClient.parseSmsReceiveStatus(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user