diff --git a/docs/rental/topup-payment.md b/docs/rental/topup-payment.md index 63aed19..267a152 100644 --- a/docs/rental/topup-payment.md +++ b/docs/rental/topup-payment.md @@ -82,6 +82,8 @@ RENT_PAYMENT_MAINNET_MAX_AMOUNT=10000.00 默认 INFO 级别即可看到充值阶段日志,不需要打开全局 DEBUG。搜索 `充值创建失败` 或 `充值核对失败`,按 `diagnosticId`、`topupNo` 或 `orderId` 关联同一次处理。 +启动及创建充值时会输出「充值配置诊断」「充值开关来源」「充值配置层级检查」。`boundEnabled/boundChannelEnabled` 是配置对象实际绑定值;`resolved` 是当前Spring环境解析值;`source` 列出配置来源(按优先级排列),可发现命令行、系统属性、环境变量或外部YAML覆盖。`ABSENT` 表示未找到配置,`NON_BOOLEAN` 表示值不是true/false,`RESOLUTION_FAILED` 表示占位符解析失败。同时输出激活profile与进程实例标识,方便核对是否重启了正确实例。只检查已知开关,其他环境变量和凭证不会输出。总开关和网络开关现分别返回明确错误提示。 + - `CHANNEL_CONFIG`:检查该网络启用状态及凭证是否配置,日志只记录布尔值。 - `PUBLIC_KEY_LOAD`:公钥文件读取或 RSA 解析失败;`fileResource=false` 时检查是否遗漏 `file:` 前缀。 - `LOCAL_ORDER_TRANSACTION`:账户检查、本地充值表查询或插入失败。 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPaymentProperties.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPaymentProperties.java index 2a19336..ff1fa3d 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPaymentProperties.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPaymentProperties.java @@ -8,6 +8,55 @@ import org.springframework.stereotype.Component; @Component @ConfigurationProperties(prefix = "rental.payment") public class RentalPaymentProperties { + private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(RentalPaymentProperties.class); + @org.springframework.beans.factory.annotation.Autowired + private org.springframework.core.env.ConfigurableEnvironment environment; + + /** 启动后输出实际绑定结果;不打印配置对象、URL、密钥或进程环境全集。 */ + @javax.annotation.PostConstruct + public void logStartupConfiguration() { + logConfiguration("STARTUP", "NILE"); + logConfiguration("STARTUP", "MAINNET"); + } + + /** 每次创建前再次记录,区分部署实例、配置文件缺失和高优先级覆盖。 */ + public void logConfiguration(String diagnosticId, String network) { + Channel selected = channel(network); + LOG.info("充值配置诊断 diagnosticId={} network={} boundEnabled={} boundChannelEnabled={} activeProfiles={} defaultProfiles={} instance={}", + diagnosticId, network, enabled, selected != null && selected.isEnabled(), + environment == null ? "unavailable" : java.util.Arrays.toString(environment.getActiveProfiles()), + environment == null ? "unavailable" : java.util.Arrays.toString(environment.getDefaultProfiles()), + java.lang.management.ManagementFactory.getRuntimeMXBean().getName()); + if (environment == null) { return; } + logSwitch(diagnosticId, "rental.enabled"); + logSwitch(diagnosticId, "rental.payment.enabled"); + logSwitch(diagnosticId, "rental.payment." + network.toLowerCase(java.util.Locale.ROOT) + ".enabled"); + logSwitch(diagnosticId, "RENT_PAYMENT_ENABLED"); + logSwitch(diagnosticId, "RENT_PAYMENT_" + network + "_ENABLED"); + // 常见错误层级仅报告是否存在,帮助发现把payment误写到根级的情况。 + LOG.info("充值配置层级检查 diagnosticId={} expectedPrefix=rental.payment legacyRootPaymentEnabledPresent={} legacyRootNetworkEnabledPresent={}", + diagnosticId, environment.containsProperty("payment.enabled"), + environment.containsProperty("payment." + network.toLowerCase(java.util.Locale.ROOT) + ".enabled")); + } + + private void logSwitch(String diagnosticId, String key) { + String value; + try { + String resolved = environment.getProperty(key); + value = resolved == null ? "ABSENT" : "true".equalsIgnoreCase(resolved.trim()) ? "TRUE" + : "false".equalsIgnoreCase(resolved.trim()) ? "FALSE" : "NON_BOOLEAN"; + } catch (RuntimeException exception) { value = "RESOLUTION_FAILED"; } + boolean found = false; + // 按Spring优先级排列;首项为优先候选。只记录来源名称,不输出原始占位符值。 + for (org.springframework.core.env.PropertySource source : environment.getPropertySources()) { + if (source.containsProperty(key)) { + LOG.info("充值开关来源 diagnosticId={} key={} resolved={} source={} firstCandidate={}", + diagnosticId, key, value, source.getName().replaceAll("[\\r\\n]", "_"), !found); + found = true; + } + } + if (!found) { LOG.info("充值开关来源 diagnosticId={} key={} resolved={} source=ABSENT", diagnosticId, key, value); } + } private boolean enabled; private int connectTimeoutMs = 5000; private int readTimeoutMs = 15000; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTopups.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTopups.java index b844909..6c42770 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTopups.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTopups.java @@ -46,12 +46,14 @@ public class RentalTopups { require(value.signum() > 0 && value.stripTrailingZeros().scale() <= 2, "充值金额必须为正数且最多两位小数"); RentalPaymentProperties.Channel channel = config.channel(network); stage = "CHANNEL_CONFIG"; + config.logConfiguration(diagnosticId, network); LOG.info("充值通道检查 diagnosticId={} network={} enabled={} channelEnabled={} apiKeyConfigured={} apiSecretConfigured={} publicKeyConfigured={}", diagnosticId, network, config.isEnabled(), channel.isEnabled(), channel.getApiKey() != null && !channel.getApiKey().isEmpty(), channel.getApiSecret() != null && !channel.getApiSecret().isEmpty(), channel.getRsaPublicKeyLocation() != null && !channel.getRsaPublicKeyLocation().isEmpty()); - require(config.isEnabled() && channel.isEnabled(), "该网络暂未启用在线充值"); + require(config.isEnabled(), "在线充值总开关未启用,请检查rental.payment.enabled实际绑定值"); + require(channel.isEnabled(), network + "充值通道未启用,请检查rental.payment." + network.toLowerCase(Locale.ROOT) + ".enabled实际绑定值"); require(value.compareTo(channel.getMinAmount()) >= 0 && value.compareTo(channel.getMaxAmount()) <= 0, "充值金额超出通道允许范围"); URI base = URI.create(channel.getBaseUrl());