|
@ -47,6 +47,11 @@ public class OpenApiRequestCheckAspect { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
private EpmetCommonServiceOpenFeignClient commonServiceOpenFeignClient; |
|
|
|
|
|
|
|
|
|
|
|
//请求时差单位:s
|
|
|
|
|
|
long requestTimeSecDiff = 120; |
|
|
|
|
|
//请求时差,单位:ms
|
|
|
|
|
|
long requestTimeMillSecDiff = requestTimeSecDiff * 1000;//单位:ms
|
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(DataFilterAspect.class); |
|
|
private static final Logger log = LoggerFactory.getLogger(DataFilterAspect.class); |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -117,10 +122,10 @@ public class OpenApiRequestCheckAspect { |
|
|
} |
|
|
} |
|
|
long timestamp = Long.valueOf(timestampStr).longValue(); |
|
|
long timestamp = Long.valueOf(timestampStr).longValue(); |
|
|
long now = System.currentTimeMillis(); |
|
|
long now = System.currentTimeMillis(); |
|
|
long requestTimeDiff = 120000; |
|
|
|
|
|
if (Math.abs(now - timestamp) > requestTimeDiff) { |
|
|
if (Math.abs(now - timestamp) > requestTimeMillSecDiff) { |
|
|
// 只允许1分钟之内的请求,允许服务器之间时差为1分钟
|
|
|
// 只允许1分钟之内的请求,允许服务器之间时差为1分钟
|
|
|
throw new RenException(String.format("请求已过时,允许时差为%s ms", requestTimeDiff)); |
|
|
throw new RenException(String.format("请求已过时,允许时差为%s s", requestTimeSecDiff)); |
|
|
} |
|
|
} |
|
|
String nonce = argMap.get(RequestParamKeys.NONCE); |
|
|
String nonce = argMap.get(RequestParamKeys.NONCE); |
|
|
String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); |
|
|
String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); |
|
@ -128,7 +133,7 @@ public class OpenApiRequestCheckAspect { |
|
|
throw new RenException("请求重复"); |
|
|
throw new RenException("请求重复"); |
|
|
} |
|
|
} |
|
|
//将nonce缓存到redis,有效期1分钟
|
|
|
//将nonce缓存到redis,有效期1分钟
|
|
|
redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeDiff); |
|
|
redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|