From 82f707ece09a906007f3d760b6bb025896e3bba6 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 22 四月 2026 15:39:36 +0800
Subject: [PATCH] 门店

---
 server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java |  186 ++++++++++++++++++----------------------------
 1 files changed, 72 insertions(+), 114 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 e9edac5..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
@@ -3,43 +3,44 @@
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
 import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
-import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.config.mybatis.SpringUtils;
-import com.doumee.core.constants.Constants;
 import com.github.binarywang.wxpay.config.WxPayConfig;
 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.http.HostName;
-import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig;
-import com.wechat.pay.java.service.billdownload.BillDownloadService;
-import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService;
-import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiServiceExtension;
+import com.wechat.pay.java.core.notification.NotificationParser;
+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;
 
 /**
  * 寰俊灏忕▼搴忕粍浠�
  */
+@Slf4j
 @Configuration
 public class WxMiniConfig {
     /********寰俊灏忕▼搴忔湇鍔�**********/
     public static WxMaService wxMaService;
-    /********寰俊灏忕▼搴忔敮浠�**********/
-    public static JsapiService wxPayService;
-//    public static WxPayService wxPayV2Service;
-    public static RefundService refundService;
-    public static JsapiServiceExtension jsapiExtService;
-    public static BillDownloadService billDownloadService;
-    public static WxPayProperties wxProperties;
-    public static  TransferToUser transferToUser;
+    /********寰俊灏忕▼搴忔敮浠� V2**********/
+    public static WxPayService wxPayService;
+    /********寰俊APP鏀粯**********/
+    public static WxPayService wxAppPayService;
+
+    /********寰俊鏀粯 V3**********/
+    public static JsapiServiceExtension v3JsapiService;
+    public static RefundService v3RefundService;
+    public static NotificationParser v3NotificationParser;
+
     @Autowired
     private WxPayProperties wxPayProperties;
 
@@ -50,127 +51,84 @@
     @PostConstruct
     void init() {
         this.load_WxMaService();
-        this.load_wxPayService();
-//        this.load_wxPayV2Service();
-        this.load_transferToUser();
-        this.wxProperties = wxPayProperties;
+//        this.load_wxPayService();
+        this.load_wxPayV3Service();
+//        this.load_wxAppPayService();
     }
     /**
      * 鍒濆鍖栧井淇″皬绋嬪簭
      */
     public void load_WxMaService() {
         WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
-        if(wxPayProperties.getExistsSub() ==1){
-            //濡傛灉鏄湇鍔″晢鏀粯,鍙栧瓙鍟嗘埛淇℃伅
-            config.setAppid(StringUtils.trimToNull(wxPayProperties.getSubAppId()));
-            config.setSecret(StringUtils.trimToNull(wxPayProperties.getSubAppSecret()));
-        }else {
-//            config.setAppid(StringUtils.trimToNull(wxPayProperties.getAppId()));
-//            config.setSecret(StringUtils.trimToNull(wxPayProperties.getAppSecret()));
-        }
+        config.setAppid(StringUtils.trimToNull(wxPayProperties.getAppId()));
+        config.setSecret(StringUtils.trimToNull(wxPayProperties.getAppSecret()));
         config.setMsgDataFormat("JSON");
-        //config.setToken("");
-        //config.setAesKey("");
         WxMaService wxMaService = new WxMaServiceImpl();
         wxMaService.setWxMaConfig(config);
         this.wxMaService = wxMaService;
     }
 
     /**
-     * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯
-     */
-    public void load_wxPayService()   {
-        try {
-            Config config =
-                    new RSAPublicKeyConfig.Builder()
-                            .merchantId(wxPayProperties.getMchId())
-                            .privateKeyFromPath(wxPayProperties.getPrivateKeyPath())
-                            .publicKeyFromPath(wxPayProperties.getPubKeyPath())
-                            .publicKeyId(wxPayProperties.getPayPublicKeyId())
-                            .merchantSerialNumber(wxPayProperties.getSerialNumer())
-                            .apiV3Key(wxPayProperties.getApiV3Key())
-                            .build();
-
-
-//            Config config =
-//                    new RSAAutoCertificateConfig.Builder()
-//                            .merchantId(wxPayProperties.getMchId())
-//                            .privateKeyFromPath(wxPayProperties.getPrivateKeyPath())
-////                            .publicKeyFromPath(wxPayProperties.getPubKeyPath())
-////                            .publicKeyId("PUB_KEY_ID_0117000719222024112700219100000508")
-//                            .merchantSerialNumber(wxPayProperties.getSerialNumer())
-//                            .apiV3Key(wxPayProperties.getApiV3Key())
-//                            .build();
-//            this.wxPayService =  new JsapiService.Builder().config(config).build();
-
-            this.jsapiExtService =  new JsapiServiceExtension.Builder().config(config).build();
-            this.refundService = new RefundService.Builder().config(config).build();
-            this.billDownloadService = new BillDownloadService.Builder().config(config).build();
-        }catch (Exception e){
-            e.printStackTrace();
-
-        }
-    }
-
-    /**
-     * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯
-     */
-//    public void load_wxPayV2Service()
-//    {
-//        WxPayConfig payConfig = new WxPayConfig();
-//        payConfig.setTradeType(WxPayConstants.TradeType.JSAPI);
-//        payConfig.setSignType(WxPayConstants.SignType.MD5);
-//        payConfig.setAppId(StringUtils.trimToNull(wxPayProperties.getAppId()));
-//        payConfig.setSubAppId(StringUtils.trimToNull(wxPayProperties.getSubAppId()));
-//        payConfig.setMchId(StringUtils.trimToNull(wxPayProperties.getMchId()));
-//        payConfig.setSubMchId(StringUtils.trimToNull(wxPayProperties.getSubMchId()));
-//        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.wxPayV2Service = wxPayService;
-//    }
-
-
-    /**
-     * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯
+     * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯 V2
      */
 //    public void load_wxPayService() {
 //        WxPayConfig payConfig = new WxPayConfig();
 //        payConfig.setTradeType(WxPayConstants.TradeType.JSAPI);
 //        payConfig.setSignType(WxPayConstants.SignType.MD5);
-//        payConfig.setAppId(StringUtils.trimToNull(sysDictService.getSysDictValue(SysDictEnum.WX_MINI_AppID.getCode())));
+//        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 {
+            // 浠� classpath 璇诲彇鍟嗘埛绉侀挜
+            ClassPathResource keyResource = new ClassPathResource(StringUtils.trimToNull(wxPayProperties.getPrivateKeyPath()));
+            InputStream keyStream = keyResource.getInputStream();
+            String privateKey = StreamUtils.copyToString(keyStream, StandardCharsets.UTF_8);
+            keyStream.close();
+
+            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(config);
+
+            log.info("寰俊鏀粯V3鍒濆鍖栨垚鍔燂紙骞冲彴璇佷功妯″紡锛�");
+        } catch (Exception e) {
+            log.error("寰俊鏀粯V3鍒濆鍖栧け璐�: {}", e.getMessage(), e);
+        }
+    }
+
+//    /**
+//     * 鍒濆鍖朅pp鏀粯
+//     */
+//    public void load_wxAppPayService() {
+//        WxPayConfig payConfig = new WxPayConfig();
+//        payConfig.setTradeType(WxPayConstants.TradeType.APP);
+//        payConfig.setSignType(WxPayConstants.SignType.MD5);
+//        payConfig.setAppId("");
 //        payConfig.setMchId(StringUtils.trimToNull(sysDictService.getSysDictValue(SysDictEnum.WX_MINI_MchId.getCode())));
 //        payConfig.setMchKey(StringUtils.trimToNull(sysDictService.getSysDictValue(SysDictEnum.WX_MINI_MchKey.getCode())));
 //        payConfig.setKeyPath(StringUtils.trimToNull(sysDictService.getSysDictValue(SysDictEnum.WX_MINI_KeyPath.getCode())));
 //        payConfig.setNotifyUrl(StringUtils.trimToNull(sysDictService.getSysDictValue(SysDictEnum.WX_MINI_NotifyUrl.getCode())));
 //        WxPayService wxPayService = new WxPayServiceImpl();
 //        wxPayService.setConfig(payConfig);
