From 698ae84adaf1b8d0e8dd61d7279863fe17c1e81d Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期四, 23 一月 2025 14:20:39 +0800
Subject: [PATCH] 1

---
 ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
index f8dd206..3461cd8 100644
--- a/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
+++ b/ruoyi-auth/src/main/java/com/ruoyi/auth/controller/TokenController.java
@@ -134,13 +134,14 @@
     {
         // 验证码生成
         String code = String.valueOf(Math.random()).substring(2, 6);
+        // 发送验证码
+        String result = SmsUtils.sendSms(registerUser.getPhone(), code);
         code += ":"+System.currentTimeMillis();
 
         // 缓存验证码
         String verifyKey = CacheConstants.PHONE_CODE_KEY + registerUser.getPhone();
         redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
-        // 发送验证码
-        String result = SmsUtils.sendSms(registerUser.getPhone(), code);
+
         if (!"OK".equals(result))
         {
             return R.fail("验证码发送失败");
@@ -202,12 +203,13 @@
                 throw new CaptchaException("验证码错误");
             }
             String[] split = captcha.split(":");
-            long l = Long.parseLong(split[2]);
+            long l = Long.parseLong(split[1]);
             long l1 = System.currentTimeMillis();
             // 判断是否大于两分钟
             if (l1 - l > 2 * 60 * 1000) {
                 throw new CaptchaException("验证码已失效");
             }
+            captcha = split[0];
             if (!smsCode.equalsIgnoreCase(captcha)) {
                 throw new CaptchaException("验证码错误");
             }

--
Gitblit v1.7.1