Parcourir la source

rename cache keys.

deason il y a 2 ans
Parent
commit
170fc7823a

+ 16 - 22
src/main/java/cn/com/qmth/examcloud/app/controller/UserAuthRestController.java

@@ -7,19 +7,6 @@
 
 package cn.com.qmth.examcloud.app.controller;
 
-import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_KEY;
-import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_TOKEN;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
 import cn.com.qmth.examcloud.app.model.LoginInfo;
 import cn.com.qmth.examcloud.app.model.LoginType;
 import cn.com.qmth.examcloud.app.model.Result;
@@ -28,6 +15,13 @@ import cn.com.qmth.examcloud.app.service.CoreAuthService;
 import cn.com.qmth.examcloud.app.service.CoreBasicService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_KEY;
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_TOKEN;
 
 /**
  * 认证中心相关接口
@@ -119,9 +113,9 @@ public class UserAuthRestController {
 
     @ApiOperation(value = "修改密码接口")
     @RequestMapping(value = "/user/update/password", method = {RequestMethod.POST})
-    public Result updatePassword(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token,  @RequestParam String password,
+    public Result updatePassword(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token, @RequestParam String password,
                                  @RequestParam String newPassword) throws Exception {
-        return authService.updateStudentPassword(key, token,password, newPassword);
+        return authService.updateStudentPassword(key, token, password, newPassword);
     }
 
     @ApiOperation(value = "重置密码接口")
@@ -135,20 +129,20 @@ public class UserAuthRestController {
     public Result userBindingPhone(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token, @RequestParam String phone, @RequestParam String code) throws Exception {
         return authService.userBindingPhone(key, token, phone, code);
     }
-    
+
     @ApiOperation(value = "极验-验证初始化接口")
     @PostMapping(value = "/verifyCode/register")
-    public Result register(@RequestParam String user_id,@RequestParam String client_type,@RequestParam(required = false) String ip_address) throws Exception{
-        return authService.register(user_id, client_type, ip_address) ;
+    public Result register(@RequestParam String user_id, @RequestParam String client_type, @RequestParam(required = false) String ip_address) throws Exception {
+        return authService.register(user_id, client_type, ip_address);
     }
 
     @ApiOperation(value = "极验-验证码登录接口")
     @PostMapping(value = "/verifyCode/gt/login")
     public Result geetestLogin(
-    		@RequestParam String seccode,@RequestParam String validate,@RequestParam String challenge,
-    		@RequestParam String user_id,@RequestParam String client_type,@RequestParam(required = false) String ip_address,
-    		@RequestParam String accountValue,@RequestParam String password,@RequestParam String accountType,
-    		@RequestParam Long rootOrgId) throws Exception{
+            @RequestParam String seccode, @RequestParam String validate, @RequestParam String challenge,
+            @RequestParam String user_id, @RequestParam String client_type, @RequestParam(required = false) String ip_address,
+            @RequestParam String accountValue, @RequestParam String password, @RequestParam String accountType,
+            @RequestParam Long rootOrgId) throws Exception {
 
         return authService.geetestLogin(seccode, validate, challenge, user_id, client_type, ip_address, accountValue, password, accountType, rootOrgId);
     }

+ 23 - 12
src/main/java/cn/com/qmth/examcloud/app/model/Constants.java

@@ -21,22 +21,12 @@ public interface Constants {
      */
     int APP_SESSION_EXPIRE_TIME = 3600 * 24 * 30;
 
-    /**
-     * APP端用户登录信息的redis key前缀
-     */
-    String APP_SESSION_USER_KEY_PREFIX = "APP:SESSION_";
-
     /**
      * 平台端的Token默认过期时间(秒)
      * 默认一小时
      */
     int PLATFORM_SESSION_EXPIRE_TIME = 3600;
 
-    /**
-     * 平台端的Token默认过期时间的redis key
-     */
-    String PLATFORM_SESSION_TIMEOUT_KEY = "$_SESSION_TIMEOUT";
-
     /**
      * 请求格式与默认编码集
      */
@@ -44,38 +34,59 @@ public interface Constants {
 
     /* 默认请求的Header参数 */
     String PARAM_KEY = "key";
+
     String PARAM_TOKEN = "token";
+
     String PARAM_APP_KEY = "app_key";
+
     String PARAM_APP_TOKEN = "app_token";
+
     String PARAM_DEVICE_ID = "deviceId";
+
     String PARAM_TRACE_ID = "TRACE_ID";
+
     String PARAM_CLIENT = "$spring_cloud_client";
+
     String PARAM_CLIENT_VALUE = "-";
 
     String PARAM_ROOT_ORG_ID = "rootOrgId";
+
     String PARAM_ACCOUNT_TYPE = "accountType";
+
     String PARAM_ACCOUNT = "account";
+
     String PARAM_PSW = "password";
 
     /* 常用的文件类型 */
     String FILE_TYPE_ZIP = "zip";
+
     String FILE_TYPE_PDF = "pdf";
+
     String FILE_TYPE_JPG = "jpg";
+
     String FILE_TYPE_JPEG = "jpeg";
+
     String FILE_TYPE_PNG = "png";
 
     /* 系统状态码 */
     String CODE_0 = "0";//错误
+
     String CODE_200 = "200";//成功
+
     String CODE_500 = "500";//失败
+
     String CODE_403 = "403";//认证失败
+
     String CODE_404 = "404";//请求地址不存在
+
     String CODE_409 = "409";//只能在考生端断点续考
+
     String CODE_P001012 = "P-001012";//认证失败
+
     String CODE_B001012 = "B-001012";//认证失败
-    
+
     String COMMON_SUCCESS_CODE = "000000";
-    
+
     String DESC_409 = "有只能在考生端进行的考试,请先在考生端完成该考试";//只能在考生端断点续考
 
 }

+ 5 - 12
src/main/java/cn/com/qmth/examcloud/app/service/CoreAuthService.java

@@ -125,23 +125,16 @@ public interface CoreAuthService {
      */
     LoginInfo getLoginInfo(String key);
 
-    /**
-     * 获取平台端的默认过期时间(秒)
-     *
-     * @return
-     */
-    int getSessionTimeout();
-
     /**
      * 初始化内部接口请求鉴权
      */
     void initRequestTrace();
 
-	Result register(String user_id,String client_type, String ip_address) throws Exception;
+    Result register(String user_id, String client_type, String ip_address) throws Exception;
 
-	Result geetestLogin( String seccode, String validate, String challenge,
-    		 String user_id, String client_type, String ip_address,
-    		 String accountValue, String password, String accountType,
-    		Long rootOrgId) throws Exception;
+    Result geetestLogin(String seccode, String validate, String challenge,
+                        String user_id, String client_type, String ip_address,
+                        String accountValue, String password, String accountType,
+                        Long rootOrgId) throws Exception;
 
 }

+ 5 - 20
src/main/java/cn/com/qmth/examcloud/app/service/impl/CoreAuthServiceImpl.java

@@ -19,6 +19,7 @@ import cn.com.qmth.examcloud.commons.util.JsonMapper;
 import cn.com.qmth.examcloud.core.basic.api.StudentCloudService;
 import cn.com.qmth.examcloud.core.basic.api.request.GetStudentReq;
 import cn.com.qmth.examcloud.core.basic.api.response.GetStudentResp;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.support.cache.CacheHelper;
 import cn.com.qmth.examcloud.support.cache.bean.OrgPropertyCacheBean;
 import com.alibaba.fastjson.JSONObject;
@@ -273,7 +274,7 @@ public class CoreAuthServiceImpl implements CoreAuthService {
             throw new ApiException("key must be not empty.");
         }
         String jsonStr = new JsonMapper().toJson(loginInfo);
-        redisService.set(APP_SESSION_USER_KEY_PREFIX + key, jsonStr, APP_SESSION_EXPIRE_TIME);
+        redisService.set(CacheConstants.CACHE_APP_LOGIN_SESSION + key, jsonStr, APP_SESSION_EXPIRE_TIME);
     }
 
     /**
@@ -283,7 +284,7 @@ public class CoreAuthServiceImpl implements CoreAuthService {
         if (StringUtils.isEmpty(key)) {
             throw new ApiException("key must be not empty.");
         }
-        redisService.delete(APP_SESSION_USER_KEY_PREFIX + key);
+        redisService.delete(CacheConstants.CACHE_APP_LOGIN_SESSION + key);
     }
 
     /**
@@ -294,23 +295,7 @@ public class CoreAuthServiceImpl implements CoreAuthService {
         if (StringUtils.isEmpty(key)) {
             throw new ApiException("key must be not empty.");
         }
-        return redisService.fromJson(APP_SESSION_USER_KEY_PREFIX + key, LoginInfo.class);
-    }
-
-    /**
-     * 获取平台端的默认过期时间(秒)
-     */
-    @Override
-    public int getSessionTimeout() {
-        try {
-            String timeout = redisService.get(Constants.PLATFORM_SESSION_TIMEOUT_KEY);
-            if (StringUtils.isNotEmpty(timeout)) {
-                return Integer.parseInt(timeout);
-            }
-        } catch (Exception e) {
-            //ignore
-        }
-        return Constants.PLATFORM_SESSION_EXPIRE_TIME;
+        return redisService.fromJson(CacheConstants.CACHE_APP_LOGIN_SESSION + key, LoginInfo.class);
     }
 
     /**
@@ -318,7 +303,7 @@ public class CoreAuthServiceImpl implements CoreAuthService {
      */
     @Override
     public void initRequestTrace() {
-        String key = "C_" + ThreadUtils.getTraceID();
+        String key = CacheConstants.CACHE_APP_REQ_TRACE + ThreadUtils.getTraceID();
         Long millis = System.currentTimeMillis();
         redisService.set(key, millis.toString(), 15);
     }

+ 5 - 5
src/test/java/cn/com/qmth/examcloud/app/ServiceTest.java

@@ -1,32 +1,32 @@
 package cn.com.qmth.examcloud.app;
 
-import cn.com.qmth.examcloud.commons.util.JsonMapper;
 import cn.com.qmth.examcloud.app.model.LoginInfo;
 import cn.com.qmth.examcloud.app.model.UserInfo;
 import cn.com.qmth.examcloud.app.service.RedisService;
+import cn.com.qmth.examcloud.commons.util.JsonMapper;
+import cn.com.qmth.examcloud.support.CacheConstants;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
-import static cn.com.qmth.examcloud.app.model.Constants.APP_SESSION_USER_KEY_PREFIX;
-
 @RunWith(SpringRunner.class)
 @SpringBootTest
 public class ServiceTest {
+
     @Autowired
     private RedisService redisService;
 
     @Test
     public void demo() throws Exception {
-        String key = "U_C_109_18809";
+        String key = "$SS:C_109_18809";
         redisService.setObj(key, new UserInfo(), 30);
 
         UserInfo user = redisService.getObj(key, UserInfo.class);
         System.out.println(new JsonMapper().toJson(user));
 
-        key = APP_SESSION_USER_KEY_PREFIX + key;
+        key = CacheConstants.CACHE_APP_LOGIN_SESSION + key;
         LoginInfo loginInfo = redisService.fromJson(key, LoginInfo.class);
         System.out.println(new JsonMapper().toJson(loginInfo));
     }