-//        this.wxPayService = wxPayService;
+//        this.wxAppPayService = wxPayService;
 //    }
-
-
-    //杞处涓氬姟
-    public void load_transferToUser()
-    {
-        TransferToUser transferToUser = new TransferToUser(
-                StringUtils.trimToNull(wxPayProperties.getSubMchId()), //鍟嗘埛id
-                StringUtils.trimToNull(wxPayProperties.getWechatSerialNumer()), //鍟嗘埛API璇佷功搴忓垪鍙凤紝濡備綍鑾峰彇璇峰弬鑰� https://pay.weixin.qq.com/doc/v3/merchant/4013053053
-                StringUtils.trimToNull(wxPayProperties.getWechatPrivateKeyPath()), // 鍟嗘埛API璇佷功绉侀挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰�
-                StringUtils.trimToNull(wxPayProperties.getWechatPayPublicKeyId()),   // 寰俊鏀粯鍏挜ID锛屽浣曡幏鍙栬鍙傝�� https://pay.weixin.qq.com/doc/v3/merchant/4013038816
-                StringUtils.trimToNull(wxPayProperties.getWechatPubKeyPath()) // 寰俊鏀粯鍏挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰�
-        );
-
-//        TransferToUser client = new TransferToUser(
-//                "1229817002",                    // 鍟嗘埛鍙凤紝鏄敱寰俊鏀粯绯荤粺鐢熸垚骞跺垎閰嶇粰姣忎釜鍟嗘埛鐨勫敮涓�鏍囪瘑绗︼紝鍟嗘埛鍙疯幏鍙栨柟寮忓弬鑰� https://pay.weixin.qq.com/doc/v3/merchant/4013070756
-//                "3FE90C2F3D40A56E1C51926F31B8A8D22426CCE0",         // 鍟嗘埛API璇佷功搴忓垪鍙凤紝濡備綍鑾峰彇璇峰弬鑰� https://pay.weixin.qq.com/doc/v3/merchant/4013053053
-//                "d://wechatApiclient_key.pem",    // 鍟嗘埛API璇佷功绉侀挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰�
-//                "PUB_KEY_ID_0112298170022025071700291836000600",      // 寰俊鏀粯鍏挜ID锛屽浣曡幏鍙栬鍙傝�� https://pay.weixin.qq.com/doc/v3/merchant/4013038816
-//                "d://pub_key.pem"          // 寰俊鏀粯鍏挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰�
-//        );
-        this.transferToUser = transferToUser;
-    }
-
 
 }

--
Gitblit v1.9.3