Commit 33d094697d545516c0192e0cc358b0e693faaf3d
Committed by
Gitee
!205 短信发送时,新增短信渠道的状态校验
Merge pull request !205 from muyi/login
Showing
2 changed files
with
23 additions
and
6 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java
| @@ -11,6 +11,7 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; | ||
| 11 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; | 11 | import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; |
| 12 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; | 12 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 13 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; | 13 | import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; |
| 14 | +import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; | ||
| 14 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; | 15 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; |
| 15 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 16 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 16 | import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; | 17 | import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; |
| @@ -40,7 +41,8 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -40,7 +41,8 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 40 | private AdminUserService adminUserService; | 41 | private AdminUserService adminUserService; |
| 41 | @Resource | 42 | @Resource |
| 42 | private MemberService memberService; | 43 | private MemberService memberService; |
| 43 | - | 44 | + @Resource |
| 45 | + private SmsChannelService smsChannelService; | ||
| 44 | @Resource | 46 | @Resource |
| 45 | private SmsTemplateService smsTemplateService; | 47 | private SmsTemplateService smsTemplateService; |
| 46 | @Resource | 48 | @Resource |
| @@ -80,13 +82,18 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -80,13 +82,18 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 80 | String templateCode, Map<String, Object> templateParams) { | 82 | String templateCode, Map<String, Object> templateParams) { |
| 81 | // 校验短信模板是否合法 | 83 | // 校验短信模板是否合法 |
| 82 | SmsTemplateDO template = this.checkSmsTemplateValid(templateCode); | 84 | SmsTemplateDO template = this.checkSmsTemplateValid(templateCode); |
| 85 | + // 校验短信渠道是否合法 | ||
| 86 | + SmsChannelDO smsChannel = this.checkSmsChannelValid(template.getChannelId()); | ||
| 87 | + | ||
| 83 | // 校验手机号码是否存在 | 88 | // 校验手机号码是否存在 |
| 84 | mobile = this.checkMobile(mobile); | 89 | mobile = this.checkMobile(mobile); |
| 85 | // 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志 | 90 | // 构建有序的模板参数。为什么放在这个位置,是提前保证模板参数的正确性,而不是到了插入发送日志 |
| 86 | List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams); | 91 | List<KeyValue<String, Object>> newTemplateParams = this.buildTemplateParams(template, templateParams); |
| 87 | 92 | ||
| 88 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 | 93 | // 创建发送日志。如果模板被禁用,则不发送短信,只记录日志 |
| 89 | - Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()); | 94 | + Boolean isSend = CommonStatusEnum.ENABLE.getStatus().equals(template.getStatus()) |
| 95 | + && CommonStatusEnum.ENABLE.getStatus().equals(smsChannel.getStatus()); | ||
| 96 | + ; | ||
| 90 | String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams); | 97 | String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams); |
| 91 | Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); | 98 | Long sendLogId = smsLogService.createSmsLog(mobile, userId, userType, isSend, template, content, templateParams); |
| 92 | 99 | ||
| @@ -98,6 +105,16 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -98,6 +105,16 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 98 | return sendLogId; | 105 | return sendLogId; |
| 99 | } | 106 | } |
| 100 | 107 | ||
| 108 | + @VisibleForTesting | ||
| 109 | + public SmsChannelDO checkSmsChannelValid(Long channelId) { | ||
| 110 | + // 获得短信模板。考虑到效率,从缓存中获取 | ||
| 111 | + SmsChannelDO channelDO = smsChannelService.getSmsChannel(channelId); | ||
| 112 | + // 短信模板不存在 | ||
| 113 | + if (channelDO == null) { | ||
| 114 | + throw exception(SMS_SEND_TEMPLATE_NOT_EXISTS); | ||
| 115 | + } | ||
| 116 | + return channelDO; | ||
| 117 | + } | ||
| 101 | 118 | ||
| 102 | @VisibleForTesting | 119 | @VisibleForTesting |
| 103 | public SmsTemplateDO checkSmsTemplateValid(String templateCode) { | 120 | public SmsTemplateDO checkSmsTemplateValid(String templateCode) { |
| @@ -112,10 +129,10 @@ public class SmsSendServiceImpl implements SmsSendService { | @@ -112,10 +129,10 @@ public class SmsSendServiceImpl implements SmsSendService { | ||
| 112 | 129 | ||
| 113 | /** | 130 | /** |
| 114 | * 将参数模板,处理成有序的 KeyValue 数组 | 131 | * 将参数模板,处理成有序的 KeyValue 数组 |
| 115 | - * | 132 | + * <p> |
| 116 | * 原因是,部分短信平台并不是使用 key 作为参数,而是数组下标,例如说腾讯云 https://cloud.tencent.com/document/product/382/39023 | 133 | * 原因是,部分短信平台并不是使用 key 作为参数,而是数组下标,例如说腾讯云 https://cloud.tencent.com/document/product/382/39023 |
| 117 | * | 134 | * |
| 118 | - * @param template 短信模板 | 135 | + * @param template 短信模板 |
| 119 | * @param templateParams 原始参数 | 136 | * @param templateParams 原始参数 |
| 120 | * @return 处理后的参数 | 137 | * @return 处理后的参数 |
| 121 | */ | 138 | */ |
yudao-ui-admin/src/views/infra/fileConfig/index.vue
| @@ -77,7 +77,7 @@ | @@ -77,7 +77,7 @@ | ||
| 77 | <el-input v-model="form.remark" placeholder="请输入备注" /> | 77 | <el-input v-model="form.remark" placeholder="请输入备注" /> |
| 78 | </el-form-item> | 78 | </el-form-item> |
| 79 | <el-form-item label="存储器" prop="storage"> | 79 | <el-form-item label="存储器" prop="storage"> |
| 80 | - <el-select v-model="form.storage" placeholder="请选择存储器" :disabled="form.id"> | 80 | + <el-select v-model="form.storage" placeholder="请选择存储器" :disabled="form.id !== undefined"> |
| 81 | <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_FILE_STORAGE)" | 81 | <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_FILE_STORAGE)" |
| 82 | :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | 82 | :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> |
| 83 | </el-select> | 83 | </el-select> |
| @@ -91,7 +91,7 @@ | @@ -91,7 +91,7 @@ | ||
| 91 | <el-input v-model="form.config.host" placeholder="请输入主机地址" /> | 91 | <el-input v-model="form.config.host" placeholder="请输入主机地址" /> |
| 92 | </el-form-item> | 92 | </el-form-item> |
| 93 | <el-form-item v-if="form.storage >= 11 && form.storage <= 12" label="主机端口" prop="config.port"> | 93 | <el-form-item v-if="form.storage >= 11 && form.storage <= 12" label="主机端口" prop="config.port"> |
| 94 | - <el-input-number min="0" v-model="form.config.port" placeholder="请输入主机端口" /> | 94 | + <el-input-number :min="0" v-model="form.config.port" placeholder="请输入主机端口" /> |
| 95 | </el-form-item> | 95 | </el-form-item> |
| 96 | <el-form-item v-if="form.storage >= 11 && form.storage <= 12" label="用户名" prop="config.username"> | 96 | <el-form-item v-if="form.storage >= 11 && form.storage <= 12" label="用户名" prop="config.username"> |
| 97 | <el-input v-model="form.config.username" placeholder="请输入密码" /> | 97 | <el-input v-model="form.config.username" placeholder="请输入密码" /> |