请求赔付

更新时间:2025.07.25

商户可调用该接口赔付给用户。

注:接口频率限制为100次/s

接口说明

支持商户:【平台商户】

请求方式:【POST】/v3/platsolution/ecommerce/mch-transfer/compensate-bills

请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点

     【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看

请求参数

Header  HTTP头参数

 Authorization  必填 string

请参考签名认证生成认证信息


 Accept  必填 string

请设置为application/json


 Content-Type  必填 string

请设置为application/json


body  包体参数

 receiver  必填   object

【收款方信息】 收款方信息

属性

 out_bill_no  必填   string(32)

【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一


 amount  必填   integer

【赔付金额】 金额,单位为“分”


 transfer_remark  必填   string(32)

【赔付原因】 赔付原因


 sponsor_mchid  选填   string(32)

【出资商户号】 微信支付分配的商户号。若不指定二级商户号,必须指定出资商户号字段。可指定平台服务商商户号或已经授权的运营主体商户号


 transfer_scene_id  选填   string(36)

【转账场景ID】 该笔转账使用的转账场景,可前往“商户平台-产品中心-商家转账”中申请或联系微信支付运营人员申请。


 user_recv_perception  选填   string(10)

【用户收款感知】 用户收款时感知到的收款原因将根据转账场景自动展示默认内容。如有其他展示需求,可在本字段传入。各场景展示的默认内容和支持传入的内容,可查看产品文档或联系微信支付运营人员了解。注:若指定该字段,必须同时指定转账场景ID,建议所有请求都传入转账场景ID。

请求示例

Java
Go
curl

需配合微信支付工具库 WXPayUtility 使用,请参考 Java 

1package com.java.demo;
2
3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777
4
5import com.google.gson.annotations.SerializedName;
6import com.google.gson.annotations.Expose;
7import okhttp3.MediaType;
8import okhttp3.OkHttpClient;
9import okhttp3.Request;
10import okhttp3.RequestBody;
11import okhttp3.Response;
12
13import java.io.IOException;
14import java.io.UncheckedIOException;
15import java.security.PrivateKey;
16import java.security.PublicKey;
17import java.util.ArrayList;
18import java.util.HashMap;
19import java.util.List;
20import java.util.Map;
21
22/**
23 * 请求赔付
24 */
25public class CompensationBillTransfer {
26  private static String HOST = "https://api.mch.weixin.qq.com";
27  private static String METHOD = "POST";
28  private static String PATH = "/v3/platsolution/ecommerce/mch-transfer/compensate-bills";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    CompensationBillTransfer client = new CompensationBillTransfer(
33      "19xxxxxxxx",                    // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340
34      "1DDE55AD98Exxxxxxxxxx",         // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924
35      "/path/to/apiclient_key.pem",    // 商户API证书私钥文件路径,本地文件路径
36      "PUB_KEY_ID_xxxxxxxxxxxxx",      // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589
37      "/path/to/wxp_pub.pem"           // 微信支付公钥文件路径,本地文件路径
38    );
39
40    TransferRequest request = new TransferRequest();
41    request.receiver = new ReceiverEntity();
42    request.receiver.type = ReceiverType.MERCHANT;
43    request.receiver.mchInfo = new MerchantInfo();
44    request.receiver.mchInfo.mchid = "1900001108";
45    request.outBillNo = "plfk2020042013";
46    request.amount = 10000L;
47    request.transferRemark = "直播违规扣罚";
48    request.sponsorMchid = "1900001109";
49    request.transferSceneId = "1001";
50    request.userRecvPerception = "退货运费补偿";
51    try {
52      MchTransferBillEntity response = client.run(request);
53
54      // TODO: 请求成功,继续业务逻辑
55      System.out.println(response);
56    } catch (WXPayUtility.ApiException e) {
57      // TODO: 请求失败,根据状态码执行不同的逻辑
58      e.printStackTrace();
59    }
60  }
61
62  public MchTransferBillEntity run(TransferRequest request) {
63    String uri = PATH;
64    String reqBody = WXPayUtility.toJson(request);
65
66    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
67    reqBuilder.addHeader("Accept", "application/json");
68    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
69    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody));
70    reqBuilder.addHeader("Content-Type", "application/json");
71    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody);
72    reqBuilder.method(METHOD, requestBody);
73    Request httpRequest = reqBuilder.build();
74
75    // 发送HTTP请求
76    OkHttpClient client = new OkHttpClient.Builder().build();
77    try (Response httpResponse = client.newCall(httpRequest).execute()) {
78      String respBody = WXPayUtility.extractBody(httpResponse);
79      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
80        // 2XX 成功,验证应答签名
81        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
82            httpResponse.headers(), respBody);
83
84        // 从HTTP应答报文构建返回数据
85        return WXPayUtility.fromJson(respBody, MchTransferBillEntity.class);
86      } else {
87        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
88      }
89    } catch (IOException e) {
90      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
91    }
92  }
93
94  private final String mchid;
95  private final String certificateSerialNo;
96  private final PrivateKey privateKey;
97  private final String wechatPayPublicKeyId;
98  private final PublicKey wechatPayPublicKey;
99
100  public CompensationBillTransfer(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
101    this.mchid = mchid;
102    this.certificateSerialNo = certificateSerialNo;
103    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
104    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
105    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
106  }
107
108  public static class TransferRequest {
109    @SerializedName("receiver")
110    public ReceiverEntity receiver;
111  
112    @SerializedName("out_bill_no")
113    public String outBillNo;
114  
115    @SerializedName("amount")
116    public Long amount;
117  
118    @SerializedName("transfer_remark")
119    public String transferRemark;
120  
121    @SerializedName("sponsor_mchid")
122    public String sponsorMchid;
123  
124    @SerializedName("transfer_scene_id")
125    public String transferSceneId;
126  
127    @SerializedName("user_recv_perception")
128    public String userRecvPerception;
129  }
130  
131  public static class MchTransferBillEntity {
132    @SerializedName("sp_mchid")
133    public String spMchid;
134  
135    @SerializedName("receiver_detail")
136    public ReceiverDetailInfo receiverDetail;
137  
138    @SerializedName("out_bill_no")
139    public String outBillNo;
140  
141    @SerializedName("amount")
142    public Long amount;
143  
144    @SerializedName("transfer_remark")
145    public String transferRemark;
146  
147    @SerializedName("bill_id")
148    public String billId;
149  
150    @SerializedName("state")
151    public TransferStatus state;
152  
153    @SerializedName("accept_time")
154    public String acceptTime;
155  
156    @SerializedName("success_time")
157    public String successTime;
158  
159    @SerializedName("sponsor_mchid")
160    public String sponsorMchid;
161  }
162  
163  public static class ReceiverEntity {
164    @SerializedName("type")
165    public ReceiverType type;
166  
167    @SerializedName("transaction_info")
168    public TransactionInfo transactionInfo;
169  }
170  
171  public static class ReceiverDetailInfo {
172    @SerializedName("receiver")
173    public ReceiverEntity receiver;
174  }
175  
176  public enum TransferStatus {
177    @SerializedName("ACCEPTED")
178    ACCEPTED,
179    @SerializedName("SUCCESS")
180    SUCCESS,
181    @SerializedName("CLOSED")
182    CLOSED,
183    @SerializedName("WAIT_USER_CONFIRM")
184    WAIT_USER_CONFIRM,
185    @SerializedName("CANCELING")
186    CANCELING,
187    @SerializedName("CANCELLED")
188    CANCELLED
189  }
190  
191  public enum ReceiverType {
192    @SerializedName("TRANSACTION_USER")
193    TRANSACTION_USER
194  }
195  
196  public static class TransactionInfo {
197    @SerializedName("transaction_id")
198    public String transactionId;
199  
200    @SerializedName("type")
201    public TransactionType type;
202  }
203  
204  public enum TransactionType {
205    @SerializedName("WXPAY")
206    WXPAY,
207    @SerializedName("WXVALUE")
208    WXVALUE
209  }
210  
211}
212

