|
|
@@ -35,19 +35,21 @@ public class SckwSmsHandlerService {
|
|
|
log.info("接收到发送短信消息:{},开始处理", JSON.toJSONString(sckwSms));
|
|
|
String type = sckwSms.getType();
|
|
|
String phone = sckwSms.getPhone();
|
|
|
- String requestKey = getKey(RedisConstant.MESSAGE_SMS_VERIFY_CODE_REQUEST_KEY, type, phone);
|
|
|
- if (Boolean.FALSE.equals(RedissonUtils.tryLock(requestKey, 5L, 10L))) {
|
|
|
+ String lockKey = getKey(RedisConstant.MESSAGE_SMS_VERIFY_CODE_LOCK_KEY, type, phone);
|
|
|
+ if (Boolean.FALSE.equals(RedissonUtils.tryLock(lockKey, 5L, 10L))) {
|
|
|
log.info("获取发送短信锁失败,不处理");
|
|
|
return;
|
|
|
}
|
|
|
try {
|
|
|
- String valueKey = getKey(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, type, phone);
|
|
|
- if (Boolean.TRUE.equals(RedissonUtils.exists(valueKey))) {
|
|
|
+ String requestKey = getKey(RedisConstant.MESSAGE_SMS_VERIFY_CODE_REQUEST_KEY, type, phone);
|
|
|
+ if (Boolean.TRUE.equals(RedissonUtils.exists(requestKey))) {
|
|
|
throw new BusinessException("请勿频繁获取短信验证码!");
|
|
|
}
|
|
|
+ RedissonUtils.putString(requestKey, String.valueOf(sckwSms.getParams().get("code")), RedisConstant.SMS_VERIFY_CODE_REQUEST_TIME);
|
|
|
//发送短信
|
|
|
SmsUtil.sendSms(sckwSms.getPhone(), sckwSms.getSignName(), sckwSms.getTemplateCode().getName(), JSON.toJSONString(sckwSms.getParams()));
|
|
|
//放入缓存
|
|
|
+ String valueKey = getKey(RedisConstant.MESSAGE_SMS_VERIFY_CODE_VALUE_KEY, type, phone);
|
|
|
RedissonUtils.putString(valueKey, String.valueOf(sckwSms.getParams().get("code")), RedisConstant.SMS_VERIFY_CODE_VALID_TIME);
|
|
|
//数据入库
|
|
|
SmsCodeEnum smsCodeEnum = sckwSms.getTemplateCode();
|
|
|
@@ -58,7 +60,7 @@ public class SckwSmsHandlerService {
|
|
|
kwmSms.setUpdateBy(sckwSms.getCreateBy());
|
|
|
kwmSmsService.add(kwmSms);
|
|
|
} finally {
|
|
|
- RedissonUtils.unlock(requestKey);
|
|
|
+ RedissonUtils.unlock(lockKey);
|
|
|
}
|
|
|
}
|
|
|
|