From 2ab42edae9d271f5f464b7be475e217752dacb38 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期三, 22 四月 2026 09:24:47 +0800
Subject: [PATCH] 代码生成

---
 server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java |   65 +++++++++++++++-----------------
 1 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java b/server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java
index d386941..9666dc4 100644
--- a/server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java
+++ b/server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java
@@ -8,19 +8,20 @@
 import com.github.binarywang.wxpay.constant.WxPayConstants;
 import com.github.binarywang.wxpay.service.WxPayService;
 import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
-import com.wechat.pay.java.core.Config;
 import com.wechat.pay.java.core.RSAAutoCertificateConfig;
-import com.wechat.pay.java.core.RSAPublicKeyConfig;
 import com.wechat.pay.java.core.notification.NotificationParser;
-import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig;
 import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
 import com.wechat.pay.java.service.refund.RefundService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.util.StreamUtils;
 
 import javax.annotation.PostConstruct;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 
 /**
  * 寰俊灏忕▼搴忕粍浠�
@@ -50,7 +51,7 @@
     @PostConstruct
     void init() {
         this.load_WxMaService();
-        this.load_wxPayService();
+//        this.load_wxPayService();
         this.load_wxPayV3Service();
 //        this.load_wxAppPayService();
     }
@@ -70,48 +71,44 @@
     /**
      * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯 V2
      */
-    public void load_wxPayService() {
-        WxPayConfig payConfig = new WxPayConfig();
-        payConfig.setTradeType(WxPayConstants.TradeType.JSAPI);
-        payConfig.setSignType(WxPayConstants.SignType.MD5);
-        payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getAppId()));
-        payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId()));
-        payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getMchKey()));
-        payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath()));
-        payConfig.setNotifyUrl(StringUtils.trimToNull(wxPayProperties.getNotifyUrl()));
-        WxPayService wxPayService = new WxPayServiceImpl();
-        wxPayService.setConfig(payConfig);
-        this.wxPayService = wxPayService;
-    }
+//    public void load_wxPayService() {
+//        WxPayConfig payConfig = new WxPayConfig();
+//        payConfig.setTradeType(WxPayConstants.TradeType.JSAPI);
+//        payConfig.setSignType(WxPayConstants.SignType.MD5);
+//        payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getAppId()));
+//        payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId()));
+//        payConfig.setMchKey(StringUtils.trimToNull(wxPayProperties.getMchKey()));
+//        payConfig.setKeyPath(StringUtils.trimToNull(wxPayProperties.getKeyPath()));
+//        payConfig.setNotifyUrl(StringUtils.trimToNull(wxPayProperties.getNotifyUrl()));
+//        WxPayService wxPayService = new WxPayServiceImpl();
+//        wxPayService.setConfig(payConfig);
+//        this.wxPayService = wxPayService;
+//    }
 
     /**
      * 鍒濆鍖栧井淇℃敮浠� V3锛圝SAPI + 閫�娆� + 鍥炶皟楠岀锛�
+     * 浣跨敤骞冲彴璇佷功妯″紡锛堣嚜鍔ㄤ笅杞藉拰绠$悊寰俊骞冲彴璇佷功锛�
      */
     public void load_wxPayV3Service() {
         try {
-            Config config =
-                    new RSAPublicKeyConfig.Builder()
-                            .merchantId(wxPayProperties.getMchId()) //寰俊鏀粯鐨勫晢鎴峰彿
-                            .privateKeyFromPath(wxPayProperties.getPrivateKeyPath()) // 鍟嗘埛API璇佷功绉侀挜鐨勫瓨鏀捐矾寰�
-                            .merchantSerialNumber(wxPayProperties.getSerialNumer()) //鍟嗘埛API璇佷功搴忓垪鍙�
-                            .publicKeyFromPath(wxPayProperties.getPubKeyPath()) //寰俊鏀粯鍏挜鐨勫瓨鏀捐矾寰�
-                            .publicKeyId(wxPayProperties.getPublicKeyId()) //寰俊鏀粯鍏挜ID
-                            .apiV3Key(wxPayProperties.getApiV3Key()) //APIv3瀵嗛挜
-                            .build();
+            // 浠� classpath 璇诲彇鍟嗘埛绉侀挜
+            ClassPathResource keyResource = new ClassPathResource(StringUtils.trimToNull(wxPayProperties.getPrivateKeyPath()));
+            InputStream keyStream = keyResource.getInputStream();
+            String privateKey = StreamUtils.copyToString(keyStream, StandardCharsets.UTF_8);
+            keyStream.close();
 
-
-            // 鏀粯鍏挜閰嶇疆锛堢敤浜庡洖璋冮獙绛撅級
-            RSAPublicKeyNotificationConfig notifyConfig = new RSAPublicKeyNotificationConfig.Builder()
-                    .publicKeyFromPath(wxPayProperties.getPubKeyPath())
-                    .publicKeyId(wxPayProperties.getPublicKeyId())
-                    .apiV3Key(wxPayProperties.getApiV3Key())
+            RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
+                    .merchantId(StringUtils.trimToNull(wxPayProperties.getMchId()))
+                    .privateKey(privateKey)
+                    .merchantSerialNumber(StringUtils.trimToNull(wxPayProperties.getSerialNumer()))
+                    .apiV3Key(StringUtils.trimToNull(wxPayProperties.getApiV3Key()))
                     .build();
 
             v3JsapiService = new JsapiServiceExtension.Builder().config(config).build();
             v3RefundService = new RefundService.Builder().config(config).build();
-            v3NotificationParser = new NotificationParser(notifyConfig);
+            v3NotificationParser = new NotificationParser(config);
 
-            log.info("寰俊鏀粯V3鍒濆鍖栨垚鍔�");
+            log.info("寰俊鏀粯V3鍒濆鍖栨垚鍔燂紙骞冲彴璇佷功妯″紡锛�");
         } catch (Exception e) {
             log.error("寰俊鏀粯V3鍒濆鍖栧け璐�: {}", e.getMessage(), e);
         }

--
Gitblit v1.9.3