|  |  |  | 
|---|
|  |  |  | 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"; //小程序id | 
|---|
|  |  |  | request.appid = "wx332441ae5b12be7d"; //小程序id | 
|---|
|  |  |  | 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<>(); | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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){ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  | httpResponse.headers(), respBody); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 从HTTP应答报文构建返回数据 | 
|---|
|  |  |  | 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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)); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SerializedName("package_info") | 
|---|
|  |  |  | public String packageInfo; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SerializedName("mch_id") | 
|---|
|  |  |  | public String mchId; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SerializedName("app_id") | 
|---|
|  |  |  | public String appId; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public enum TransferBillStatus { | 
|---|