申请企业商户企业支付业务账单
更新时间:2025.05.09申请企业商户企业支付业务账单。该接口允许服务商为指定出资子商户申请特定日期的企业支付业务账单,仅支持申请三个月内的账单数据。业务账单包含交易明细,可用于企业对账和财务分析。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/webizpay/bill/trade-bill
请求域名:【主域名】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_mchid 必填 string(32)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
sub_mchid 必填 string(32)
【出资子商户号】 由服务商为子商户进件后获取,具体请参考服务商模式开发必要参数说明。
date 必填 string
【账单日期】 账单日期,仅支持申请三个月内业务账单,格式yyyy-MM-DD。
仅支持按一天的纬度查询
type 必填 string
【账单类型】 账单类型,当前默认只有QYZFALL
可选取值
QYZFALL
: 企业支付
请求示例
需配合微信支付工具库 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 ApplyBill { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/webizpay/bill/trade-bill"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ApplyBill client = new ApplyBill( 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 StoreApplyBillRequest request = new StoreApplyBillRequest(); 41 request.spMchid = "12341234"; 42 request.subMchid = "43214321"; 43 request.date = "2025-04-23"; 44 request.type = BillType.QYZFALL; 45 try { 46 StoreApplyBillResponse response = client.run(request); 47 48 // TODO: 请求成功,继续业务逻辑 49 System.out.println(response); 50 } catch (WXPayUtility.ApiException e) { 51 // TODO: 请求失败,根据状态码执行不同的逻辑 52 e.printStackTrace(); 53 } 54 } 55 56 public StoreApplyBillResponse run(StoreApplyBillRequest request) { 57 String uri = PATH; 58 String reqBody = WXPayUtility.toJson(request); 59 60 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 61 reqBuilder.addHeader("Accept", "application/json"); 62 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 63 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 64 reqBuilder.addHeader("Content-Type", "application/json"); 65 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 66 reqBuilder.method(METHOD, requestBody); 67 Request httpRequest = reqBuilder.build(); 68 69 // 发送HTTP请求 70 OkHttpClient client = new OkHttpClient.Builder().build(); 71 try (Response httpResponse = client.newCall(httpRequest).execute()) { 72 String respBody = WXPayUtility.extractBody(httpResponse); 73 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 74 // 2XX 成功,验证应答签名 75 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 76 httpResponse.headers(), respBody); 77 78 // 从HTTP应答报文构建返回数据 79 return WXPayUtility.fromJson(respBody, StoreApplyBillResponse.class); 80 } else { 81 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 82 } 83 } catch (IOException e) { 84 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 85 } 86 } 87 88 private final String mchid; 89 private final String certificateSerialNo; 90 private final PrivateKey privateKey; 91 private final String wechatPayPublicKeyId; 92 private final PublicKey wechatPayPublicKey; 93 94 public ApplyBill(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 95 this.mchid = mchid; 96 this.certificateSerialNo = certificateSerialNo; 97 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 98 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 99 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 100 } 101 102 public static class StoreApplyBillRequest { 103 @SerializedName("sp_mchid") 104 public String spMchid; 105 106 @SerializedName("sub_mchid") 107 public String subMchid; 108 109 @SerializedName("date") 110 public String date; 111 112 @SerializedName("type") 113 public BillType type; 114 } 115 116 public static class StoreApplyBillResponse { 117 @SerializedName("sp_mchid") 118 public String spMchid; 119 120 @SerializedName("sub_mchid") 121 public String subMchid; 122 123 @SerializedName("date") 124 public String date; 125 126 @SerializedName("type") 127 public BillType type; 128 129 @SerializedName("download_url") 130 public String downloadUrl; 131 132 @SerializedName("hash_type") 133 public String hashType; 134 135 @SerializedName("hash_value") 136 public String hashValue; 137 } 138 139 public enum BillType { 140 @SerializedName("QYZFALL") 141 QYZFALL 142 } 143 144} 145
需配合微信支付工具库 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) 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 := &StoreApplyBillRequest{ 27 SpMchid: wxpay_utility.String("12341234"), 28 SubMchid: wxpay_utility.String("43214321"), 29 Date: wxpay_utility.String("2025-04-23"), 30 Type: BILLTYPE_QYZFALL.Ptr(), 31 } 32 33 response, err := ApplyBill(config, request) 34 if err != nil { 35 fmt.Printf("请求失败: %+v\n", err) 36 // TODO: 请求失败,根据状态码执行不同的处理 37 return 38 } 39 40 // TODO: 请求成功,继续业务逻辑 41 fmt.Printf("请求成功: %+v\n", response) 42} 43 44func ApplyBill(config *wxpay_utility.MchConfig, request *StoreApplyBillRequest) (response *StoreApplyBillResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/webizpay/bill/trade-bill" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 reqBody, err := json.Marshal(request) 56 if err != nil { 57 return nil, err 58 } 59 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 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 httpRequest.Header.Set("Content-Type", "application/json") 66 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 67 if err != nil { 68 return nil, err 69 } 70 httpRequest.Header.Set("Authorization", authorization) 71 72 client := &http.Client{} 73 httpResponse, err := client.Do(httpRequest) 74 if err != nil { 75 return nil, err 76 } 77 78 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 79 if err != nil { 80 return nil, err 81 } 82 83 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 84 // 2XX 成功,验证应答签名 85 err = wxpay_utility.ValidateResponse( 86 config.WechatPayPublicKeyId(), 87 config.WechatPayPublicKey(), 88 &httpResponse.Header, 89 respBody, 90 ) 91 if err != nil { 92 return nil, err 93 } 94 95 if err := json.Unmarshal(respBody, response); err != nil { 96 return nil, err 97 } 98 99 return response, nil 100 } else { 101 return nil, wxpay_utility.NewApiException( 102 httpResponse.StatusCode, 103 httpResponse.Header, 104 respBody, 105 ) 106 } 107} 108 109type StoreApplyBillRequest struct { 110 SpMchid *string `json:"sp_mchid,omitempty"` 111 SubMchid *string `json:"sub_mchid,omitempty"` 112 Date *string `json:"date,omitempty"` 113 Type *BillType `json:"type,omitempty"` 114} 115 116type StoreApplyBillResponse struct { 117 SpMchid *string `json:"sp_mchid,omitempty"` 118 SubMchid *string `json:"sub_mchid,omitempty"` 119 Date *string `json:"date,omitempty"` 120 Type *BillType `json:"type,omitempty"` 121 DownloadUrl *string `json:"download_url,omitempty"` 122 HashType *string `json:"hash_type,omitempty"` 123 HashValue *string `json:"hash_value,omitempty"` 124} 125 126type BillType string 127 128func (e BillType) Ptr() *BillType { 129 return &e 130} 131 132const ( 133 BILLTYPE_QYZFALL BillType = "QYZFALL" 134) 135
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/webizpay/bill/trade-bill \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sp_mchid" : "12341234", 8 "sub_mchid" : "43214321", 9 "date" : "2025-04-23", 10 "type" : "QYZFALL" 11 }' 12
应答参数
200 OK
sp_mchid 必填 string(32)
【服务商商户号】 服务商商户号,由商户请求时传入
sub_mchid 必填 string(32)
【出资子商户号】 出资子商户号,表示此出资商户的账单,又商户请求时传入
date 必填 string
【账单日期】 账单日期 格式yyyy-MM-DD,表示当日的账单
type 必填 string
【账单类型】 账单类型,商户请求时传入
可选取值
QYZFALL
: 企业支付
download_url 必填 string(256)
【账单下载地址】 供下一步请求账单文件的下载地址,该地址5min内有效。参考下载账单
hash_type 必填 string
【哈希类型】 哈希类型,固定为SHA1。
hash_value 必填 string(2048)
【哈希值】 账单文件的SHA1摘要值,用于服务商侧校验文件的一致性。
应答示例
200 OK
1{ 2 "sp_mchid" : "12341234", 3 "sub_mchid" : "43214321", 4 "date" : "2025-04-23", 5 "type" : "QYZFALL", 6 "download_url" : "https://api.mch.weixin.qq.com/v3/billdownload/file?token=xxx", 7 "hash_type" : "SHA1", 8 "hash_value" : "79bb0f45fc4c42234a918000b2668d689e2bde04" 9} 10
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |