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/TransferToUser.java | 59 +++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 39 insertions(+), 20 deletions(-) diff --git a/server/services/src/main/java/com/doumee/config/wx/TransferToUser.java b/server/services/src/main/java/com/doumee/config/wx/TransferToUser.java index af0b96e..3e50307 100644 --- a/server/services/src/main/java/com/doumee/config/wx/TransferToUser.java +++ b/server/services/src/main/java/com/doumee/config/wx/TransferToUser.java @@ -27,25 +27,41 @@ private static String CANCEL_PATH = "/v3/fund-app/mch-transfer/transfer-bills/out-bill-no/{out_bill_no}/cancel"; + public TransferToUser(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { + this.mchid = mchid; + this.certificateSerialNo = certificateSerialNo; + this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); + this.wechatPayPublicKeyId = wechatPayPublicKeyId; + this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); + } + public static void main(String[] args) { // TODO: 璇峰噯澶囧晢鎴峰紑鍙戝繀瑕佸弬鏁帮紝鍙傝�冿細https://pay.weixin.qq.com/doc/v3/merchant/4013070756 +// 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" // 寰俊鏀粯鍏挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰� +// ); + 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" // 寰俊鏀粯鍏挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰� + "1723326069", // 鍟嗘埛鍙凤紝鏄敱寰俊鏀粯绯荤粺鐢熸垚骞跺垎閰嶇粰姣忎釜鍟嗘埛鐨勫敮涓�鏍囪瘑绗︼紝鍟嗘埛鍙疯幏鍙栨柟寮忓弬鑰� https://pay.weixin.qq.com/doc/v3/merchant/4013070756 + "12C0F0DD0F3D2B565B45586D3FEA225EBF723BEC", // 鍟嗘埛API璇佷功搴忓垪鍙凤紝濡備綍鑾峰彇璇峰弬鑰� https://pay.weixin.qq.com/doc/v3/merchant/4013053053 + "d://jinkuai/shanghu/apiclient_key.pem", // 鍟嗘埛API璇佷功绉侀挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰� + "PUB_KEY_ID_0117233260692025072500181939000603", // 寰俊鏀粯鍏挜ID锛屽浣曡幏鍙栬鍙傝�� https://pay.weixin.qq.com/doc/v3/merchant/4013038816 + "d://jinkuai/shanghu/pub_key.pem" // 寰俊鏀粯鍏挜鏂囦欢璺緞锛屾湰鍦版枃浠惰矾寰� ); TransferToUserRequest request = new TransferToUserRequest(); - request.appid = "wxcd2b89fd2ff065f8"; //灏忕▼搴廼d + request.appid = "wx332441ae5b12be7d"; //灏忕▼搴廼d request.outBillNo = "plfk2020042016"; request.transferSceneId = "1005"; - request.openid = "oKKHU5IFKpss_DIbFX1lqghFJOEg"; - request.userName = client.encrypt("鏂芥棴杈�"); - request.transferAmount = 91L; + request.openid = "oFucG7Nu5teWNIZiWkAINfAE4glE"; +// request.userName = client.encrypt("鏂芥棴杈�"); + request.transferAmount = 10L; request.transferRemark = "~~~"; - request.notifyUrl = "https://www.weixin.qq.com/wxpay/pay.php"; +// request.notifyUrl = "https://www.weixin.qq.com/wxpay/pay.php"; request.userRecvPerception = "鍔冲姟鎶ラ叕"; request.transferSceneReportInfos = new ArrayList<>(); { @@ -75,13 +91,6 @@ private final String wechatPayPublicKeyId; private final PublicKey wechatPayPublicKey; - public TransferToUser(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { - this.mchid = mchid; - this.certificateSerialNo = certificateSerialNo; - this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); - this.wechatPayPublicKeyId = wechatPayPublicKeyId; - this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); - } public TransferToUserResponse testRun(TransferToUserRequest request) { String uri = PATH; @@ -118,6 +127,7 @@ public TransferToUserResponse run(TransferToUserRequest request,String name) { String uri = PATH; request.appid = WxMiniConfig.wxProperties.getSubAppId(); + request.notifyUrl = WxMiniConfig.wxProperties.getWechatNotifyUrl(); request.transferSceneId = "1005"; request.userRecvPerception = "鍔冲姟鎶ラ叕"; if(request.transferAmount >= 30){ @@ -140,7 +150,7 @@ Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); reqBuilder.addHeader("Accept", "application/json"); reqBuilder.addHeader("Wechatpay-Serial", WxMiniConfig.wxProperties.getWechatPayPublicKeyId()); - reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(WxMiniConfig.wxProperties.getMchId(), + reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(WxMiniConfig.wxProperties.getSubMchId(), WxMiniConfig.wxProperties.getWechatSerialNumer(), WXPayUtility.loadPrivateKeyFromPath(WxMiniConfig.wxProperties.getWechatPrivateKeyPath()), METHOD, uri, reqBody)); @@ -161,7 +171,10 @@ httpResponse.headers(), respBody); // 浠嶩TTP搴旂瓟鎶ユ枃鏋勫缓杩斿洖鏁版嵁 - return WXPayUtility.fromJson(respBody, TransferToUserResponse.class); + TransferToUser.TransferToUserResponse response = WXPayUtility.fromJson(respBody, TransferToUserResponse.class); + response.appId = request.appid; + response.mchId = WxMiniConfig.wxProperties.getSubMchId(); + return response; } else { throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); } @@ -178,7 +191,7 @@ Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); reqBuilder.addHeader("Accept", "application/json"); reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); - reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(WxMiniConfig.wxProperties.getMchId(), + reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(WxMiniConfig.wxProperties.getSubMchId(), WxMiniConfig.wxProperties.getWechatSerialNumer(), WXPayUtility.loadPrivateKeyFromPath(WxMiniConfig.wxProperties.getWechatPrivateKeyPath()), METHOD, uri, null)); @@ -227,6 +240,12 @@ @SerializedName("package_info") public String packageInfo; + + @SerializedName("mch_id") + public String mchId; + + @SerializedName("app_id") + public String appId; } public enum TransferBillStatus { -- Gitblit v1.9.3