From bd6229ebd9cb543a22944ecb1142fad92b675dce Mon Sep 17 00:00:00 2001 From: rk <94314517@qq.com> Date: 星期一, 13 十月 2025 14:26:25 +0800 Subject: [PATCH] bug 修复 --- server/services/src/main/java/com/doumee/config/wx/WxMiniConfig.java | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 106 insertions(+), 6 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 f93edef..e9edac5 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 @@ -10,6 +10,15 @@ 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.service.refund.RefundService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; @@ -21,12 +30,18 @@ */ @Configuration public class WxMiniConfig { - @Autowired - private SystemDictDataBiz systemDictDataBiz; /********寰俊灏忕▼搴忔湇鍔�**********/ public static WxMaService wxMaService; /********寰俊灏忕▼搴忔敮浠�**********/ - public static WxPayService wxPayService; + 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; + @Autowired + private WxPayProperties wxPayProperties; public static WxMiniConfig me() { return SpringUtils.get().getBean(WxMiniConfig.class); @@ -35,15 +50,24 @@ @PostConstruct void init() { this.load_WxMaService(); -// this.load_wxPayService(); + this.load_wxPayService(); +// this.load_wxPayV2Service(); + this.load_transferToUser(); + this.wxProperties = wxPayProperties; } /** * 鍒濆鍖栧井淇″皬绋嬪簭 */ public void load_WxMaService() { WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); - config.setAppid(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.APPID).getCode())); - config.setSecret(StringUtils.trimToNull(systemDictDataBiz.queryByCode(Constants.WX_CONFIG,Constants.SECRET).getCode())); + 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.setMsgDataFormat("JSON"); //config.setToken(""); //config.setAesKey(""); @@ -51,6 +75,63 @@ 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; +// } + /** * 鍒濆鍖栧井淇″皬绋嬪簭鏀粯 @@ -70,7 +151,26 @@ // } + //杞处涓氬姟 + 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