| | |
| | | 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; |
| | |
| | | } |
| | | 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); |
| | |
| | | } |
| | | 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()); |
| | |
| | | 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); |