添加调试日志
This commit is contained in:
1 parent
36e3b046a0
commit
beb7f6de8a
3 files changed
+43
-3
No files matched your search
@@ -103,6 +103,7 @@ RENT_PAYMENT_MAINNET_TLS_CERTIFICATE=file:/etc/nginx/certs/fullchain.pem
|
||||
- `LOCAL_ORDER_TRANSACTION`:账户检查、本地充值表查询或插入失败。
|
||||
- `PAYMENT_RECONCILE`:补偿租约申请等失败,包括旧表缺少 `lease_token` 字段。
|
||||
- `PAYMENT_CREATE` / `PAYMENT_QUERY`:支付连接、TLS、认证、解析失败;结合支付 HTTP 状态和 businessCode 检查。
|
||||
若定位到支付响应校验,搜索「充值支付业务失败」:包含HTTP状态、businessCode、dataType、safeMessage及响应字符数。safeMessage只允许项目已知固定错误,未知消息显示UNKNOWN_MESSAGE_REDACTED,避免响应中的SQL或认证信息进入日志。JSON解析失败单独输出安全异常位置,不输出响应正文。
|
||||
- `PAYMENT_CREATE_RESPONSE_VALIDATE`:支付返回单号、金额、地址、有效期或收银台地址不符合要求。
|
||||
- `CHAIN_VERIFY` / `LEDGER_CREDIT`:链上核验或账务事务失败。
|
||||
|
||||
|
||||
@@ -84,15 +84,46 @@ public class RentalPaymentClient {
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
LOG.info("充值支付HTTP响应 topupNo={} operation={} httpStatus={} elapsedMs={}",
|
||||
text(order, "topup_no"), operation, response.code(), TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - started));
|
||||
Map<String, Object> result = json.readValue(RentalHttp.body(response), new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
String body = RentalHttp.body(response);
|
||||
Map<String, Object> result;
|
||||
try {
|
||||
result = json.readValue(body, new TypeReference<Map<String, Object>>() { });
|
||||
} catch (Exception exception) {
|
||||
LOG.warn("充值支付JSON解析失败 topupNo={} operation={} responseChars={} diagnostic={}",
|
||||
text(order, "topup_no"), operation, body.length(), RentalDiagnostics.describe(exception));
|
||||
throw exception;
|
||||
}
|
||||
require(result != null, "支付返回JSON为空");
|
||||
LOG.info("充值支付业务响应 topupNo={} operation={} businessCode={} dataObject={}",
|
||||
text(order, "topup_no"), operation, number(result, "code"), result.get("data") instanceof Map);
|
||||
require(number(result, "code") == 200 && result.get("data") instanceof Map, "支付请求未成功,请稍后核对");
|
||||
if (number(result, "code") != 200 || !(result.get("data") instanceof Map)) {
|
||||
String safeMessage = safeBusinessMessage(result.get("msg"));
|
||||
LOG.warn("充值支付业务失败 topupNo={} operation={} httpStatus={} businessCode={} dataType={} safeMessage={} responseChars={}",
|
||||
text(order, "topup_no"), operation, response.code(), number(result, "code"),
|
||||
result.get("data") == null ? "null" : result.get("data").getClass().getSimpleName(), safeMessage, body.length());
|
||||
throw new IllegalArgumentException("支付请求未成功,请稍后核对");
|
||||
}
|
||||
return (Map<String, Object>) result.get("data");
|
||||
}
|
||||
}
|
||||
|
||||
/** 仅输出已知固定业务错误;未知响应可能包含SQL、凭证或认证材料,不能直接打印。 */
|
||||
static String safeBusinessMessage(Object value) {
|
||||
if (!(value instanceof String)) { return "MISSING_MESSAGE"; }
|
||||
String message = (String) value;
|
||||
java.util.List<String> allowed = java.util.Arrays.asList(
|
||||
"请求已过期", "API 凭证无效", "请求认证失败", "请求 nonce 已使用", "请求解密或认证失败",
|
||||
"加密请求字段不完整", "加密请求字段长度超限", "不支持的金额币种", "支付网络无效",
|
||||
"商户应用不可用", "商户订单号已存在", "同一支付单号参数不一致",
|
||||
"该收款地址和金额已有待支付订单,请稍后重试", "订单创建失败,请重试",
|
||||
"暂无可用钱包地址,请联系平台管理员补充子账号", "钱包分配失败,请重试",
|
||||
"业务参数格式错误", "业务参数不能重复", "业务参数不完整或包含不支持的参数",
|
||||
"order_id 长度不能超过 32", "walletUserName 格式错误", "notify_url 格式错误",
|
||||
"notify_url 长度不能超过 128", "amount 必须为正数且最多保留 4 位小数", "amount 格式错误",
|
||||
"USDT 兑换汇率配置无效", "路径不存在,请检查路径是否正确", "没有权限,请联系管理员授权");
|
||||
return allowed.contains(message) ? message : "UNKNOWN_MESSAGE_REDACTED";
|
||||
}
|
||||
|
||||
/**
|
||||
* RSA验签使用项目既有参数规范化规则,不使用租赁HMAC或浏览器跳转结果。
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,14 @@ import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
/** 隔离MySQL兼容DDL与真实事务测试;支付和链上适配器可控,不访问真实账户或广播。 */
|
||||
public class RentalTopupTest {
|
||||
@Test public void businessFailureLogsOnlyKnownFixedMessages() {
|
||||
assertEquals("暂无可用钱包地址,请联系平台管理员补充子账号",
|
||||
RentalPaymentClient.safeBusinessMessage("暂无可用钱包地址,请联系平台管理员补充子账号"));
|
||||
assertEquals("API 凭证无效", RentalPaymentClient.safeBusinessMessage("API 凭证无效"));
|
||||
assertEquals("UNKNOWN_MESSAGE_REDACTED", RentalPaymentClient.safeBusinessMessage("SQL with api_secret=secret"));
|
||||
assertEquals("UNKNOWN_MESSAGE_REDACTED", RentalPaymentClient.safeBusinessMessage("API 凭证无效\nsecret"));
|
||||
assertEquals("MISSING_MESSAGE", RentalPaymentClient.safeBusinessMessage(null));
|
||||
}
|
||||
@Test public void diagnosticSummaryIncludesCauseAndLocationWithoutSensitiveMessages() {
|
||||
Exception failure = new Exception("secret-top-level", new java.sql.SQLException("secret-sql-parameters", "42S22", 1054));
|
||||
String diagnostic = RentalDiagnostics.describe(failure);
|
||||
|
||||
Reference in new issue
Block a user