|
@@ -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();
|
|
|
}
|
|
|
|