he2802 3 éve
szülő
commit
b99811e59c

+ 22 - 5
zhongzheng-api/src/main/java/com/zhongzheng/controller/wx/WxLoginController.java

@@ -82,16 +82,17 @@ public class WxLoginController
 
     @ApiOperation("小程序校验PC登录二维码")
     @PostMapping("/scan_login_check")
-    public AjaxResult scanLoginCheck(@RequestBody String scanCode)
+    public AjaxResult scanLoginCheck(@RequestBody WxLoginBody loginBody)
     {
         ClientLoginUser loginUser = wxTokenService.getLoginUser(ServletUtils.getRequest());
+        String scanCode = loginBody.getScanCode();
         String key = "SCAN_LOGIN_"+scanCode;
         Long userId = redisCache.getCacheObject(key);
-        if(Validator.isNotEmpty(userId)){
-            redisCache.setCacheObject(key, loginUser.getUser().getUserId(),30, TimeUnit.SECONDS);//30秒锁定
+        if(Validator.isNotEmpty(userId)&&userId.equals(-2L)){
+            redisCache.setCacheObject(key, loginUser.getUser().getUserId(),60, TimeUnit.SECONDS);//60秒锁定
             return AjaxResult.success();
         }else{
-            return AjaxResult.error("校验码不存在或已过期 ");
+            return AjaxResult.error("校验码不存在或已过期");
         }
     }
 
@@ -103,10 +104,26 @@ public class WxLoginController
         return AjaxResult.success(map);
     }
 
+    @ApiOperation("小程序已扫码")
+    @GetMapping("/scan_code")
+    public AjaxResult scanCode(WxLoginBody loginBody)
+    {
+        String scanCode = loginBody.getScanCode();
+        String key = "SCAN_LOGIN_"+scanCode;
+        Long userId = redisCache.getCacheObject(key);
+        if(Validator.isEmpty(userId)){
+            return AjaxResult.error("标识码不存在");
+        }else{
+            redisCache.setCacheObject(key, -2L,180, TimeUnit.SECONDS);//延长180秒锁定
+            return AjaxResult.success();
+        }
+    }
+
     @ApiOperation("PC检查小程序是否扫码登录")
     @GetMapping("/check_pc_login")
-    public AjaxResult checkPcLogin(String scanCode)
+    public AjaxResult checkPcLogin(WxLoginBody loginBody)
     {
+        String scanCode = loginBody.getScanCode();
         Map<String,Object> map = wxLoginService.checkPcLogin(scanCode);
         return AjaxResult.success(map);
     }

+ 1 - 1
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -110,7 +110,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 // 过滤请求
                 .authorizeRequests()
                 // 对于登录login 验证码captchaImage 允许匿名访问
-                .antMatchers("/login", "/captchaImage", "/testLogin","/wx/pay/callback","/gzh_login","/check_pc_login","/pc_login_url").anonymous()
+                .antMatchers("/login", "/captchaImage", "/testLogin","/wx/pay/callback","/gzh_login","/check_pc_login","/pc_login_url","/scan_code").anonymous()
                 .antMatchers("/aliyun/oss/callback").anonymous()
                 .antMatchers(
                         HttpMethod.GET,

+ 5 - 2
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/WxLoginService.java

@@ -128,7 +128,7 @@ public class WxLoginService
         } catch (Exception e) {
             e.printStackTrace();
         }
-        redisCache.setCacheObject(key, -1,30, TimeUnit.SECONDS);//30秒锁定
+        redisCache.setCacheObject(key, -1L,60, TimeUnit.SECONDS);//30秒锁定
         Map<String,Object> map = new HashMap<>();
         map.put("scanCode",scanCode);
         map.put("urlBase64",urlBase64);
@@ -143,7 +143,10 @@ public class WxLoginService
     public Map<String,Object> checkPcLogin(String scanCode) {
         String key = "SCAN_LOGIN_"+scanCode;
         Long userId = redisCache.getCacheObject(key);
-        if(Validator.isNotEmpty(userId)&&userId.longValue()>0L){
+        if(Validator.isNotEmpty(userId)&&userId.equals(-2L)){
+            throw new CustomException("小程序已扫码");
+        }
+        else if(Validator.isNotEmpty(userId)&&userId.longValue()>0L){
             User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getUserId, userId).last("limit 1"));
             if(Validator.isEmpty(user)){
                 throw new CustomException("暂未登录");

+ 2 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/bo/WxLoginBody.java

@@ -28,7 +28,6 @@ public class WxLoginBody {
 
     /** code */
     @ApiModelProperty("code")
-    @NotBlank(message = "code不能为空")
     private String code;
 
     /** encryptedData */
@@ -38,6 +37,8 @@ public class WxLoginBody {
     @ApiModelProperty("邀请码")
     private String inviteCode;
 
+    @ApiModelProperty("扫码标识码")
+    private String scanCode;
 
 
 }