查询赔付结果(按商户赔付单号)
更新时间:2025.07.25商户单号查询赔付记录。
注:接口频率限制为100次/s
接口说明
支持商户:【平台商户】
请求方式:【GET】/v3/platsolution/ecommerce/mch-transfer/compensate-bills/out-bill-no/{out_bill_no}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
out_bill_no 必填 string(32)
【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一
请求示例
需配合微信支付工具库 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 CompensationBillGetByOutNo { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/platsolution/ecommerce/mch-transfer/compensate-bills/out-bill-no/{out_bill_no}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CompensationBillGetByOutNo client = new CompensationBillGetByOutNo( 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 CompensationBillGetByOutNoRequest request = new CompensationBillGetByOutNoRequest(); 41 request.outBillNo = "plfk2020042013"; 42 try { 43 MchTransferBillEntity response = client.run(request); 44 45 // TODO: 请求成功,继续业务逻辑 46 System.out.println(response); 47 } catch (WXPayUtility.ApiException e) { 48 // TODO: 请求失败,根据状态码执行不同的逻辑 49 e.printStackTrace(); 50 } 51 } 52 53 public MchTransferBillEntity run(CompensationBillGetByOutNoRequest request) { 54 String uri = PATH; 55 uri = uri.replace("{out_bill_no}", WXPayUtility.urlEncode(request.outBillNo)); 56 57 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 58 reqBuilder.addHeader("Accept", "application/json"); 59 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 60 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 61 reqBuilder.method(METHOD, null); 62 Request httpRequest = reqBuilder.build(); 63 64 // 发送HTTP请求 65 OkHttpClient client = new OkHttpClient.Builder().build(); 66 try (Response httpResponse = client.newCall(httpRequest).execute()) { 67 String respBody = WXPayUtility.extractBody(httpResponse); 68 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 69 // 2XX 成功,验证应答签名 70 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 71 httpResponse.headers(), respBody); 72 73 // 从HTTP应答报文构建返回数据 74 return WXPayUtility.fromJson(respBody, MchTransferBillEntity.class); 75 } else { 76 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 77 } 78 } catch (IOException e) { 79 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 80 } 81 } 82 83 private final String mchid; 84 private final String certificateSerialNo; 85 private final PrivateKey privateKey; 86 private final String wechatPayPublicKeyId; 87 private final PublicKey wechatPayPublicKey; 88 89 public CompensationBillGetByOutNo(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 90 this.mchid = mchid; 91 this.certificateSerialNo = certificateSerialNo; 92 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 93 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 94 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 95 } 96 97 public static class CompensationBillGetByOutNoRequest { 98 @SerializedName("out_bill_no") 99 @Expose(serialize = false) 100 public String outBillNo; 101 102 @SerializedName("business_type") 103 @Expose(serialize = false) 104 public BusinsssType businessType; 105 } 106 107 public static class MchTransferBillEntity { 108 @SerializedName("sp_mchid") 109 public String spMchid; 110 111 @SerializedName("receiver_detail") 112 public ReceiverDetailInfo receiverDetail; 113 114 @SerializedName("out_bill_no") 115 public String outBillNo; 116 117 @SerializedName("amount") 118 public Long amount; 119 120 @SerializedName("transfer_remark") 121 public String transferRemark; 122 123 @SerializedName("bill_id") 124 public String billId; 125 126 @SerializedName("state") 127 public TransferStatus state; 128 129 @SerializedName("accept_time") 130 public String acceptTime; 131 132 @SerializedName("success_time") 133 public String successTime; 134 135 @SerializedName("close_info") 136 public TransferCloseInfo closeInfo; 137 138 @SerializedName("sponsor_mchid") 139 public String sponsorMchid; 140 } 141 142 public enum BusinsssType { 143 @SerializedName("DEPOSIT_COMPENSATION") 144 DEPOSIT_COMPENSATION, 145 @SerializedName("PLATFORM_AFTER_SALES_COMPENSATION") 146 PLATFORM_AFTER_SALES_COMPENSATION, 147 @SerializedName("INSURANCE_CLAIM") 148 INSURANCE_CLAIM, 149 @SerializedName("DEPOSIT_AFTER_SALES_COMPENSATION") 150 DEPOSIT_AFTER_SALES_COMPENSATION 151 } 152 153 public static class ReceiverDetailInfo { 154 @SerializedName("receiver") 155 public ReceiverEntity receiver; 156 } 157 158 public enum TransferStatus { 159 @SerializedName("ACCEPTED") 160 ACCEPTED, 161 @SerializedName("SUCCESS") 162 SUCCESS, 163 @SerializedName("CLOSED") 164 CLOSED, 165 @SerializedName("WAIT_USER_CONFIRM") 166 WAIT_USER_CONFIRM, 167 @SerializedName("CANCELING") 168 CANCELING, 169 @SerializedName("CANCELLED") 170 CANCELLED 171 } 172 173 public static class TransferCloseInfo { 174 @SerializedName("close_time") 175 public String closeTime; 176 177 @SerializedName("close_reason") 178 public String closeReason; 179 } 180 181 public static class ReceiverEntity { 182 @SerializedName("type") 183 public ReceiverType type; 184 185 @SerializedName("transaction_info") 186 public TransactionInfo transactionInfo; 187 } 188 189 public enum ReceiverType { 190 @SerializedName("TRANSACTION_USER") 191 TRANSACTION_USER 192 } 193 194 public static class TransactionInfo { 195 @SerializedName("transaction_id") 196 public String transactionId; 197 198 @SerializedName("type") 199 public TransactionType type; 200 } 201 202 public enum TransactionType { 203 @SerializedName("WXPAY") 204 WXPAY, 205 @SerializedName("WXVALUE") 206 WXVALUE 207 } 208 209} 210
需配合微信支付工具库 wxpay_utility 使用,请参考 Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 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 := &CompensationBillGetByOutNoRequest{ 28 OutBillNo: wxpay_utility.String("plfk2020042013"), 29 } 30 31 response, err := CompensationBillGetByOutNo(config, request) 32 if err != nil { 33 fmt.Printf("请求失败: %+v\n", err) 34 // TODO: 请求失败,根据状态码执行不同的处理 35 return 36 } 37 38 // TODO: 请求成功,继续业务逻辑 39 fmt.Printf("请求成功: %+v\n", response) 40} 41 42func CompensationBillGetByOutNo(config *wxpay_utility.MchConfig, request *CompensationBillGetByOutNoRequest) (response *MchTransferBillEntity, err error) { 43 const ( 44 host = "https://api.mch.weixin.qq.com" 45 method = "GET" 46 path = "/v3/platsolution/ecommerce/mch-transfer/compensate-bills/out-bill-no/{out_bill_no}" 47 ) 48 49 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 50 if err != nil { 51 return nil, err 52 } 53 reqUrl.Path = strings.Replace(reqUrl.Path, "{out_bill_no}", url.PathEscape(*request.OutBillNo), -1) 54 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 55 if err != nil { 56 return nil, err 57 } 58 httpRequest.Header.Set("Accept", "application/json") 59 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 60 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest.Header.Set("Authorization", authorization) 65 66 client := &http.Client{} 67 httpResponse, err := client.Do(httpRequest) 68 if err != nil { 69 return nil, err 70 } 71 72 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 73 if err != nil { 74 return nil, err 75 } 76 77 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 78 // 2XX 成功,验证应答签名 79 err = wxpay_utility.ValidateResponse( 80 config.WechatPayPublicKeyId(), 81 config.WechatPayPublicKey(), 82 &httpResponse.Header, 83 respBody, 84 ) 85 if err != nil { 86 return nil, err 87 } 88 89 if err := json.Unmarshal(respBody, response); err != nil { 90 return nil, err 91 } 92 93 return response, nil 94 } else { 95 return nil, wxpay_utility.NewApiException( 96 httpResponse.StatusCode, 97 httpResponse.Header, 98 respBody, 99 ) 100 } 101} 102 103type CompensationBillGetByOutNoRequest struct { 104 OutBillNo *string `json:"out_bill_no,omitempty"` 105 BusinessType *BusinsssType `json:"business_type,omitempty"` 106} 107 108func (o *CompensationBillGetByOutNoRequest) MarshalJSON() ([]byte, error) { 109 type Alias CompensationBillGetByOutNoRequest 110 a := &struct { 111 OutBillNo *string `json:"out_bill_no,omitempty"` 112 BusinessType *BusinsssType `json:"business_type,omitempty"` 113 *Alias 114 }{ 115 // 序列化时移除非 Body 字段 116 OutBillNo: nil, 117 BusinessType: nil, 118 Alias: (*Alias)(o), 119 } 120 return json.Marshal(a) 121} 122 123type MchTransferBillEntity struct { 124 SpMchid *string `json:"sp_mchid,omitempty"` 125 ReceiverDetail *ReceiverDetailInfo `json:"receiver_detail,omitempty"` 126 OutBillNo *string `json:"out_bill_no,omitempty"` 127 Amount *int64 `json:"amount,omitempty"` 128 TransferRemark *string `json:"transfer_remark,omitempty"` 129 BillId *string `json:"bill_id,omitempty"` 130 State *TransferStatus `json:"state,omitempty"` 131 AcceptTime *time.Time `json:"accept_time,omitempty"` 132 SuccessTime *time.Time `json:"success_time,omitempty"` 133 CloseInfo *TransferCloseInfo `json:"close_info,omitempty"` 134 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 135} 136 137type BusinsssType string 138 139func (e BusinsssType) Ptr() *BusinsssType { 140 return &e 141} 142 143const ( 144 BUSINSSSTYPE_DEPOSIT_COMPENSATION BusinsssType = "DEPOSIT_COMPENSATION" 145 BUSINSSSTYPE_PLATFORM_AFTER_SALES_COMPENSATION BusinsssType = "PLATFORM_AFTER_SALES_COMPENSATION" 146 BUSINSSSTYPE_INSURANCE_CLAIM BusinsssType = "INSURANCE_CLAIM" 147 BUSINSSSTYPE_DEPOSIT_AFTER_SALES_COMPENSATION BusinsssType = "DEPOSIT_AFTER_SALES_COMPENSATION" 148) 149 150type ReceiverDetailInfo struct { 151 Receiver *ReceiverEntity `json:"receiver,omitempty"` 152} 153 154type TransferStatus string 155 156func (e TransferStatus) Ptr() *TransferStatus { 157 return &e 158} 159 160const ( 161 TRANSFERSTATUS_ACCEPTED TransferStatus = "ACCEPTED" 162 TRANSFERSTATUS_SUCCESS TransferStatus = "SUCCESS" 163 TRANSFERSTATUS_CLOSED TransferStatus = "CLOSED" 164 TRANSFERSTATUS_WAIT_USER_CONFIRM TransferStatus = "WAIT_USER_CONFIRM" 165 TRANSFERSTATUS_CANCELING TransferStatus = "CANCELING" 166 TRANSFERSTATUS_CANCELLED TransferStatus = "CANCELLED" 167) 168 169type TransferCloseInfo struct { 170 CloseTime *time.Time `json:"close_time,omitempty"` 171 CloseReason *string `json:"close_reason,omitempty"` 172} 173 174type ReceiverEntity struct { 175 Type *ReceiverType `json:"type,omitempty"` 176 TransactionInfo *TransactionInfo `json:"transaction_info,omitempty"` 177} 178 179type ReceiverType string 180 181func (e ReceiverType) Ptr() *ReceiverType { 182 return &e 183} 184 185const ( 186 RECEIVERTYPE_TRANSACTION_USER ReceiverType = "TRANSACTION_USER" 187) 188 189type TransactionInfo struct { 190 TransactionId *string `json:"transaction_id,omitempty"` 191 Type *TransactionType `json:"type,omitempty"` 192} 193 194type TransactionType string 195 196func (e TransactionType) Ptr() *TransactionType { 197 return &e 198} 199 200const ( 201 TRANSACTIONTYPE_WXPAY TransactionType = "WXPAY" 202 TRANSACTIONTYPE_WXVALUE TransactionType = "WXVALUE" 203) 204
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/platsolution/ecommerce/mch-transfer/compensate-bills/out-bill-no/plfk2020042013 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
应答参数
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
: 系统关闭(余额不足、转账失败等原因)。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
close_info 选填 object
【关单信息】 当状态为已关闭时返回,转账的关闭信息,如关闭原因等
属性 | |
close_time 选填 string(32) 【关单时间】 单据关闭时会返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE close_reason 选填 string(64) 【关单原因】 当状态为已关闭时返回,关闭信息,如关闭原因等 |
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 "close_info" : { 20 "close_time" : "2015-05-20T13:29:35+08:00", 21 "close_reason" : "NOT_ENOUGH" 22 }, 23 "sponsor_mchid" : "1900001109" 24} 25
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |