mirror of
https://gitee.com/y_project/RuoYi-Cloud.git
synced 2026-01-26 19:51:56 +08:00
[feat] 限制短信验证码获取频次
This commit is contained in:
@@ -3,6 +3,7 @@ package com.ruoyi.gateway.handler;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import com.ruoyi.common.core.utils.uuid.IdUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@@ -35,7 +36,10 @@ public class ValidateCodeHandler implements HandlerFunction<ServerResponse>
|
|||||||
switch (serverRequest.queryParam("type").orElse("image")) {
|
switch (serverRequest.queryParam("type").orElse("image")) {
|
||||||
case "sms":
|
case "sms":
|
||||||
if (Objects.nonNull(serverRequest.queryParam("receiver").orElse(null))) {
|
if (Objects.nonNull(serverRequest.queryParam("receiver").orElse(null))) {
|
||||||
ajax = validateCodeService.createSMSCaptcha(serverRequest.queryParam("receiver").orElse(null));
|
ajax = validateCodeService.createSMSCaptcha(
|
||||||
|
serverRequest.queryParam("receiver").orElse(null),
|
||||||
|
serverRequest.queryParam("uuid").orElse(IdUtils.simpleUUID())
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public interface ValidateCodeService
|
|||||||
/**
|
/**
|
||||||
* 生成短信验证码
|
* 生成短信验证码
|
||||||
*/
|
*/
|
||||||
public AjaxResult createSMSCaptcha(String receiver) throws IOException, CaptchaException;
|
public AjaxResult createSMSCaptcha(String receiver,String uuid) throws IOException, CaptchaException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验验证码
|
* 校验验证码
|
||||||
|
|||||||
@@ -104,20 +104,23 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AjaxResult createSMSCaptcha(String receiver) throws IOException, CaptchaException {
|
public AjaxResult createSMSCaptcha(String receiver, String uuid) throws IOException, CaptchaException {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
boolean captchaEnabled = captchaProperties.getEnabled();
|
boolean captchaEnabled = captchaProperties.getEnabled();
|
||||||
ajax.put("captchaEnabled", captchaEnabled);
|
ajax.put("captchaEnabled", captchaEnabled);
|
||||||
if (!captchaEnabled)
|
if (!captchaEnabled) {
|
||||||
{
|
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
// 保存验证码信息
|
// 保存验证码信息
|
||||||
String uuid = IdUtils.simpleUUID();
|
|
||||||
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + uuid;
|
||||||
|
long expire = redisService.getExpire(verifyKey);
|
||||||
|
if (expire <= 0) {
|
||||||
String code = captchaProducerNumber.createText();
|
String code = captchaProducerNumber.createText();
|
||||||
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
|
||||||
ajax.put("code", code);
|
ajax.put("code", code);
|
||||||
|
expire = redisService.getExpire(verifyKey);
|
||||||
|
}
|
||||||
|
ajax.put("expire", expire);
|
||||||
ajax.put("uuid", uuid);
|
ajax.put("uuid", uuid);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user