疯狂的狮子li
2023-03-30 1ed1752f678f769e43e9faa34809701850c7f727
ruoyi-admin/src/main/java/com/ruoyi/web/controller/CaptchaController.java
@@ -6,7 +6,6 @@
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.GlobalConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.SpringUtils;
@@ -64,7 +63,8 @@
        }
        String key = GlobalConstants.CAPTCHA_CODE_KEY + phonenumber;
        String code = RandomUtil.randomNumbers(4);
        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired));
        // 验证码模板id 自行处理 (查数据库或写死均可)
        String templateId = configService.selectConfigByKey("sys.account.templateId");
        Map<String, String> map = new HashMap<>(1);
@@ -90,9 +90,10 @@
        }
        String key = GlobalConstants.CAPTCHA_CODE_KEY + email;
        String code = RandomUtil.randomNumbers(4);
        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
        RedisUtils.setCacheObject(key, code, Duration.ofMinutes(captchaExpired));
        try {
            MailUtils.sendText(email, "登录验证码", "您本次验证码为:" + code + ",有效性为" + Constants.CAPTCHA_EXPIRATION + "分钟,请尽快填写。");
            MailUtils.sendText(email, "登录验证码", "您本次验证码为:%s,有效性为%d分钟,请尽快填写。".formatted(code, captchaExpired));
        } catch (Exception e) {
            log.error("验证码短信发送异常 => {}", e.getMessage());
            return R.fail(e.getMessage());
@@ -128,7 +129,8 @@
            Expression exp = parser.parseExpression(StringUtils.remove(code, "="));
            code = exp.getValue(String.class);
        }
        RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(Constants.CAPTCHA_EXPIRATION));
        Integer captchaExpired = Convert.toInt(configService.selectConfigByKey("sys.account.captchaExpired"));
        RedisUtils.setCacheObject(verifyKey, code, Duration.ofMinutes(captchaExpired));
        captchaVo.setUuid(uuid);
        captchaVo.setImg(captcha.getImageBase64());
        return R.ok(captchaVo);