|
|
@@ -139,74 +139,72 @@ public class OpenApiVerifyService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if (isSuccess && !map.containsKey("AppId")) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "没有AppId信息";
|
|
|
+ }
|
|
|
+ String appId = map.get("AppId");
|
|
|
+ OpenApiSignInfo signInfo = openApiSignInfoDao.findTopByAppId(appId);
|
|
|
+ if (isSuccess && ObjectUtils.isEmpty(signInfo)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "AppId错误";
|
|
|
+ }
|
|
|
+ if (isSuccess && (signInfo.getAppState() == null || signInfo.getAppState() != AppState.Enable)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "AppId未启用";
|
|
|
+ }
|
|
|
+ if (isSuccess && !map.containsKey("Timestamp")) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "没有Timestamp信息";
|
|
|
+ }
|
|
|
+ String timestamp = map.get("Timestamp");
|
|
|
+ if (isSuccess && (StringUtils.isEmpty(timestamp) || timestamp.length() != 14)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "Timestamp格式错误";
|
|
|
+ }
|
|
|
+
|
|
|
if (isSuccess) {
|
|
|
- OpenApiSignInfo signInfo = null;
|
|
|
- if (isSuccess && !map.containsKey("AppId")) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "没有AppId信息";
|
|
|
- }
|
|
|
- String appId = map.get("AppId");
|
|
|
- signInfo = openApiSignInfoDao.findTopByAppId(appId);
|
|
|
- if (isSuccess && ObjectUtils.isEmpty(signInfo)) {
|
|
|
+ Long time = DateUtils.timeToLong(timestamp, DateUtils.unionAuth);
|
|
|
+ if (time == null || Math.abs(time - System.currentTimeMillis()) > OpenAPIConfig.timeBetween) {
|
|
|
isSuccess = false;
|
|
|
- msg = "AppId错误";
|
|
|
- }
|
|
|
- if (isSuccess && (signInfo.getAppState() == null || signInfo.getAppState() != AppState.Enable)) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "AppId未启用";
|
|
|
- }
|
|
|
- if (isSuccess && !map.containsKey("Timestamp")) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "没有Timestamp信息";
|
|
|
- }
|
|
|
- String timestamp = map.get("Timestamp");
|
|
|
- if (isSuccess && (StringUtils.isEmpty(timestamp) || timestamp.length() != 14)) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "Timestamp格式错误";
|
|
|
- }
|
|
|
-
|
|
|
- if (isSuccess) {
|
|
|
- Long time = DateUtils.timeToLong(timestamp, DateUtils.unionAuth);
|
|
|
- if (time == null || Math.abs(time - System.currentTimeMillis()) > OpenAPIConfig.timeBetween) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "Timestamp不符合要求";
|
|
|
- }
|
|
|
+ msg = "Timestamp不符合要求";
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (isSuccess && !map.containsKey("Nonce")) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "没有Nonce信息";
|
|
|
- }
|
|
|
- String nonce = map.get("Nonce");
|
|
|
- if (isSuccess && (StringUtils.isEmpty(nonce) || nonce.length() > 50)) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "Nonce为空或长度不符合要求";
|
|
|
- }
|
|
|
- if (isSuccess && !map.containsKey("Signature")) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "没有Signature信息";
|
|
|
- }
|
|
|
- String signature = map.get("Signature");
|
|
|
- if (isSuccess && (StringUtils.isEmpty(signature) || signature.length() > 200)) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "Signature为空或长度不符合要求";
|
|
|
- }
|
|
|
+ if (isSuccess && !map.containsKey("Nonce")) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "没有Nonce信息";
|
|
|
+ }
|
|
|
+ String nonce = map.get("Nonce");
|
|
|
+ if (isSuccess && (StringUtils.isEmpty(nonce) || nonce.length() > 50)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "Nonce为空或长度不符合要求";
|
|
|
+ }
|
|
|
+ if (isSuccess && !map.containsKey("Signature")) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "没有Signature信息";
|
|
|
+ }
|
|
|
+ String signature = map.get("Signature");
|
|
|
+ if (isSuccess && (StringUtils.isEmpty(signature) || signature.length() > 200)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "Signature为空或长度不符合要求";
|
|
|
+ }
|
|
|
|
|
|
- if (isSuccess) {
|
|
|
- String sign = AesUtils.signData(requestStr);
|
|
|
- log.info("数据sign {}", sign);
|
|
|
- String appKey = signInfo.getAppKey();
|
|
|
- String c = String.format("%s%s%s%s", appId, timestamp, nonce, sign);
|
|
|
- String tempSignature = AesUtils.signMacSHA256(c, appKey);
|
|
|
- log.info("系统tempSignature {}", tempSignature);
|
|
|
- log.info("传入signature {}", signature);
|
|
|
+ if (isSuccess) {
|
|
|
+ String sign = AesUtils.signData(requestStr);
|
|
|
+ log.info("数据sign {}", sign);
|
|
|
+ String appKey = signInfo.getAppKey();
|
|
|
+ String c = String.format("%s%s%s%s", appId, timestamp, nonce, sign);
|
|
|
+ String tempSignature = AesUtils.signMacSHA256(c, appKey);
|
|
|
+ log.info("系统tempSignature {}", tempSignature);
|
|
|
+ log.info("传入signature {}", signature);
|
|
|
|
|
|
- if (!tempSignature.equals(signature)) {
|
|
|
- isSuccess = false;
|
|
|
- msg = "Signature认证错误";
|
|
|
- }
|
|
|
+ if (!tempSignature.equals(signature)) {
|
|
|
+ isSuccess = false;
|
|
|
+ msg = "Signature认证错误";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
} else {
|
|
|
msg = "报文头没有OPEN-BODY-SIG标记";
|
|
|
}
|