应答参数

200 OK

 sp_mchid  必填   string(32)

【服务商商户号】 微信支付分配的商户号


 receiver_detail  必填   object

【转账接收方信息】 转账接收方信息

属性

 out_bill_no  必填   string(32)

【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一


 amount  必填   integer

【赔付金额】 金额,单位为“分”


 transfer_remark  选填   string(32)

【赔付原因】 赔付原因


 bill_id  必填   string(64)

【微信支付转账单号】 微信支付转账单号


 state  必填   string

【赔付状态】 赔付状态

可选取值

  • ACCEPTED:  已受理

  • SUCCESS:  已成功

  • CLOSED:  系统关闭(余额不足、转账失败等原因)。

  • WAIT_USER_CONFIRM:  预下单成功,等待用户确认

  • CANCELING:  商户撤销请求受理成功,该笔付款正在撤销中

  • CANCELLED:  付款撤销完成


 accept_time  必填   string(32)

【受理时间】 受理成功时会返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE


 success_time  选填   string(32)

【成功时间】 转账成功时会返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE


 sponsor_mchid  选填   string(32)

【出资商户号】 微信支付分配的商户号

应答示例

200 OK

1{
2  "sp_mchid" : "1900001108",
3  "receiver_detail" : {
4    "receiver" : {
5      "type" : "TRANSACTION_USER",
6      "transaction_info" : {
7        "transaction_id" : "1217752501201407033233368018",
8        "type" : "WXPAY"
9      }
10    }
11  },
12  "out_bill_no" : "plfk2020042013",
13  "amount" : 10000,
14  "transfer_remark" : "直播违规扣罚",
15  "bill_id" : "1330000071100999991182020050700019480001",
16  "state" : "SUCCESS",
17  "accept_time" : "2015-05-20T13:29:35+08:00",
18  "success_time" : "2015-05-20T13:29:35+08:00",
19  "sponsor_mchid" : "1900001109"
20}
21

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

请根据错误提示正确传入参数

400

INVALID_REQUEST

HTTP 请求不符合微信支付 APIv3 接口规则

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

 

更多技术问题
技术咨询
反馈
咨询
目录
置顶