lyhzzz 1 month ago
parent
commit
8e7d64b870

+ 6 - 0
src/main/java/com/fdkankan/ucenter/controller/app/AppController.java

@@ -44,6 +44,12 @@ public class AppController extends BaseController {
         appService.appLogin(param);
         return Result.success();
     }
+
+    @GetMapping("/qrCodeLogin")
+    public Result qrCodeLogin(@RequestParam(required = false) String uuid){
+        appService.qrCodeLogin(getUserName(),uuid);
+        return Result.success();
+    }
     /**
      * app登录
      * appUserName  相机设备嘛

+ 2 - 1
src/main/java/com/fdkankan/ucenter/interceptor/AppInterceptor.java

@@ -46,7 +46,8 @@ public class AppInterceptor implements HandlerInterceptor {
 				if(redisUtil.hasKey(redisKey2)){
 					redisUtil.expire(redisKey2,21800L);
 				}else {
-					redisUtil.set(redisKey2,token,21800L);
+					this.needLogin(request,response);
+					return false;
 				}
 				return true;
 			}

+ 9 - 0
src/main/java/com/fdkankan/ucenter/service/impl/AppService.java

@@ -122,6 +122,14 @@ public class AppService {
         redisUtil.set(param.getUuid(),param.getAppUserName(),60 * 5);
     }
 
+    public void qrCodeLogin(String userName, String uuid) {
+        if(StringUtils.isEmpty(userName) || StringUtils.isEmpty(uuid)){
+            throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
+        }
+        redisUtil.set(uuid,userName,60 * 5);
+
+    }
+
     private Long commonCheckCamera(AppLoginParam param){
         Camera camera = cameraService.getBySnCodeAndPassword(param.getAppUserName(),param.getAppPassword());
         if(camera == null){
@@ -170,6 +178,7 @@ public class AppService {
         if(redisUtil.hasKey(redisKey)){
             redisUtil.del(redisKey);
         }
+        loginService.logout(token);
     }
 
     public JSONObject getNickName() {

+ 7 - 20
src/main/java/com/fdkankan/ucenter/service/impl/LoginService.java

@@ -203,7 +203,7 @@ public class LoginService {
     }
 
     public JSONObject createLoginQrCode() throws Exception {
-        String uuid = NumberUtils.getUUID();
+        String uuid = "4dkankan_"+NumberUtils.getUUID();
         String filePath = QrCodeFilePath.LOGIN_QR_CODE_PATH + uuid + ".png";
         File file = new File(QrCodeFilePath.LOGO_IMAGE_LOCAL);
         if(!file.exists()){
@@ -217,7 +217,7 @@ public class LoginService {
         return json;
     }
 
-    public JSONObject sendUserInfo(String uuid) {
+    public Object sendUserInfo(String uuid) {
         if (StringUtils.isEmpty(uuid)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
@@ -229,28 +229,15 @@ public class LoginService {
         if(!redisUtil.hasKey(uuid)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3004, LoginConstant.FAILURE_MSG_3004);
         }
-        String childName = redisUtil.get(uuid);
-        Camera camera = cameraService.getBySnCode(childName);
-        if(camera == null){
-            throw new BusinessException(LoginConstant.FAILURE_CODE_3004, LoginConstant.FAILURE_MSG_3004);
-        }
-        CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
-        if(cameraDetail == null){
+
+        String userName = redisUtil.get(uuid);
+        User user = userService.getByUserName(userName);
+        if(user == null){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3004, LoginConstant.FAILURE_MSG_3004);
         }
-        UserVo userVo = new UserVo();
-        userVo.setUserName(childName);
-        userVo.setId(cameraDetail.getUserId());
-        userVo.setCameraId(camera.getId());
-        userVo.setCameraLogin(1);
-        String token = this.redisLogin(childName,JSONObject.toJSONString(userVo),"camera");
-        JSONObject obj = new JSONObject();
-        obj.put("token",token);
-        obj.put("childName",childName);
-        obj.put("to",1);
         redisUtil.del(uuid);
         FileUtils.deleteFile(QrCodeFilePath.LOGIN_QR_CODE_PATH +uuid +".png");
-        return obj;
+        return this.login(userService.getByUserName(userName));
     }