lyhzzz il y a 1 semaine
Parent
commit
36c1b4dfc3

+ 3 - 0
src/main/java/com/fdkankan/ucenter/common/RedisKeyUtil.java

@@ -15,5 +15,8 @@ public class RedisKeyUtil {
 
     public static final String SCENE_COOPERATION_NUM_USERID = "scene:cooperation:num:userId";
 
+    public static final String LOGIN_USER = "4dkankan:login.username:%s:token:%s";
+
+
 
 }

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

@@ -43,7 +43,7 @@ public class AppInterceptor implements HandlerInterceptor {
 			String redisKey = RedisKeyUtil.PREFIX_CACHE_CAMERA + username;
 			if(redisUtil.hasKey(redisKey)){
 				redisUtil.expire(redisKey,21800L);
-				String redisKey2 =  String.format(RedisKey.TOKEN_V3 , token );
+				String redisKey2 =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
 				if(redisUtil.hasKey(redisKey2)){
 					redisUtil.expire(redisKey2,21800L);
 				}else {

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

@@ -42,7 +42,8 @@ public class UcenterInterceptor implements HandlerInterceptor {
 			return false;
 		}
 		try {
-			String redisKey = String.format(RedisKey.TOKEN_V3,token);
+			String username = JwtUtil.getUsername(token);
+			String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
 			if(redisUtil.hasKey(redisKey)){
 				redisUtil.expire(redisKey,2 * 60 * 60);
 				return true;

+ 2 - 1
src/main/java/com/fdkankan/ucenter/service/impl/AppService.java

@@ -104,7 +104,8 @@ public class AppService {
         redisUtil.set(redisKey, token,time);
 
         //设置官网token
-        String redisKey2 =  String.format(RedisKey.TOKEN_V3 , token );
+        String redisKey2 =  String.format(RedisKeyUtil.LOGIN_USER ,userName, token );
+
         redisUtil.set(redisKey2, value,time);
         return token;
     }

+ 3 - 1
src/main/java/com/fdkankan/ucenter/service/impl/InnerServiceImpl.java

@@ -8,6 +8,7 @@ import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.ucenter.common.constants.ResultCode;
@@ -67,7 +68,8 @@ public class InnerServiceImpl implements IInnerService {
         }
         User user = userService.getById(userId);
         String token = JwtUtil.createJWT(-1, user.getUserName(), "user");
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,user.getUserName(), token );
+
         redisUtil.set(redisKey, JSON.toJSONString(user), RedisKey.EXPIRE_TIME_2_HOUR);
 
         JSONObject object = new JSONObject();

+ 5 - 3
src/main/java/com/fdkankan/ucenter/service/impl/LoginService.java

@@ -105,7 +105,8 @@ public class LoginService {
     }
 
     public void logout(String token) {
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String username = JwtUtil.getUsername(token);
+        String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
         if(redisUtil.hasKey(redisKey)){
             redisUtil.del(redisKey);
         }
@@ -298,13 +299,14 @@ public class LoginService {
 
     public String redisLogin(String userName,String value,String loginType){
         String token = JwtUtil.createJWT(-1,userName,loginType);
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,userName, token );
         redisUtil.set(redisKey, value,2 * 60 * 60);
         return token;
     }
 
     public void loginCheck(String token) {
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String username = JwtUtil.getUsername(token);
+        String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
         if(!redisUtil.hasKey(redisKey)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3004, LoginConstant.FAILURE_MSG_3004);
         }

+ 4 - 1
src/main/java/com/fdkankan/ucenter/service/impl/SceneApiService.java

@@ -5,9 +5,11 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.common.util.JwtUtil;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.PageInfo;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.ucenter.constant.CameraConstant;
@@ -108,7 +110,8 @@ public class SceneApiService {
         if(StringUtils.isEmpty(token)){
             throw new BusinessException(3004, "无token参数");
         }
-        String redisKey = String.format(RedisKey.TOKEN_V3,token);
+        String username = JwtUtil.getUsername(token);
+        String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
 
         if( !redisUtil.hasKey(redisKey)){
             throw new BusinessException(3004, "token参数不正确");

+ 4 - 1
src/main/java/com/fdkankan/ucenter/service/impl/UserServiceImpl.java

@@ -10,6 +10,7 @@ import com.fdkankan.common.constant.ConstantUrl;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.*;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
@@ -314,7 +315,9 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
     @Override
     public User getByToken(String token) {
         try {
-            String value = redisUtil.get(String.format(RedisKey.TOKEN_V3, token));
+            String username = JwtUtil.getUsername(token);
+            String redisKey =  String.format(RedisKeyUtil.LOGIN_USER ,username, token );
+            String value = redisUtil.get(redisKey);
             if(StringUtils.isEmpty(value)){
                 throw new Exception();
             }