查询赔付结果(按商户赔付单号)
更新时间: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)
【商户单号】 商户系统内部的单号,只能由数字、大小写字母组成,在服务商系统内部唯一
请求示例
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
需配合微信支付工具库 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 // TODO: 请求成功,继续业务逻辑 45 System.out.println(response); 46 } catch (WXPayUtility.ApiException e) { 47 // TODO: 请求失败,根据状态码执行不同的逻辑 48 e.printStackTrace(); 49 } 50 } 51 52 public MchTransferBillEntity run(CompensationBillGetByOutNoRequest request) { 53 String uri = PATH; 54 uri = uri.replace("{out_bill_no}", WXPayUtility.urlEncode(request.outBillNo)); 55 56 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 57 reqBuilder.addHeader("Accept", "application/json"); 58 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 59 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 60 reqBuilder.method(METHOD, null); 61 Request httpRequest = reqBuilder.build(); 62 63 // 发送HTTP请求 64 OkHttpClient client = new OkHttpClient.Builder().build(); 65 try (Response httpResponse = client.newCall(httpRequest).execute()) { 66 String respBody = WXPayUtility.extractBody(httpResponse); 67 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 68 // 2XX 成功,验证应答签名 69 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 70 httpResponse.headers(), respBody); 71 72 // 从HTTP应答报文构建返回数据 73 return WXPayUtility.fromJson(respBody, MchTransferBillEntity.class); 74 } else { 75 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 76 } 77 } catch (IOException e) { 78 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 79 } 80 } 81 82 private final String mchid; 83 private final String certificateSerialNo; 84 private final PrivateKey privateKey; 85 private final String wechatPayPublicKeyId; 86 private final PublicKey wechatPayPublicKey; 87 88 public CompensationBillGetByOutNo(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 89 this.mchid = mchid; 90 this.certificateSerialNo = certificateSerialNo; 91 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 92 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 93 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 94 } 95 96 public static class CompensationBillGetByOutNoRequest { 97 @SerializedName("out_bill_no") 98 @Expose(serialize = false) 99 public String outBillNo; 100 101 @SerializedName("business_type") 102 @Expose(serialize = false) 103 public BusinsssType businessType; 104 } 105 106 public static class MchTransferBillEntity { 107 @SerializedName("sp_mchid") 108 public String spMchid; 109 110 @SerializedName("receiver_detail") 111 public ReceiverDetailInfo receiverDetail; 112 113 @SerializedName("out_bill_no") 114 public String outBillNo; 115 116 @SerializedName("amount") 117 public Long amount; 118 119 @SerializedName("transfer_remark") 120 public String transferRemark; 121 122 @SerializedName("bill_id") 123 public String billId; 124 125 @SerializedName("state") 126 public TransferStatus state; 127 128 @SerializedName("accept_time") 129 public String acceptTime; 130 131 @SerializedName("success_time") 132 public String successTime; 133 134 @SerializedName("close_info") 135 public TransferCloseInfo closeInfo; 136 137 @SerializedName("sponsor_mchid") 138 public String sponsorMchid; 139 } 140 141 public enum BusinsssType { 142 @SerializedName("DEPOSIT_COMPENSATION") 143 DEPOSIT_COMPENSATION, 144 @SerializedName("PLATFORM_AFTER_SALES_COMPENSATION") 145 PLATFORM_AFTER_SALES_COMPENSATION, 146 @SerializedName("INSURANCE_CLAIM") 147 INSURANCE_CLAIM, 148 @SerializedName("DEPOSIT_AFTER_SALES_COMPENSATION") 149 DEPOSIT_AFTER_SALES_COMPENSATION 150 } 151 152 public static class ReceiverDetailInfo { 153 @SerializedName("receiver") 154 public ReceiverEntity receiver; 155 } 156 157 public enum TransferStatus { 158 @SerializedName("ACCEPTED") 159 ACCEPTED, 160 @SerializedName("SUCCESS") 161 SUCCESS, 162 @SerializedName("CLOSED") 163 CLOSED, 164 @SerializedName("WAIT_USER_CONFIRM") 165 WAIT_USER_CONFIRM, 166 @SerializedName("CANCELING") 167 CANCELING, 168 @SerializedName("CANCELLED") 169 CANCELLED 170 } 171 172 public static class TransferCloseInfo { 173 @SerializedName("close_time") 174 public String closeTime; 175 176 @SerializedName("close_reason") 177 public String closeReason; 178 } 179 180 public static class ReceiverEntity { 181 @SerializedName("type") 182 public ReceiverType type; 183 184 @SerializedName("transaction_info") 185 public TransactionInfo transactionInfo; 186 } 187 188 public enum ReceiverType { 189 @SerializedName("TRANSACTION_USER") 190 TRANSACTION_USER 191 } 192 193 public static class TransactionInfo { 194 @SerializedName("transaction_id") 195 public String transactionId; 196 197 @SerializedName("type") 198 public TransactionType type; 199 } 200 201 public enum TransactionType { 202 @SerializedName("WXPAY") 203 WXPAY, 204 @SerializedName("WXVALUE") 205 WXVALUE 206 } 207 208} 209
需配合微信支付工具库 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 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 72 if err != nil { 73 return nil, err 74 } 75 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 76 // 2XX 成功,验证应答签名 77 err = wxpay_utility.ValidateResponse( 78 config.WechatPayPublicKeyId(), 79 config.WechatPayPublicKey(), 80 &httpResponse.Header, 81 respBody, 82 ) 83 if err != nil { 84 return nil, err 85 } 86 response := &MchTransferBillEntity{} 87 if err := json.Unmarshal(respBody, response); err != nil { 88 return nil, err 89 } 90 91 return response, nil 92 } else { 93 return nil, wxpay_utility.NewApiException( 94 httpResponse.StatusCode, 95 httpResponse.Header, 96 respBody, 97 ) 98 } 99} 100 101type CompensationBillGetByOutNoRequest struct { 102 OutBillNo *string `json:"out_bill_no,omitempty"` 103 BusinessType *BusinsssType `json:"business_type,omitempty"` 104} 105 106func (o *CompensationBillGetByOutNoRequest) MarshalJSON() ([]byte, error) { 107 type Alias CompensationBillGetByOutNoRequest 108 a := &struct { 109 OutBillNo *string `json:"out_bill_no,omitempty"` 110 BusinessType *BusinsssType `json:"business_type,omitempty"` 111 *Alias 112 }{ 113 // 序列化时移除非 Body 字段 114 OutBillNo: nil, 115 BusinessType: nil, 116 Alias: (*Alias)(o), 117 } 118 return json.Marshal(a) 119} 120 121type MchTransferBillEntity struct { 122 SpMchid *string `json:"sp_mchid,omitempty"` 123 ReceiverDetail *ReceiverDetailInfo `json:"receiver_detail,omitempty"` 124 OutBillNo *string `json:"out_bill_no,omitempty"` 125 Amount *int64 `json:"amount,omitempty"` 126 TransferRemark *string `json:"transfer_remark,omitempty"` 127 BillId *string `json:"bill_id,omitempty"` 128 State *TransferStatus `json:"state,omitempty"` 129 AcceptTime *time.Time `json:"accept_time,omitempty"` 130 SuccessTime *time.Time `json:"success_time,omitempty"` 131 CloseInfo *TransferCloseInfo `json:"close_info,omitempty"` 132 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 133} 134 135type BusinsssType string 136 137func (e BusinsssType) Ptr() *BusinsssType { 138 return &e 139} 140 141const ( 142 BUSINSSSTYPE_DEPOSIT_COMPENSATION BusinsssType = "DEPOSIT_COMPENSATION" 143 BUSINSSSTYPE_PLATFORM_AFTER_SALES_COMPENSATION BusinsssType = "PLATFORM_AFTER_SALES_COMPENSATION" 144 BUSINSSSTYPE_INSURANCE_CLAIM BusinsssType = "INSURANCE_CLAIM" 145 BUSINSSSTYPE_DEPOSIT_AFTER_SALES_COMPENSATION BusinsssType = "DEPOSIT_AFTER_SALES_COMPENSATION" 146) 147 148type ReceiverDetailInfo struct { 149 Receiver *ReceiverEntity `json:"receiver,omitempty"` 150} 151 152type TransferStatus string 153 154func (e TransferStatus) Ptr() *TransferStatus { 155 return &e 156} 157 158const ( 159 TRANSFERSTATUS_ACCEPTED TransferStatus = "ACCEPTED" 160 TRANSFERSTATUS_SUCCESS TransferStatus = "SUCCESS" 161 TRANSFERSTATUS_CLOSED TransferStatus = "CLOSED" 162 TRANSFERSTATUS_WAIT_USER_CONFIRM TransferStatus = "WAIT_USER_CONFIRM" 163 TRANSFERSTATUS_CANCELING TransferStatus = "CANCELING" 164 TRANSFERSTATUS_CANCELLED TransferStatus = "CANCELLED" 165) 166 167type TransferCloseInfo struct { 168 CloseTime *time.Time `json:"close_time,omitempty"` 169 CloseReason *string `json:"close_reason,omitempty"` 170} 171 172type ReceiverEntity struct { 173 Type *ReceiverType `json:"type,omitempty"` 174 TransactionInfo *TransactionInfo `json:"transaction_info,omitempty"` 175} 176 177type ReceiverType string 178 179func (e ReceiverType) Ptr() *ReceiverType { 180 return &e 181} 182 183const ( 184 RECEIVERTYPE_TRANSACTION_USER ReceiverType = "TRANSACTION_USER" 185) 186 187type TransactionInfo struct { 188 TransactionId *string `json:"transaction_id,omitempty"` 189 Type *TransactionType `json:"type,omitempty"` 190} 191 192type TransactionType string 193 194func (e TransactionType) Ptr() *TransactionType { 195 return &e 196} 197 198const ( 199 TRANSACTIONTYPE_WXPAY TransactionType = "WXPAY" 200 TRANSACTIONTYPE_WXVALUE TransactionType = "WXVALUE" 201) 202
应答参数
折叠全部参数
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
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
