赔付商家
更新时间:2025.12.04商户可调用该接口从运营账户赔付给二级商户。
注:接口频率限制为50次/s
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/platsolution/ecommerce/mch-transfer/sub-mch-compensation-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
【赔付商户信息】 赔付商户信息描述
| 属性 | |||||
type 必填 string 【赔付接收方类型】 赔付接收方类型 可选取值
mch_info 必填 object 【赔付接收方商户信息】 赔付接收方商户信息
|
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一
amount 必填 integer
【赔付金额】 金额,单位为“分”
transfer_remark 必填 string(32)
【赔付备注】 备注,在资金账单中展示
sponsor_mchid 选填 string(32)
【出资商户号】 可指定平台服务商商户号或已经授权的运营主体商户号。若未填写,则默认使用平台服务商商户号出资
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/platsolution/ecommerce/mch-transfer/sub-mch-compensation-bills \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "receiver" : { 8 "type" : "MERCHANT", 9 "mch_info" : { 10 "mchid" : "1900001108" 11 } 12 }, 13 "out_bill_no" : "plfk2020042013", 14 "amount" : 10000, 15 "transfer_remark" : "赔付金发放", 16 "sponsor_mchid" : "1900001109" 17 }' 18
需配合微信支付工具库 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 SubMchCompensationBillTransfer { 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/sub-mch-compensation-bills"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 SubMchCompensationBillTransfer client = new SubMchCompensationBillTransfer( 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 try { 50 MchTransferBillEntity response = client.run(request); 51 // TODO: 请求成功,继续业务逻辑 52 System.out.println(response); 53 } catch (WXPayUtility.ApiException e) { 54 // TODO: 请求失败,根据状态码执行不同的逻辑 55 e.printStackTrace(); 56 } 57 } 58 59 public MchTransferBillEntity run(TransferRequest request) { 60 String uri = PATH; 61 String reqBody = WXPayUtility.toJson(request); 62 63 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 64 reqBuilder.addHeader("Accept", "application/json"); 65 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 66 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 67 reqBuilder.addHeader("Content-Type", "application/json"); 68 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 69 reqBuilder.method(METHOD, requestBody); 70 Request httpRequest = reqBuilder.build(); 71 72 // 发送HTTP请求 73 OkHttpClient client = new OkHttpClient.Builder().build(); 74 try (Response httpResponse = client.newCall(httpRequest).execute()) { 75 String respBody = WXPayUtility.extractBody(httpResponse); 76 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 77 // 2XX 成功,验证应答签名 78 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 79 httpResponse.headers(), respBody); 80 81 // 从HTTP应答报文构建返回数据 82 return WXPayUtility.fromJson(respBody, MchTransferBillEntity.class); 83 } else { 84 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 85 } 86 } catch (IOException e) { 87 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 88 } 89 } 90 91 private final String mchid; 92 private final String certificateSerialNo; 93 private final PrivateKey privateKey; 94 private final String wechatPayPublicKeyId; 95 private final PublicKey wechatPayPublicKey; 96 97 public SubMchCompensationBillTransfer(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 98 this.mchid = mchid; 99 this.certificateSerialNo = certificateSerialNo; 100 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 101 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 102 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 103 } 104 105 public static class TransferRequest { 106 @SerializedName("receiver") 107 public ReceiverEntity receiver; 108 109 @SerializedName("out_bill_no") 110 public String outBillNo; 111 112 @SerializedName("amount") 113 public Long amount; 114 115 @SerializedName("transfer_remark") 116 public String transferRemark; 117 118 @SerializedName("sponsor_mchid") 119 public String sponsorMchid; 120 } 121 122 public static class MchTransferBillEntity { 123 @SerializedName("sp_mchid") 124 public String spMchid; 125 126 @SerializedName("receiver_detail") 127 public ReceiverDetailInfo receiverDetail; 128 129 @SerializedName("out_bill_no") 130 public String outBillNo; 131 132 @SerializedName("amount") 133 public Long amount; 134 135 @SerializedName("transfer_remark") 136 public String transferRemark; 137 138 @SerializedName("bill_id") 139 public String billId; 140 141 @SerializedName("state") 142 public TransferStatus state; 143 144 @SerializedName("accept_time") 145 public String acceptTime; 146 147 @SerializedName("success_time") 148 public String successTime; 149 150 @SerializedName("sponsor_mchid") 151 public String sponsorMchid; 152 } 153 154 public static class ReceiverEntity { 155 @SerializedName("type") 156 public ReceiverType type; 157 158 @SerializedName("mch_info") 159 public MerchantInfo mchInfo; 160 } 161 162 public static class ReceiverDetailInfo { 163 @SerializedName("receiver") 164 public ReceiverEntity receiver; 165 } 166 167 public enum TransferStatus { 168 @SerializedName("ACCEPTED") 169 ACCEPTED, 170 @SerializedName("SUCCESS") 171 SUCCESS, 172 @SerializedName("CLOSED") 173 CLOSED 174 } 175 176 public enum ReceiverType { 177 @SerializedName("MERCHANT") 178 MERCHANT 179 } 180 181 public static class MerchantInfo { 182 @SerializedName("mchid") 183 public String mchid; 184 } 185 186} 187
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &TransferRequest{ 28 Receiver: &ReceiverEntity{ 29 Type: RECEIVERTYPE_MERCHANT.Ptr(), 30 MchInfo: &MerchantInfo{ 31 Mchid: wxpay_utility.String("1900001108"), 32 }, 33 }, 34 OutBillNo: wxpay_utility.String("plfk2020042013"), 35 Amount: wxpay_utility.Int64(10000), 36 TransferRemark: wxpay_utility.String("直播违规扣罚"), 37 SponsorMchid: wxpay_utility.String("1900001109"), 38 } 39 40 response, err := SubMchCompensationBillTransfer(config, request) 41 if err != nil { 42 fmt.Printf("请求失败: %+v\n", err) 43 // TODO: 请求失败,根据状态码执行不同的处理 44 return 45 } 46 47 // TODO: 请求成功,继续业务逻辑 48 fmt.Printf("请求成功: %+v\n", response) 49} 50 51func SubMchCompensationBillTransfer(config *wxpay_utility.MchConfig, request *TransferRequest) (response *MchTransferBillEntity, err error) { 52 const ( 53 host = "https://api.mch.weixin.qq.com" 54 method = "POST" 55 path = "/v3/platsolution/ecommerce/mch-transfer/sub-mch-compensation-bills" 56 ) 57 58 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 59 if err != nil { 60 return nil, err 61 } 62 reqBody, err := json.Marshal(request) 63 if err != nil { 64 return nil, err 65 } 66 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 67 if err != nil { 68 return nil, err 69 } 70 httpRequest.Header.Set("Accept", "application/json") 71 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 72 httpRequest.Header.Set("Content-Type", "application/json") 73 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 74 if err != nil { 75 return nil, err 76 } 77 httpRequest.Header.Set("Authorization", authorization) 78 79 client := &http.Client{} 80 httpResponse, err := client.Do(httpRequest) 81 if err != nil { 82 return nil, err 83 } 84 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 85 if err != nil { 86 return nil, err 87 } 88 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 89 // 2XX 成功,验证应答签名 90 err = wxpay_utility.ValidateResponse( 91 config.WechatPayPublicKeyId(), 92 config.WechatPayPublicKey(), 93 &httpResponse.Header, 94 respBody, 95 ) 96 if err != nil { 97 return nil, err 98 } 99 response := &MchTransferBillEntity{} 100 if err := json.Unmarshal(respBody, response); err != nil { 101 return nil, err 102 } 103 104 return response, nil 105 } else { 106 return nil, wxpay_utility.NewApiException( 107 httpResponse.StatusCode, 108 httpResponse.Header, 109 respBody, 110 ) 111 } 112} 113 114type TransferRequest struct { 115 Receiver *ReceiverEntity `json:"receiver,omitempty"` 116 OutBillNo *string `json:"out_bill_no,omitempty"` 117 Amount *int64 `json:"amount,omitempty"` 118 TransferRemark *string `json:"transfer_remark,omitempty"` 119 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 120} 121 122type MchTransferBillEntity struct { 123 SpMchid *string `json:"sp_mchid,omitempty"` 124 ReceiverDetail *ReceiverDetailInfo `json:"receiver_detail,omitempty"` 125 OutBillNo *string `json:"out_bill_no,omitempty"` 126 Amount *int64 `json:"amount,omitempty"` 127 TransferRemark *string `json:"transfer_remark,omitempty"` 128 BillId *string `json:"bill_id,omitempty"` 129 State *TransferStatus `json:"state,omitempty"` 130 AcceptTime *time.Time `json:"accept_time,omitempty"` 131 SuccessTime *time.Time `json:"success_time,omitempty"` 132 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 133} 134 135type ReceiverEntity struct { 136 Type *ReceiverType `json:"type,omitempty"` 137 MchInfo *MerchantInfo `json:"mch_info,omitempty"` 138} 139 140type ReceiverDetailInfo struct { 141 Receiver *ReceiverEntity `json:"receiver,omitempty"` 142} 143 144type TransferStatus string 145 146func (e TransferStatus) Ptr() *TransferStatus { 147 return &e 148} 149 150const ( 151 TRANSFERSTATUS_ACCEPTED TransferStatus = "ACCEPTED" 152 TRANSFERSTATUS_SUCCESS TransferStatus = "SUCCESS" 153 TRANSFERSTATUS_CLOSED TransferStatus = "CLOSED" 154) 155 156type ReceiverType string 157 158func (e ReceiverType) Ptr() *ReceiverType { 159 return &e 160} 161 162const ( 163 RECEIVERTYPE_MERCHANT ReceiverType = "MERCHANT" 164) 165 166type MerchantInfo struct { 167 Mchid *string `json:"mchid,omitempty"` 168} 169
应答参数
200 OK
sp_mchid 必填 string(32)
【服务商商户号】 微信支付分配的商户号
receiver_detail 必填 object
【赔付接收方信息】 赔付接收方信息
| 属性 | |||||||||
receiver 必填 object 【赔付接收者信息】 赔付接收者信息
|
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一
amount 必填 integer
【赔付金额】 金额,单位为“分”
transfer_remark 必填 string(32)
【赔付备注】 备注,在资金账单中展示
bill_id 必填 string(64)
【微信支付赔付单号】 微信支付赔付单号
state 必填 string
【赔付状态】 赔付状态
可选取值
ACCEPTED: 已受理SUCCESS: 已成功CLOSED: 系统关闭(余额不足、转账失败等原因)。
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" : "MERCHANT", 6 "mch_info" : { 7 "mchid" : "1900001108" 8 } 9 } 10 }, 11 "out_bill_no" : "plfk2020042013", 12 "amount" : 10000, 13 "transfer_remark" : "赔付金发放", 14 "bill_id" : "1330000071100999991182020050700019480001", 15 "state" : "SUCCESS", 16 "accept_time" : "2015-05-20T13:29:35+08:00", 17 "success_time" : "2015-05-20T13:29:35+08:00", 18 "sponsor_mchid" : "1900001109" 19} 20
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

