|
@@ -94,8 +94,19 @@ public class OmgPay {
|
|
|
params.put("TimeStamp", String.valueOf(System.currentTimeMillis() / 1000L));
|
|
params.put("TimeStamp", String.valueOf(System.currentTimeMillis() / 1000L));
|
|
|
params.put("CheckMacValue", OmgCheckMacValue.generate(params, cfg.getHashKey(), cfg.getHashIv()));
|
|
params.put("CheckMacValue", OmgCheckMacValue.generate(params, cfg.getHashKey(), cfg.getHashIv()));
|
|
|
String resp = postForm(endpoint(baseUrl, URL_QUERY_TRADE_INFO), params);
|
|
String resp = postForm(endpoint(baseUrl, URL_QUERY_TRADE_INFO), params);
|
|
|
- Map<String, String> result = parseKvResponse(resp);
|
|
|
|
|
- verifyResponse(result, cfg, true);
|
|
|
|
|
|
|
+ Map<String, String> result;
|
|
|
|
|
+ try {
|
|
|
|
|
+ result = parseKvResponse(resp);
|
|
|
|
|
+ } catch (RuntimeException e) {
|
|
|
|
|
+ log.error("[OMG] queryTrade 解析响应失败 MerchantTradeNo={} resp={}", merchantTradeNo, truncate(resp, 500), e);
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ verifyResponse(result, cfg, true);
|
|
|
|
|
+ } catch (RuntimeException e) {
|
|
|
|
|
+ log.error("[OMG] queryTrade 验签失败 MerchantTradeNo={} resp={}", merchantTradeNo, truncate(resp, 500), e);
|
|
|
|
|
+ throw e;
|
|
|
|
|
+ }
|
|
|
verifyCorrelation(result, "MerchantID", cfg.getMerchantId());
|
|
verifyCorrelation(result, "MerchantID", cfg.getMerchantId());
|
|
|
verifyCorrelation(result, "MerchantTradeNo", merchantTradeNo);
|
|
verifyCorrelation(result, "MerchantTradeNo", merchantTradeNo);
|
|
|
return result;
|
|
return result;
|
|
@@ -178,6 +189,11 @@ public class OmgPay {
|
|
|
throw new IllegalArgumentException("OMG response is blank");
|
|
throw new IllegalArgumentException("OMG response is blank");
|
|
|
}
|
|
}
|
|
|
for (String pair : resp.split("&", -1)) {
|
|
for (String pair : resp.split("&", -1)) {
|
|
|
|
|
+ if (pair.isEmpty()) {
|
|
|
|
|
+ // 尾随 & 或连续 && 产生的空段是 OMG 真实响应常态,跳过;
|
|
|
|
|
+ // 空段不含 key=value,不进入 map,不影响 CheckMacValue 验签。
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
int idx = pair.indexOf('=');
|
|
int idx = pair.indexOf('=');
|
|
|
if (idx <= 0) {
|
|
if (idx <= 0) {
|
|
|
throw new IllegalArgumentException("Malformed OMG response field");
|
|
throw new IllegalArgumentException("Malformed OMG response field");
|
|
@@ -243,4 +259,12 @@ public class OmgPay {
|
|
|
throw new IllegalArgumentException(name + " is required");
|
|
throw new IllegalArgumentException(name + " is required");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /** 截断响应文本用于诊断日志(null 安全)。 */
|
|
|
|
|
+ private static String truncate(String s, int max) {
|
|
|
|
|
+ if (s == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ return s.length() <= max ? s : s.substring(0, max);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|