MrShi
2025-08-22 278da88f21bff29eef96a2e439ac35eb444630fe
server/services/src/main/java/com/doumee/config/wx/TransferToUser.java
@@ -27,6 +27,14 @@
    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(
@@ -38,18 +46,18 @@
//        );
        TransferToUser client = new TransferToUser(
                "1661772003",                    // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756
                "3C9A32FB6CD453FAAAF97F9737ECAEA9D6625727",         // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053
                "d://wechatApiclient_key.pem",    // 商户API证书私钥文件路径,本地文件路径
                "47E172124E73E8098A565E971064C20ACDE7C911",      // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816
                "d://wechatpay_47E172124E73E8098A565E971064C20ACDE7C911.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.openid = "oFucG7Nu5teWNIZiWkAINfAE4glE";
//        request.userName = client.encrypt("施旭辉");
        request.transferAmount = 10L;
        request.transferRemark = "~~~";
@@ -83,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;
@@ -126,7 +127,7 @@
    public TransferToUserResponse run(TransferToUserRequest request,String name) {
        String uri = PATH;
        request.appid = WxMiniConfig.wxProperties.getSubAppId();
//        request.notifyUrl = WxMiniConfig.wxProperties.getWechatNotifyUrl();
        request.notifyUrl = WxMiniConfig.wxProperties.getWechatNotifyUrl();
        request.transferSceneId = "1005";
        request.userRecvPerception = "劳务报酬";
        if(request.transferAmount >= 30){
@@ -170,7 +171,10 @@
                        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());
            }
@@ -236,6 +240,12 @@
        @SerializedName("package_info")
        public String packageInfo;
        @SerializedName("mch_id")
        public String mchId;
        @SerializedName("app_id")
        public String appId;
    }
    public enum TransferBillStatus {