Browse Source

新增短信验证码
新增登录校验短信验证码
新增注册校验短信验证码

fangzhen 7 months ago
parent
commit
e7327edc46

+ 10 - 6
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java

@@ -134,13 +134,17 @@ public class SysRegisterService {
             throw new CaptchaNullException();
         }
         String verifyKey = CacheConstants.SMS_REGISTER_CODE_KEY + StringUtils.nvl(username, "");
-        String captcha = redisCache.getCacheObject(verifyKey).toString();
-        redisCache.deleteObject(verifyKey);
-        if (captcha == null) {
+        try {
+            String captcha = redisCache.getCacheObject(verifyKey).toString();
+            redisCache.deleteObject(verifyKey);
+            if (captcha == null) {
+                throw new CaptchaExpireException();
+            }
+            if (!code.equalsIgnoreCase(captcha)) {
+                throw new CaptchaException();
+            }
+        } catch (NullPointerException e) {
             throw new CaptchaExpireException();
         }
-        if (!code.equalsIgnoreCase(captcha)) {
-            throw new CaptchaException();
-        }
     }
 }