商户单号查询公益捐赠详情
更新时间:2025.07.10根据商户单号查询公益捐赠单的详细信息。
注意
API只支持查询最近30天内的捐赠单,超过30天可以通过资金账单对账确认。
转账单中涉及金额的字段单位为“分”。
如果遇到新的错误码,请务必不要换单重试。需通过商户单号查询订单结果,当查询原订单结果明确为失败时,再更换商户订单号进行重试。否则会有重复捐赠的资金风险。如果有新的错误码,会更新到此API文档中。
错误码描述字段message只供人工定位问题时做参考,系统实现时请不要依赖这个字段来做自动化处理。
接口限频: 单个商户 100 QPS,如果超过频率限制,会报错 RATELIMIT_EXCEEDED,请降低频率请求。
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/fund-app/mch-transfer/partner/charity-transfer-bills/out-transfer-no/{out_transfer_no}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
out_transfer_no 必填 string(32)
【商户公益捐赠单号】 商户公益捐赠单号
query 查询参数
sponsor_mchid 必填 string(32)
【出资商户号】 出资商户号
out_budget_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 GetByOutNo4Charity { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/fund-app/mch-transfer/partner/charity-transfer-bills/out-transfer-no/{out_transfer_no}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetByOutNo4Charity client = new GetByOutNo4Charity( 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 GetByOutNo4CharityRequest request = new GetByOutNo4CharityRequest(); 41 request.outTransferNo = "trans202506300102"; 42 request.sponsorMchid = "1900001109"; 43 request.outBudgetNo = "budget202506030102"; 44 try { 45 TransferCharityBillEntity response = client.run(request); 46 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public TransferCharityBillEntity run(GetByOutNo4CharityRequest request) { 56 String uri = PATH; 57 uri = uri.replace("{out_transfer_no}", WXPayUtility.urlEncode(request.outTransferNo)); 58 Map<String, Object> args = new HashMap<>(); 59 args.put("sponsor_mchid", request.sponsorMchid); 60 args.put("out_budget_no", request.outBudgetNo); 61 uri = uri + "?" + WXPayUtility.urlEncode(args); 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, null)); 67 reqBuilder.method(METHOD, null); 68 Request httpRequest = reqBuilder.build(); 69 70 // 发送HTTP请求 71 OkHttpClient client = new OkHttpClient.Builder().build(); 72 try (Response httpResponse = client.newCall(httpRequest).execute()) { 73 String respBody = WXPayUtility.extractBody(httpResponse); 74 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 75 // 2XX 成功,验证应答签名 76 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 77 httpResponse.headers(), respBody); 78 79 // 从HTTP应答报文构建返回数据 80 return WXPayUtility.fromJson(respBody, TransferCharityBillEntity.class); 81 } else { 82 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 83 } 84 } catch (IOException e) { 85 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 86 } 87 } 88 89 private final String mchid; 90 private final String certificateSerialNo; 91 private final PrivateKey privateKey; 92 private final String wechatPayPublicKeyId; 93 private final PublicKey wechatPayPublicKey; 94 95 public GetByOutNo4Charity(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 96 this.mchid = mchid; 97 this.certificateSerialNo = certificateSerialNo; 98 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 99 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 100 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 101 } 102 103 public static class GetByOutNo4CharityRequest { 104 @SerializedName("sponsor_mchid") 105 @Expose(serialize = false) 106 public String sponsorMchid; 107 108 @SerializedName("out_budget_no") 109 @Expose(serialize = false) 110 public String outBudgetNo; 111 112 @SerializedName("out_transfer_no") 113 @Expose(serialize = false) 114 public String outTransferNo; 115 } 116 117 public static class TransferCharityBillEntity { 118 @SerializedName("out_budget_no") 119 public String outBudgetNo; 120 121 @SerializedName("budget_id") 122 public String budgetId; 123 124 @SerializedName("out_transfer_no") 125 public String outTransferNo; 126 127 @SerializedName("transfer_id") 128 public String transferId; 129 130 @SerializedName("amount") 131 public Long amount; 132 133 @SerializedName("transfer_remark") 134 public String transferRemark; 135 136 @SerializedName("receive_mchid") 137 public String receiveMchid; 138 139 @SerializedName("state") 140 public TransferBillStatus state; 141 142 @SerializedName("create_time") 143 public String createTime; 144 145 @SerializedName("success_time") 146 public String successTime; 147 } 148 149 public enum TransferBillStatus { 150 @SerializedName("ACCEPTED") 151 ACCEPTED, 152 @SerializedName("SUCCESS") 153 SUCCESS, 154 @SerializedName("CLOSE") 155 CLOSE 156 } 157 158} 159
需配合微信支付工具库 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) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &GetByOutNo4CharityRequest{ 27 SponsorMchid: wxpay_utility.String("1900001109"), 28 OutBudgetNo: wxpay_utility.String("budget202506030102"), 29 OutTransferNo: wxpay_utility.String("trans202506300102"), 30 } 31 32 response, err := GetByOutNo4Charity(config, request) 33 if err != nil { 34 fmt.Printf("请求失败: %+v\n", err) 35 // TODO: 请求失败,根据状态码执行不同的处理 36 return 37 } 38 39 // TODO: 请求成功,继续业务逻辑 40 fmt.Printf("请求成功: %+v\n", response) 41} 42 43func GetByOutNo4Charity(config *wxpay_utility.MchConfig, request *GetByOutNo4CharityRequest) (response *TransferCharityBillEntity, err error) { 44 const ( 45 host = "https://api.mch.weixin.qq.com" 46 method = "GET" 47 path = "/v3/fund-app/mch-transfer/partner/charity-transfer-bills/out-transfer-no/{out_transfer_no}" 48 ) 49 50 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 51 if err != nil { 52 return nil, err 53 } 54 reqUrl.Path = strings.Replace(reqUrl.Path, "{out_transfer_no}", url.PathEscape(*request.OutTransferNo), -1) 55 query := reqUrl.Query() 56 query.Add("sponsor_mchid", *request.SponsorMchid) 57 query.Add("out_budget_no", *request.OutBudgetNo) 58 reqUrl.RawQuery = query.Encode() 59 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest.Header.Set("Accept", "application/json") 64 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 65 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 66 if err != nil { 67 return nil, err 68 } 69 httpRequest.Header.Set("Authorization", authorization) 70 71 client := &http.Client{} 72 httpResponse, err := client.Do(httpRequest) 73 if err != nil { 74 return nil, err 75 } 76 77 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 78 if err != nil { 79 return nil, err 80 } 81 82 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 83 // 2XX 成功,验证应答签名 84 err = wxpay_utility.ValidateResponse( 85 config.WechatPayPublicKeyId(), 86 config.WechatPayPublicKey(), 87 &httpResponse.Header, 88 respBody, 89 ) 90 if err != nil { 91 return nil, err 92 } 93 94 if err := json.Unmarshal(respBody, response); err != nil { 95 return nil, err 96 } 97 98 return response, nil 99 } else { 100 return nil, wxpay_utility.NewApiException( 101 httpResponse.StatusCode, 102 httpResponse.Header, 103 respBody, 104 ) 105 } 106} 107 108type GetByOutNo4CharityRequest struct { 109 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 110 OutBudgetNo *string `json:"out_budget_no,omitempty"` 111 OutTransferNo *string `json:"out_transfer_no,omitempty"` 112} 113 114func (o *GetByOutNo4CharityRequest) MarshalJSON() ([]byte, error) { 115 type Alias GetByOutNo4CharityRequest 116 a := &struct { 117 SponsorMchid *string `json:"sponsor_mchid,omitempty"` 118 OutBudgetNo *string `json:"out_budget_no,omitempty"` 119 OutTransferNo *string `json:"out_transfer_no,omitempty"` 120 *Alias 121 }{ 122 // 序列化时移除非 Body 字段 123 SponsorMchid: nil, 124 OutBudgetNo: nil, 125 OutTransferNo: nil, 126 Alias: (*Alias)(o), 127 } 128 return json.Marshal(a) 129} 130 131type TransferCharityBillEntity struct { 132 OutBudgetNo *string `json:"out_budget_no,omitempty"` 133 BudgetId *string `json:"budget_id,omitempty"` 134 OutTransferNo *string `json:"out_transfer_no,omitempty"` 135 TransferId *string `json:"transfer_id,omitempty"` 136 Amount *int64 `json:"amount,omitempty"` 137 TransferRemark *string `json:"transfer_remark,omitempty"` 138 ReceiveMchid *string `json:"receive_mchid,omitempty"` 139 State *TransferBillStatus `json:"state,omitempty"` 140 CreateTime *string `json:"create_time,omitempty"` 141 SuccessTime *string `json:"success_time,omitempty"` 142} 143 144type TransferBillStatus string 145 146func (e TransferBillStatus) Ptr() *TransferBillStatus { 147 return &e 148} 149 150const ( 151 TRANSFERBILLSTATUS_ACCEPTED TransferBillStatus = "ACCEPTED" 152 TRANSFERBILLSTATUS_SUCCESS TransferBillStatus = "SUCCESS" 153 TRANSFERBILLSTATUS_CLOSE TransferBillStatus = "CLOSE" 154) 155
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/partner/charity-transfer-bills/out-transfer-no/trans202506300102?sponsor_mchid=1900001109&out_budget_no=budget202506030102 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
应答参数
200 OK
out_budget_no 必填 string(32)
【商户预算单号】 商户预算单号
budget_id 必填 string(32)
【微信支付预算单号】 微信支付预算单号
out_transfer_no 必填 string(32)
【商户公益捐赠单号】 商户公益捐赠单号
transfer_id 必填 string(32)
【微信支付公益捐赠单号】 微信支付公益捐赠单号
amount 必填 integer
【捐赠金额】 单位为“分”。
transfer_remark 必填 string(32)
【捐赠备注】 捐赠备注
receive_mchid 必填 string(32)
【收款商户号】 收款商户号
state 必填 string
【捐赠状态】 捐赠状态
可选取值
ACCEPTED
: 转账已受理SUCCESS
: 转账成功CLOSE
: 已关闭
create_time 必填 string
【捐赠单创建时间】 捐赠单创建时间,遵循rfc3339标准格式:yyyy-MM-DDThh:mm:ss+TIMEZONE
success_time 选填 string
【捐赠完成时间】 捐赠完成时间,仅当转账成功时返回,遵循rfc3339标准格式:yyyy-MM-DDThh:mm:ss+TIMEZONE
应答示例
200 OK
1{ 2 "out_budget_no" : "budget202506030102", 3 "budget_id" : "1182020050700019480001", 4 "out_transfer_no" : "trans202506300102", 5 "transfer_id" : "4217752501201407033233368018", 6 "amount" : 10000, 7 "transfer_remark" : "帮助受助群体爱心捐款", 8 "receive_mchid" : "1900001109", 9 "state" : "SUCCESS", 10 "create_time" : "2025-06-21T13:29:35.120+08:00", 11 "success_time" : "2025-06-21T13:29:35.120+08:00" 12} 13
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
404 | NOT_FOUND | 记录不存在 | 确认订单号 |
429 | RATELIMIT_EXCEEDED | 请求接口频率过快 | 降低频率,稍后重试 |