请求赔付预下单
更新时间:2025.07.25商户可调用该接口进行赔付预下单,并锁定商户资金。若赔付订单状态已经为终态(成功或关闭),接口将返回错误码。
在预下单成功后,商户需携带接口返回的跳转参数,引导用户至微信内进行确认,用户确认后执行赔付。若预下单后超过24小时没有赔付成功,系统将自动关闭订单。
订单赔付成功或者关闭时,系统将通过接口指定的商户回调地址通知赔付结果。
注:接口频率限制为100次/s
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/platsolution/ecommerce/mch-transfer/compensate-bills/pre-transfer
请求域名:【主域名】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 包体参数
sp_appid 选填 string(32)
【公众账号ID】 微信分配的公众账号ID
receiver 必填 object
【收款方信息】 收款方信息
属性 | |||||
type 选填 string 【转账接收方类型】 转账接收方类型 可选取值
transaction_info 选填 object 【转账接收方订单信息】 转账接收方订单信息,当接收方类型为TRANSACTION_USER时,需要设置。
|
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一
amount 必填 integer
【金额】 金额,单位为“分”
transfer_remark 必填 string(32)
【赔付原因】 赔付原因
sponsor_mchid 选填 string(32)
【出资商户号】 微信支付分配的商户号。若不指定二级商户号,必须指定出资商户号字段。可指定平台服务商商户号或已经授权的运营主体商户号
user_recv_perception 选填 string(10)
【用户收款感知】 用户收款时感知到的收款原因将根据转账场景自动展示默认内容。如有其他展示需求,可在本字段传入。各场景展示的默认内容和支持传入的内容,可查看产品文档或联系微信支付运营人员了解。注:若指定该字段,必须同时指定转账场景ID,建议所有请求都传入转账场景ID。
notify_url 选填 string(256)
【商户回调地址】 异步接收微信支付转账结果通知的回调地址,通知URL必须为公网可访问的URL,必须为HTTPS,不能携带参数。
请求示例
需配合微信支付工具库 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 CompensationBillPreTransfer { 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/pre-transfer"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CompensationBillPreTransfer client = new CompensationBillPreTransfer( 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.spAppid = "wx8888888888888888"; 42 request.receiver = new ReceiverEntity(); 43 request.receiver.type = ReceiverType.MERCHANT; 44 request.receiver.mchInfo = new MerchantInfo(); 45 request.receiver.mchInfo.mchid = "1900001108"; 46 request.outBillNo = "plfk2020042013"; 47 request.amount = 10000L; 48 request.transferRemark = "直播违规扣罚"; 49 request.sponsorMchid = "1900001109"; 50 request.userRecvPerception = "退货运费补偿"; 51 request.notifyUrl = "https://www.weixin.qq.com/wxpay/pay.php"; 52 try { 53 PreTransferResponse response = client.run(request); 54 55 // TODO: 请求成功,继续业务逻辑 56 System.out.println(response); 57 } catch (WXPayUtility.ApiException e) { 58 // TODO: 请求失败,根据状态码执行不同的逻辑 59 e.printStackTrace(); 60 } 61 } 62 63 public PreTransferResponse run(TransferRequest request) { 64 String uri = PATH; 65 String reqBody = WXPayUtility.toJson(request); 66 67 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 68 reqBuilder.addHeader("Accept", "application/json"); 69 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 70 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 71 reqBuilder.addHeader("Content-Type", "application/json"); 72 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 73 reqBuilder.method(METHOD, requestBody); 74 Request httpRequest = reqBuilder.build(); 75 76 // 发送HTTP请求 77 OkHttpClient client = new OkHttpClient.Builder().build(); 78 try (Response httpResponse = client.newCall(httpRequest).execute()) { 79 String respBody = WXPayUtility.extractBody(httpResponse); 80 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 81 // 2XX 成功,验证应答签名 82 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 83 httpResponse.headers(), respBody); 84 85 // 从HTTP应答报文构建返回数据 86 return WXPayUtility.fromJson(respBody, PreTransferResponse.class); 87 } else { 88 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 89 } 90 } catch (IOException e) { 91 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 92 } 93 } 94 95 private final String mchid; 96 private final String certificateSerialNo; 97 private final PrivateKey privateKey; 98 private final String wechatPayPublicKeyId; 99 private final PublicKey wechatPayPublicKey; 100 101 public CompensationBillPreTransfer(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 102 this.mchid = mchid; 103 this.certificateSerialNo = certificateSerialNo; 104 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 105 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 106 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 107 } 108 109 public static class TransferRequest { 110 @SerializedName("sp_appid") 111 public String spAppid; 112 113 @SerializedName("receiver") 114 public ReceiverEntity receiver; 115 116 @SerializedName("out_bill_no") 117 public String outBillNo; 118 119 @SerializedName("amount") 120 public Long amount; 121 122 @SerializedName("transfer_remark") 123 public String transferRemark; 124 125 @SerializedName("sponsor_mchid") 126 public String sponsorMchid; 127 128 @SerializedName("user_recv_perception") 129 public String userRecvPerception; 130 131 @SerializedName("notify_url") 132 public String notifyUrl; 133 } 134 135 public static class PreTransferResponse { 136 @SerializedName("out_bill_no") 137 public String outBillNo; 138 139 @SerializedName("bill_id") 140 public String billId; 141 142 @SerializedName("accept_time") 143 public String acceptTime; 144 145 @SerializedName("package_info") 146 public String packageInfo; 147 } 148 149 public static class ReceiverEntity { 150 @SerializedName("type") 151 public ReceiverType type; 152 153 @SerializedName("transaction_info") 154 public TransactionInfo transactionInfo; 155 } 156 157 public enum ReceiverType { 158 @SerializedName("TRANSACTION_USER") 159 TRANSACTION_USER 160 } 161 162 public static class TransactionInfo { 163 @SerializedName("transaction_id") 164 public String transactionId; 165 166 @SerializedName("type") 167 public TransactionType type; 168 } 169 170 public enum TransactionType { 171 @SerializedName("WXPAY") 172 WXPAY, 173 @SerializedName("WXVALUE") 174 WXVALUE 175 } 176 177} 178
需配合微信支付工具库 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 SpAppid: wxpay_utility.String("wx8888888888888888"), 29 Receiver: &ReceiverEntity{ 30 Type: RECEIVERTYPE_MERCHANT.Ptr(), 31 MchInfo: &MerchantInfo{ 32 Mchid: wxpay_utility.String("1900001108"), 33 }, 34 }, 35 OutBillNo: wxpay_utility.String("plfk2020042013"), 36 Amount: wxpay_utility.Int64(10000), 37 TransferRemark: wxpay_utility.String("直播违规扣罚"), 38 SponsorMchid: wxpay_utility.String("1900001109"), 39 UserRecvPerception: wxpay_utility.String("退货运费补偿"), 40 NotifyUrl: wxpay_utility.String("https://www.weixin.qq.com/wxpay/pay.php"), 41 } 42 43 response, err := CompensationBillPreTransfer(config, request) 44 if err != nil { 45 fmt.Printf("请求失败: %+v\n", err) 46 // TODO: 请求失败,根据状态码执行不同的处理 47 return 48 } 49 50 // TODO: 请求成功,继续业务逻辑 51 fmt.Printf("请求成功: %+v\n", response) 52} 53 54func CompensationBillPreTransfer(config *wxpay_utility.MchConfig, request *TransferRequest) (response *PreTransferResponse, err error) { 55 const ( 56 host = "https://api.mch.weixin.qq.com" 57 method = "POST" 58 path = "/v3/platsolution/ecommerce/mch-transfer/compensate-bills/pre-transfer" 59 ) 60 61 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 62 if err != nil { 63 return nil, err 64 } 65 reqBody, err := json.Marshal(request) 66 if err != nil { 67 return nil, err 68 } 69 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 70 if err != nil { 71 return nil, err 72 } 73 httpRequest.Header.Set("Accept", "application/json") 74 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 75 httpRequest.Header.Set("Content-Type", "application/json") 76 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 77 if err != nil { 78 return nil, err 79 } 80 httpRequest.Header.Set("Authorization", authorization) 81 82 client := &http.Client{} 83 httpResponse, err := client.Do(httpRequest) 84 if err != nil { 85 return nil, err 86 } 87 88 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 89 if err != nil { 90 return nil, err 91 } 92 93 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 94 // 2XX 成功,验证应答签名 95 err = wxpay_utility.ValidateResponse( 96 config.WechatPayPublicKeyId(), 97 config.WechatPayPublicKey(), 98 &httpResponse.Header, 99 respBody, 100 ) 101 if err != nil { 102 return nil, err 103 } 104 105 if err := json.Unmarshal(respBody, response); err != nil { 106 return nil, err 107 } 108 109 return response, nil 110 } else { 111 return nil, wxpay_utility.NewApiException( 112 httpResponse.StatusCode, 113 httpResponse.Header, 114 respBody, 115 ) 116 } 117} 118 119type TransferRequest struct { 120 SpAppid *string `json:"sp_appid,omitempty"` 121 Receiver *ReceiverEntity `json:"receiver,omitempty"` 122 OutBillNo *string `json:"out_bill_no,omitempty"` 123 Amount *int64 `json:"amount,omitempty"` 124 TransferRemark *string `json:"transfer_remark,omitempty"` 125 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 126 UserRecvPerception *string `json:"user_recv_perception,omitempty"` 127 NotifyUrl *string `json:"notify_url,omitempty"` 128} 129 130type PreTransferResponse struct { 131 OutBillNo *string `json:"out_bill_no,omitempty"` 132 BillId *string `json:"bill_id,omitempty"` 133 AcceptTime *time.Time `json:"accept_time,omitempty"` 134 PackageInfo *string `json:"package_info,omitempty"` 135} 136 137type ReceiverEntity struct { 138 Type *ReceiverType `json:"type,omitempty"` 139 TransactionInfo *TransactionInfo `json:"transaction_info,omitempty"` 140} 141 142type ReceiverType string 143 144func (e ReceiverType) Ptr() *ReceiverType { 145 return &e 146} 147 148const ( 149 RECEIVERTYPE_TRANSACTION_USER ReceiverType = "TRANSACTION_USER" 150) 151 152type TransactionInfo struct { 153 TransactionId *string `json:"transaction_id,omitempty"` 154 Type *TransactionType `json:"type,omitempty"` 155} 156 157type TransactionType string 158 159func (e TransactionType) Ptr() *TransactionType { 160 return &e 161} 162 163const ( 164 TRANSACTIONTYPE_WXPAY TransactionType = "WXPAY" 165 TRANSACTIONTYPE_WXVALUE TransactionType = "WXVALUE" 166) 167
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/platsolution/ecommerce/mch-transfer/compensate-bills/pre-transfer \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sp_appid" : "wx8888888888888888", 8 "receiver" : { 9 "type" : "TRANSACTION_USER", 10 "transaction_info" : { 11 "transaction_id" : "1217752501201407033233368018", 12 "type" : "WXPAY" 13 } 14 }, 15 "out_bill_no" : "plfk2020042013", 16 "amount" : 10000, 17 "transfer_remark" : "直播违规扣罚", 18 "sponsor_mchid" : "1900001109", 19 "user_recv_perception" : "退货运费补偿", 20 "notify_url" : "https://www.weixin.qq.com/wxpay/pay.php" 21 }' 22
应答参数
200 OK
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的商家单号,只能由数字、大小写字母组成,在商户系统内部唯一
bill_id 必填 string(64)
【微信支付付款单号】 微信支付付款单号
accept_time 必填 string(32)
【受理时间】 受理成功时会返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE
package_info 必填 string(1024)
【跳转领取页面的package信息】 商家付款单跳转微信支付收款页的package信息,该数据在24小时内有效;只有在待用户确认中才返回
应答示例
200 OK
1{ 2 "out_bill_no" : "plfk2020042013", 3 "bill_id" : "1330000071100999991182020050700019480001", 4 "accept_time" : "2015-05-20T13:29:35+08:00", 5 "package_info" : "affffddafdfafddffda==" 6} 7
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |