lyhzzz 1 月之前
父节点
当前提交
7c47d253aa

+ 13 - 1
src/main/java/com/fdkankan/ucenter/aop/SignVerifyAspect.java

@@ -1,5 +1,7 @@
 package com.fdkankan.ucenter.aop;
 
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.sign.SignUtils;
 import com.fdkankan.ucenter.annotation.VerifySign;
 import com.fdkankan.ucenter.common.constants.ResultCode;
@@ -26,6 +28,8 @@ public class SignVerifyAspect {
 
     @Autowired
     IAppSecretService appSecretService;
+    @Autowired
+    RedisUtil redisUtil;
 
     @Around("@annotation(verifySign)")
     public Object verifySign(ProceedingJoinPoint joinPoint, VerifySign verifySign) throws Throwable {
@@ -41,13 +45,21 @@ public class SignVerifyAspect {
         String appId = request.getHeader(verifySign.appId().toLowerCase());
 
         log.info("verifySign--requestPath:{},sign:{},appId:{}",request.getRequestURL(),sign,appId);
-        AppSecret byAppId = appSecretService.getByAppId(appId);
+        AppSecret byAppId = null;
+        if(redisUtil.hasKey("ucenter:sign:appid:"+appId)){
+            byAppId = JSONObject.parseObject(redisUtil.get("ucenter:sign:appid:"+appId),AppSecret.class);
+        }else {
+            byAppId = appSecretService.getByAppId(appId);
+        }
         if(byAppId == null){
             throw new BusinessException(ResultCode.SIGN_ERROR);
         }
         if(!SignUtils.checkSign(sign,appId,byAppId.getPrivateKey())){
             throw new BusinessException(ResultCode.SIGN_ERROR);
         }
+        if(!redisUtil.hasKey("ucenter:sign:appid:"+appId)){
+            redisUtil.set("ucenter:sign:appid:"+appId, JSONObject.toJSONString(byAppId),60 *60 *2);
+        }
         return joinPoint.proceed();
     }
 

+ 14 - 1
src/main/java/com/fdkankan/ucenter/controller/inner/InnerController.java

@@ -1,7 +1,9 @@
 package com.fdkankan.ucenter.controller.inner;
 
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.sign.SignUtils;
 import com.fdkankan.ucenter.annotation.VerifySign;
 import com.fdkankan.ucenter.common.BaseController;
@@ -135,9 +137,20 @@ public class InnerController extends BaseController {
         return Result.success(innerService.getSceneBySnCode(param));
     }
 
+    @Autowired
+    RedisUtil redisUtil;
     @GetMapping(value = "/pdsfsdfsrvateddsfeky/{appId}")
     @VerifySign
     public Result getPrivateKey(@PathVariable String appId){
-        return Result.success(appSecretService.getByAppId(appId));
+        AppSecret byAppId = null;
+        if(redisUtil.hasKey("ucenter:sign:appid:"+appId)){
+            byAppId = JSONObject.parseObject(redisUtil.get("ucenter:sign:appid:"+appId),AppSecret.class);
+        }else {
+            byAppId = appSecretService.getByAppId(appId);
+        }
+        if(!redisUtil.hasKey("ucenter:sign:appid:"+appId)){
+            redisUtil.set("ucenter:sign:appid:"+appId, JSONObject.toJSONString(byAppId),60 *60 *2);
+        }
+        return Result.success(byAppId);
     }
 }