Browse Source

修改:openApi验签部分,修改返回提示

dev_shibei_match
wxz 4 years ago
parent
commit
e27fbc3c1a
  1. 5
      epmet-commons/epmet-commons-security/src/main/java/com/epmet/commons/security/sign/openapi/OpenApiSignUtils.java
  2. 4
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/exception/EpmetErrorCode.java
  3. 5
      epmet-module/epmet-ext/epmet-ext-server/src/main/java/com/epmet/aspect/OpenApiRequestCheckAspect.java

5
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); System.out.println("随机数:" + uuid);
HashMap<String, String> content = new HashMap<>(); HashMap<String, String> content = new HashMap<>();
content.put("orgId", "aaa"); //content.put("orgId", "aaa");
content.put("test", null); //content.put("test", null);
content.put("gridId", "12128e0f614f1c00a058ea9a107033b2");
content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0"); content.put("app_id", "7d98b8af2d05752b4225709c4cfd4bd0");
content.put("timestamp", String.valueOf(now)); content.put("timestamp", String.valueOf(now));
content.put("nonce", uuid); content.put("nonce", uuid);

4
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_TOKEN_EXPIRED(10102, "Token过期"),
OPEN_API_PARAMS_MISSING(10103, "参数不完整"), OPEN_API_PARAMS_MISSING(10103, "参数不完整"),
OPEN_API_SIGN_ERROR(10104, "签名错误"), 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 int code;
private String msg; private String msg;

5
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) { if (Math.abs(now - timestamp) > requestTimeMillSecDiff) {
// 只允许1分钟之内的请求,允许服务器之间时差为1分钟 // 只允许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 nonce = argMap.get(RequestParamKeys.NONCE);
String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce)); String nonceInCache = redisUtils.getString(RedisKeys.getOpenApiNonceKey(nonce));
if (StringUtils.isNotBlank(nonceInCache)) { if (StringUtils.isNotBlank(nonceInCache)) {
throw new RenException("请求重复"); throw new RenException(EpmetErrorCode.OPEN_API_REQUEST_REPEAT.getCode());
} }
//将nonce缓存到redis,有效期1分钟 //将nonce缓存到redis,有效期1分钟
redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff); redisUtils.set(RedisKeys.getOpenApiNonceKey(nonce), System.currentTimeMillis(), requestTimeSecDiff);

Loading…
Cancel
Save