From 57820a35da231c93472a04b28338bd155fe06260 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, 29 Jul 2025 13:23:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=EF=BC=8C=E5=85=BC=E5=AE=B9=E5=85=AC=E9=92=A5=E6=A8=A1?= =?UTF-8?q?=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ShopOrderServiceImpl.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) 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 803fc70..60341d1 100644 --- a/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java +++ b/src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java @@ -366,7 +366,7 @@ import com.gxwebsoft.common.core.service.PaymentCacheService; } // 构建微信支付配置 - Config config; + Config config = null; if (active.equals("dev")) { // 开发环境使用自动证书配置 // 检查数据库配置是否完整 @@ -393,10 +393,6 @@ import com.gxwebsoft.common.core.service.PaymentCacheService; if (payment.getPubKey() != null && !payment.getPubKey().isEmpty() && payment.getPubKeyId() != null && !payment.getPubKeyId().isEmpty()) { - System.out.println("=== 检测到公钥配置,使用RSA公钥模式 ==="); - System.out.println("公钥文件: " + payment.getPubKey()); - System.out.println("公钥ID: " + payment.getPubKeyId()); - try { // 开发环境固定使用 wechatpay_public_key.pem String tenantCertPath = "dev/wechat/" + order.getTenantId(); @@ -404,7 +400,12 @@ import com.gxwebsoft.common.core.service.PaymentCacheService; System.out.println("开发环境公钥文件路径: " + pubKeyPath); + // 检查公钥文件是否存在 if (certificateLoader.certificateExists(pubKeyPath)) { + System.out.println("=== 检测到公钥配置,使用RSA公钥模式 ==="); + System.out.println("公钥文件: " + payment.getPubKey()); + System.out.println("公钥ID: " + payment.getPubKeyId()); + String pubKeyFile = certificateLoader.loadCertificatePath(pubKeyPath); System.out.println("✅ 开发环境公钥文件加载成功: " + pubKeyFile); @@ -418,15 +419,17 @@ import com.gxwebsoft.common.core.service.PaymentCacheService; .build(); System.out.println("✅ 开发环境RSA公钥配置成功"); } else { - System.err.println("❌ 公钥文件不存在: " + pubKeyPath); - throw new RuntimeException("公钥文件不存在: " + pubKeyPath); + System.out.println("⚠️ 开发环境公钥文件不存在,跳过公钥模式: " + pubKeyPath); + // 跳过公钥配置,继续后续的自动证书配置 } - } catch (Exception pubKeyException) { - System.err.println("❌ RSA公钥配置失败: " + pubKeyException.getMessage()); - pubKeyException.printStackTrace(); - throw new RuntimeException("RSA公钥配置失败: " + pubKeyException.getMessage(), pubKeyException); + } catch (Exception e) { + System.err.println("❌ 开发环境公钥配置检查失败: " + e.getMessage()); + // 跳过公钥配置,继续后续的自动证书配置 } - } else { + } + + // 如果没有公钥配置或公钥文件不存在,尝试自动证书配置 + if (config == null) { // 没有公钥配置,尝试自动证书配置 try { System.out.println("=== 尝试创建自动证书配置 ===");