From a5f18859dc7807c16ebdd77679ab7cc232b76182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 24 Feb 2026 12:05:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(payment):=20=E4=BC=98=E5=8C=96=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 开发测试环境支持强制覆盖回调地址,便于本地联调 - 生产环境优先使用数据库中的notifyUrl配置 - 数据库未配置时才使用环境默认配置作为兜底方案 - 实现从通知URL提取基础API URL的功能 - 重构默认回调URL生成逻辑,优先使用数据库配置 - 移除重复的回调地址添加,优化地址列表构建流程 --- .../EnvironmentAwarePaymentService.java | 23 +++++++--- .../service/impl/ShopOrderServiceImpl.java | 42 +++++++++++++------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gxwebsoft/common/core/service/EnvironmentAwarePaymentService.java b/src/main/java/com/gxwebsoft/common/core/service/EnvironmentAwarePaymentService.java index 2155cc9..bf6ae24 100644 --- a/src/main/java/com/gxwebsoft/common/core/service/EnvironmentAwarePaymentService.java +++ b/src/main/java/com/gxwebsoft/common/core/service/EnvironmentAwarePaymentService.java @@ -50,15 +50,26 @@ public class EnvironmentAwarePaymentService { return null; } - // 根据环境调整回调地址 + // 开发/测试环境允许强制覆盖,方便本地联调。 + if (isDevelopmentEnvironment()) { + Payment envPayment = clonePayment(payment); + String notifyUrl = getEnvironmentNotifyUrl(); + log.info("环境感知支付配置(开发/测试) - 环境: {}, 原始回调: {}, 覆盖后回调: {}", + activeProfile, payment.getNotifyUrl(), notifyUrl); + envPayment.setNotifyUrl(notifyUrl); + return envPayment; + } + + // 生产/其它环境:优先使用数据库中的 notifyUrl(多租户域名可能不同)。 + if (payment.getNotifyUrl() != null && !payment.getNotifyUrl().trim().isEmpty()) { + return payment; + } + + // 数据库未配置时才兜底使用环境配置。 Payment envPayment = clonePayment(payment); String notifyUrl = getEnvironmentNotifyUrl(); - - log.info("环境感知支付配置 - 环境: {}, 原始回调: {}, 调整后回调: {}", - activeProfile, payment.getNotifyUrl(), notifyUrl); - + log.info("环境感知支付配置(兜底) - 环境: {}, 原始回调为空,兜底回调: {}", activeProfile, notifyUrl); envPayment.setNotifyUrl(notifyUrl); - return envPayment; } diff --git a/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java b/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java index 5a4a292..da73b60 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java @@ -133,6 +133,22 @@ public class ShopOrderServiceImpl extends ServiceImpl= 0) { + return u.substring(0, idx + "/api".length()); + } + // Fallback: treat notifyUrl itself as base. + return u; + } + private String prepaySnapshotKey(Payment payment, String outTradeNo) { return WECHAT_PREPAY_SNAPSHOT_KEY_PREFIX + payment.getMchId() + ":" + outTradeNo; } @@ -188,16 +204,21 @@ public class ShopOrderServiceImpl extends ServiceImpl