Browse Source

[feat]
1、增加短信验证码开关

limeng 4 months ago
parent
commit
47b496be97

+ 16 - 12
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/LoginToWebsiteController.java

@@ -44,6 +44,7 @@ import com.tourism.webadmin.back.service.TourUserService;
 import com.tourism.webadmin.back.service.impl.TourBookInfoServiceImpl;
 import com.tourism.webadmin.back.util.SMSUtils;
 import com.tourism.common.additional.config.ApplicationConfig;
+import com.tourism.webadmin.config.SmsSwitch;
 import com.tourism.webadmin.upms.model.SysUser;
 import io.jsonwebtoken.lang.Collections;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -106,14 +107,15 @@ public class LoginToWebsiteController {
     private UpDownloaderFactory upDownloaderFactory;
     @Autowired
     private WxMaService wxMaService;
-
     @Autowired
     private TourCountryCodeService tourCountryCodeService;
+    @Autowired
+    private TourBookInfoServiceImpl tourBookInfoService;
+    @Autowired
+    private SmsSwitch smsSwitch;
 
     private static final String SHOW_NAME_FIELD = "showName";
     private static final String HEAD_IMAGE_URL_FIELD = "headImageUrl";
-    @Autowired
-    private TourBookInfoServiceImpl tourBookInfoService;
 
 
     /**
@@ -279,15 +281,17 @@ public class LoginToWebsiteController {
             @MyRequestBody String smsCode,
             @MyRequestBody String countryCode) throws UnsupportedEncodingException
     {
-        // 校验短信验证码
-//        String smsCodeKey = CacheConstants.getSmsCodeKey(loginMoblie);
-//        RBucket<String> bucket = redissonClient.getBucket(smsCodeKey);
-//        String redisCode = bucket.get();
-//        if(StringUtils.isBlank(redisCode) || !redisCode.equals(smsCode)){
-//            return ResponseResult.error(ErrorCodeEnum.SMS_CODE_ERR);
-//        }
-//        // 短信验证码校验成功,清除验证码
-//        bucket.delete();
+        if(smsSwitch.isEnable()) {
+            // 校验短信验证码
+            String smsCodeKey = CacheConstants.getSmsCodeKey(loginMoblie);
+            RBucket<String> bucket = redissonClient.getBucket(smsCodeKey);
+            String redisCode = bucket.get();
+            if(StringUtils.isBlank(redisCode) || !redisCode.equals(smsCode)){
+                return ResponseResult.error(ErrorCodeEnum.SMS_CODE_ERR);
+            }
+            // 短信验证码校验成功,清除验证码
+            bucket.delete();
+        }
         // 查询用户信息
         TourUser tourUser = tourUserService.getOne(Wrappers.<TourUser>lambdaQuery().eq(TourUser::getMobile, loginMoblie));
         // 如果用户信息不存在,则新建

+ 15 - 0
application-webadmin/src/main/java/com/tourism/webadmin/config/SmsSwitch.java

@@ -0,0 +1,15 @@
+package com.tourism.webadmin.config;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+@Data
+@Component
+@ConfigurationProperties(prefix = "sms")
+public class SmsSwitch {
+    /**
+     * 短信开关
+     */
+    private boolean enable;
+}

+ 1 - 0
application-webadmin/src/main/resources/application-prod.yml

@@ -206,6 +206,7 @@ sa-token:
   is-read-header: true
   is-read-cookie: false
 sms:
+  enable: false
   config-type: yaml
   blends:
     huawei:

+ 1 - 0
application-webadmin/src/main/resources/application-test.yml

@@ -214,6 +214,7 @@ sa-token:
   is-read-header: true
   is-read-cookie: false
 sms:
+  enable: false
   config-type: yaml
   blends:
     huawei: