完成云片的发送回执处理
This commit is contained in:
parent
8ab29d2a25
commit
86cbf21d6d
@ -17,11 +17,11 @@ public class SmsReceiveRespDTO {
|
|||||||
*/
|
*/
|
||||||
private Boolean success;
|
private Boolean success;
|
||||||
/**
|
/**
|
||||||
* API 接收结果编码
|
* API 接收结果的编码
|
||||||
*/
|
*/
|
||||||
private String errorCode;
|
private String errorCode;
|
||||||
/**
|
/**
|
||||||
* API 接收结果说明
|
* API 接收结果的说明
|
||||||
*/
|
*/
|
||||||
private String errorMsg;
|
private String errorMsg;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.controller.sms;
|
package cn.iocoder.dashboard.modules.system.controller.sms;
|
||||||
|
|
||||||
import cn.hutool.core.util.URLUtil;
|
import cn.hutool.core.util.URLUtil;
|
||||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.enums.SmsChannelEnum;
|
import cn.iocoder.dashboard.framework.sms.core.enums.SmsChannelEnum;
|
||||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService;
|
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -25,10 +25,11 @@ public class SmsCallbackController {
|
|||||||
@PostMapping("/sms/yunpian")
|
@PostMapping("/sms/yunpian")
|
||||||
@ApiOperation(value = "云片短信的回调", notes = "参见 https://www.yunpian.com/official/document/sms/zh_cn/domestic_push_report 文档")
|
@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)
|
@ApiImplicitParam(name = "sms_status", value = "发送状态", required = true, example = "[{具体内容}]", dataTypeClass = Long.class)
|
||||||
public CommonResult<Boolean> receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable {
|
@OperateLog(enable = false)
|
||||||
|
public String receiveYunpianSmsStatus(@RequestParam("sms_status") String smsStatus) throws Throwable {
|
||||||
String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode
|
String text = URLUtil.decode(smsStatus); // decode 解码参数,因为它被 encode
|
||||||
smsService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text);
|
smsService.receiveSmsStatus(SmsChannelEnum.YUN_PIAN.getCode(), text);
|
||||||
return CommonResult.success(true);
|
return "SUCCESS"; // 约定返回 SUCCESS 为成功
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package cn.iocoder.dashboard.modules.system.dal.dataobject.sms;
|
|||||||
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
import cn.iocoder.dashboard.common.enums.UserTypeEnum;
|
||||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||||
import cn.iocoder.dashboard.framework.sms.core.enums.SmsFrameworkErrorCodeConstants;
|
import cn.iocoder.dashboard.framework.sms.core.enums.SmsFrameworkErrorCodeConstants;
|
||||||
|
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsReceiveStatusEnum;
|
||||||
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum;
|
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
@ -150,9 +151,23 @@ public class SysSmsLogDO extends BaseDO {
|
|||||||
|
|
||||||
// ========= 接收相关字段 =========
|
// ========= 接收相关字段 =========
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * 是否获取过结果[0否 1是]
|
* 接收状态
|
||||||
// */
|
*
|
||||||
// private Integer gotResult;
|
* 枚举 {@link SysSmsReceiveStatusEnum}
|
||||||
|
*/
|
||||||
|
private Integer receiveStatus;
|
||||||
|
/**
|
||||||
|
* 接收时间
|
||||||
|
*/
|
||||||
|
private Date receiveTime;
|
||||||
|
/**
|
||||||
|
* 短信 API 接收结果的编码
|
||||||
|
*/
|
||||||
|
private String apiReceiveCode;
|
||||||
|
/**
|
||||||
|
* 短信 API 接收结果的提示
|
||||||
|
*/
|
||||||
|
private String apiReceiveMsg;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package cn.iocoder.dashboard.modules.system.enums.sms;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 短信的接收状态枚举
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
* @date 2021/2/1 13:39
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum SysSmsReceiveStatusEnum {
|
||||||
|
|
||||||
|
INIT(0), // 初始化
|
||||||
|
SUCCESS(10), // 接收成功
|
||||||
|
FAILURE(20), // 接收失败
|
||||||
|
;
|
||||||
|
|
||||||
|
private final int status;
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,7 @@ package cn.iocoder.dashboard.modules.system.service.sms;
|
|||||||
|
|
||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,7 +29,7 @@ public interface SysSmsLogService {
|
|||||||
SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams);
|
SysSmsTemplateDO template, String templateContent, Map<String, Object> templateParams);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新发送日志的结果
|
* 更新日志的发送结果
|
||||||
*
|
*
|
||||||
* @param id 日志编号
|
* @param id 日志编号
|
||||||
* @param sendCode 发送结果的编码
|
* @param sendCode 发送结果的编码
|
||||||
@ -41,4 +42,15 @@ public interface SysSmsLogService {
|
|||||||
void updateSmsSendResult(Long id, Integer sendCode, String sendMsg,
|
void updateSmsSendResult(Long id, Integer sendCode, String sendMsg,
|
||||||
String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo);
|
String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新日志的接收结果
|
||||||
|
*
|
||||||
|
* @param id 日志编号
|
||||||
|
* @param success 是否接收成功
|
||||||
|
* @param receiveTime 用户接收时间
|
||||||
|
* @param apiReceiveCode API 接收结果的编码
|
||||||
|
* @param apiReceiveMsg API 接收结果的说明
|
||||||
|
*/
|
||||||
|
void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import cn.iocoder.dashboard.common.pojo.CommonResult;
|
|||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsLogDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsLogDO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO;
|
||||||
import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsLogMapper;
|
import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsLogMapper;
|
||||||
|
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsReceiveStatusEnum;
|
||||||
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum;
|
import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum;
|
||||||
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsLogService;
|
import cn.iocoder.dashboard.modules.system.service.sms.SysSmsLogService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -41,6 +42,8 @@ public class SysSmsLogServiceImpl implements SysSmsLogService {
|
|||||||
logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId());
|
logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId());
|
||||||
// 设置渠道相关字段
|
// 设置渠道相关字段
|
||||||
logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode());
|
logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode());
|
||||||
|
// 设置接收相关字段
|
||||||
|
logBuilder.receiveStatus(SysSmsReceiveStatusEnum.INIT.getStatus());
|
||||||
|
|
||||||
// 插入数据库
|
// 插入数据库
|
||||||
SysSmsLogDO logDO = logBuilder.build();
|
SysSmsLogDO logDO = logBuilder.build();
|
||||||
@ -51,10 +54,19 @@ public class SysSmsLogServiceImpl implements SysSmsLogService {
|
|||||||
@Override
|
@Override
|
||||||
public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg,
|
public void updateSmsSendResult(Long id, Integer sendCode, String sendMsg,
|
||||||
String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) {
|
String apiSendCode, String apiSendMsg, String apiRequestId, String apiSerialNo) {
|
||||||
SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS : SysSmsSendStatusEnum.FAILURE;
|
SysSmsSendStatusEnum sendStatus = CommonResult.isSuccess(sendCode) ? SysSmsSendStatusEnum.SUCCESS
|
||||||
|
: SysSmsSendStatusEnum.FAILURE;
|
||||||
smsLogMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date())
|
smsLogMapper.updateById(SysSmsLogDO.builder().id(id).sendStatus(sendStatus.getStatus()).sendTime(new Date())
|
||||||
.sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg)
|
.sendCode(sendCode).sendMsg(sendMsg).apiSendCode(apiSendCode).apiSendMsg(apiSendMsg)
|
||||||
.apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build());
|
.apiRequestId(apiRequestId).apiSerialNo(apiSerialNo).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSmsReceiveResult(Long id, Boolean success, Date receiveTime, String apiReceiveCode, String apiReceiveMsg) {
|
||||||
|
SysSmsReceiveStatusEnum receiveStatus = Objects.equals(success, true) ? SysSmsReceiveStatusEnum.SUCCESS
|
||||||
|
: SysSmsReceiveStatusEnum.FAILURE;
|
||||||
|
smsLogMapper.updateById(SysSmsLogDO.builder().id(id).receiveStatus(receiveStatus.getStatus()).receiveTime(receiveTime)
|
||||||
|
.apiReceiveCode(apiReceiveCode).apiReceiveMsg(apiReceiveMsg).build());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.dashboard.modules.system.service.sms.impl;
|
package cn.iocoder.dashboard.modules.system.service.sms.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.iocoder.dashboard.common.core.KeyValue;
|
import cn.iocoder.dashboard.common.core.KeyValue;
|
||||||
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
import cn.iocoder.dashboard.common.enums.CommonStatusEnum;
|
||||||
@ -153,6 +154,14 @@ public class SysSmsServiceImpl implements SysSmsService {
|
|||||||
Assert.notNull(smsClient, String.format("短信客户端(%s) 不存在", channelCode));
|
Assert.notNull(smsClient, String.format("短信客户端(%s) 不存在", channelCode));
|
||||||
// 解析内容
|
// 解析内容
|
||||||
List<SmsReceiveRespDTO> receiveResults = smsClient.parseSmsReceiveStatus(text);
|
List<SmsReceiveRespDTO> receiveResults = smsClient.parseSmsReceiveStatus(text);
|
||||||
|
if (CollUtil.isEmpty(receiveResults)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 更新短信日志的接收结果. 因为量一般不打,所以先使用 for 循环更新
|
||||||
|
receiveResults.forEach(result -> {
|
||||||
|
smsLogService.updateSmsReceiveResult(result.getLogId(), result.getSuccess(), result.getReceiveTime(),
|
||||||
|
result.getErrorCode(), result.getErrorCode());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user