From e27fbc3c1ab1337bb0e4b3d272c297f502797a21 Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 13 Apr 2021 13:48:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9AopenApi=E9=AA=8C?= =?UTF-8?q?=E7=AD=BE=E9=83=A8=E5=88=86=EF=BC=8C=E4=BF=AE=E6=94=B9=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commons/security/sign/openapi/OpenApiSignUtils.java | 5 +++-- .../com/epmet/commons/tools/exception/EpmetErrorCode.java | 4 +++- .../java/com/epmet/aspect/OpenApiRequestCheckAspect.java | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java index 8551289868..1de1b04f73 100644 --- a/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java +++ b/epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java @@ -93,8 +93,9 @@ public class OpenApiSignUtils { System.out.println("随机数:" + uuid); HashMap content = new HashMap<>(); - content.put("orgId", "aaa"); - content.put("test", null); + //content.put("orgId", "aaa"); + //content.put("test", null); + content.put("gridId", "12128e0f614f1c00a058ea9a107033b2"); content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); content.put("timestamp", String.valueOf(now)); content.put("nonce", uuid); diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java index 26834d4458..5673b272f1 100644 --- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java +++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java @@ -156,7 +156,9 @@ public enum EpmetErrorCode { OPEN_API_TOKEN_EXPIRED(10102, "Token过期"), OPEN_API_PARAMS_MISSING(10103, "参数不完整"), OPEN_API_SIGN_ERROR(10104, "签名错误"), - OPEN_API_PARAMS_APPID_DIFF(10105, "app_id不一致"); // app_id在请求参数中和在token中不一致 + OPEN_API_PARAMS_APPID_DIFF(10105, "app_id不一致"), // app_id在请求参数中和在token中不一致 + OPEN_API_REQUEST_EXPIRED(10106, "请求过期"), + OPEN_API_REQUEST_REPEAT(10107, "请求重复"); private int code; private String msg; diff --git a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java index 6661ac747d..c6f23cc779 100644 --- a/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java +++ b/epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java @@ -125,12 +125,13 @@ public class OpenApiRequestCheckAspect { if (Math.abs(now - timestamp) > requestTimeMillSecDiff) { // 只允许1分钟之内的请求,允许服务器之间时差为1分钟 - throw new RenException(String.format("请求已过时,允许时差为%s s", requestTimeSecDiff)); + throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_EXPIRED.getCode(), + String.format("请求已过期,允许时差为%s s", requestTimeSecDiff)); } String nonce = argMap.get(RequestParamKeys.NONCE); String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); if (StringUtils.isNotBlank(nonceInCache)) { - throw new RenException("请求重复"); + throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_REPEAT.getCode()); } //将nonce缓存到redis,有效期1分钟 redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff);