|
|
@@ -1,6 +1,8 @@
|
|
|
package com.sckw.message.service;
|
|
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.sckw.core.common.enums.enums.DictEnum;
|
|
|
+import com.sckw.core.common.enums.enums.DictTypeEnum;
|
|
|
import com.sckw.core.exception.BusinessException;
|
|
|
import com.sckw.core.utils.NumberUtils;
|
|
|
import com.sckw.core.web.context.LoginUserHolder;
|
|
|
@@ -16,6 +18,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @author: yzc
|
|
|
@@ -37,23 +40,24 @@ public class SmsService {
|
|
|
* @date: 2023-06-13 13:43
|
|
|
*/
|
|
|
public void sendVerifyCode(SendSmsVerifyCoderReqVO param) {
|
|
|
+ String type = param.getType();
|
|
|
+ if (Objects.isNull(DictEnum.getLabel(DictTypeEnum.SEND_SMS_TYPE.getType(), type))) {
|
|
|
+ throw new BusinessException("非法短信类型!");
|
|
|
+ }
|
|
|
String phone = param.getPhone();
|
|
|
- // 防重攻击
|
|
|
- String messageSmsVerifyCodeKey = getMessageSmsVerifyCodeKey(phone);
|
|
|
+ String messageSmsVerifyCodeKey = getMessageSmsVerifyCodeKey(type, phone);
|
|
|
if (Boolean.TRUE.equals(RedissonUtils.exists(messageSmsVerifyCodeKey))) {
|
|
|
- throw new BusinessException("请勿频繁获取短信验证码");
|
|
|
+ throw new BusinessException("请勿频繁获取短信验证码!");
|
|
|
}
|
|
|
- SckwSms sckwSms = new SckwSms();
|
|
|
- sckwSms.setPhone(param.getPhone());
|
|
|
- sckwSms.setTemplateCode(SmsCodeEnum.VERIFICATION_CODE);
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("code", NumberUtils.createRandomVcode());
|
|
|
- sckwSms.setParams(params);
|
|
|
- sckwSms.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ SckwSms sckwSms = new SckwSms();
|
|
|
+ sckwSms.setPhone(param.getPhone()).setType(type).setTemplateCode(SmsCodeEnum.VERIFICATION_CODE)
|
|
|
+ .setParams(params).setCreateBy(LoginUserHolder.getUserId());
|
|
|
streamBridge.send("sckw-sms", JSON.toJSONString(sckwSms));
|
|
|
}
|
|
|
|
|
|
- private String getMessageSmsVerifyCodeKey(String phone) {
|
|
|
- return String.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, phone);
|
|
|
+ private String getMessageSmsVerifyCodeKey(String type, String phone) {
|
|
|
+ return String.format(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, type, phone);
|
|
|
}
|
|
|
}
|