申请分账账单
更新时间:2025.09.29分账账单已于2025年1月15日修复部分数据没有展示“`”的问题
微信支付按天提供分账账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含分账相关的金额、时间等信息,供商户核对到账等情况。
微信侧未成功的分账单不会出现在对账单中。
对账单中涉及金额的字段单位为“元”;
对账单接口只能下载三个月以内的账单。
账单文件包括明细数据和汇总数据两部分,每一部分都包含一行表头和若干行具体数据。
明细数据每一行对应一笔分账或一笔回退,同时每一个数据前加入了字符`,以避免数据被Excel按科学计数法处理。如需汇总金额等数据,可以批量替换掉该字符。
接口说明
支持商户:【普通商户】
请求方式:【GET】/v3/profitsharing/bills
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
query 查询参数
bill_date 必填 string(10)
【账单日期】 格式YYYY-MM-DD。仅支持三个月内的账单下载申请。
tar_type 选填 string
【压缩类型】 不填则以不压缩的方式返回数据流
可选取值
GZIP
: 返回格式为.gzip的压缩包账单
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/profitsharing/bills?bill_date=2019-06-11&tar_type=GZIP \ 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/merchant/4014931831 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 SplitBill { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/profitsharing/bills"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 SplitBill client = new SplitBill( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 SplitBillRequest request = new SplitBillRequest(); 41 request.billDate = "2019-06-11"; 42 request.tarType = SplitBillTarType.GZIP; 43 try { 44 SplitBillResponse response = client.run(request); 45 // TODO: 请求成功,继续业务逻辑 46 System.out.println(response); 47 } catch (WXPayUtility.ApiException e) { 48 // TODO: 请求失败,根据状态码执行不同的逻辑 49 e.printStackTrace(); 50 } 51 } 52 53 public SplitBillResponse run(SplitBillRequest request) { 54 String uri = PATH; 55 Map<String, Object> args = new HashMap<>(); 56 args.put("bill_date", request.billDate); 57 args.put("tar_type", request.tarType); 58 String queryString = WXPayUtility.urlEncode(args); 59 if (!queryString.isEmpty()) { 60 uri = uri + "?" + queryString; 61 } 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, SplitBillResponse.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 SplitBill(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 SplitBillRequest { 104 @SerializedName("bill_date") 105 @Expose(serialize = false) 106 public String billDate; 107 108 @SerializedName("tar_type") 109 @Expose(serialize = false) 110 public SplitBillTarType tarType; 111 } 112 113 public static class SplitBillResponse { 114 @SerializedName("hash_type") 115 public SplitBillHashType hashType; 116 117 @SerializedName("hash_value") 118 public String hashValue; 119 120 @SerializedName("download_url") 121 public String downloadUrl; 122 } 123 124 public enum SplitBillTarType { 125 @SerializedName("GZIP") 126 GZIP 127 } 128 129 public enum SplitBillHashType { 130 @SerializedName("SHA1") 131 SHA1 132 } 133 134} 135
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9) 10 11func main() { 12 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 13 config, err := wxpay_utility.CreateMchConfig( 14 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 15 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 16 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 17 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 18 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 19 ) 20 if err != nil { 21 fmt.Println(err) 22 return 23 } 24 25 request := &SplitBillRequest{ 26 BillDate: wxpay_utility.String("2019-06-11"), 27 TarType: SPLITBILLTARTYPE_GZIP.Ptr(), 28 } 29 30 response, err := SplitBill(config, request) 31 if err != nil { 32 fmt.Printf("请求失败: %+v\n", err) 33 // TODO: 请求失败,根据状态码执行不同的处理 34 return 35 } 36 37 // TODO: 请求成功,继续业务逻辑 38 fmt.Printf("请求成功: %+v\n", response) 39} 40 41func SplitBill(config *wxpay_utility.MchConfig, request *SplitBillRequest) (response *SplitBillResponse, err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "GET" 45 path = "/v3/profitsharing/bills" 46 ) 47 48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 49 if err != nil { 50 return nil, err 51 } 52 query := reqUrl.Query() 53 if request.BillDate != nil { 54 query.Add("bill_date", *request.BillDate) 55 } 56 if request.TarType != nil { 57 query.Add("tar_type", fmt.Sprintf("%v", *request.TarType)) 58 } 59 reqUrl.RawQuery = query.Encode() 60 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest.Header.Set("Accept", "application/json") 65 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 66 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 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 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 78 if err != nil { 79 return nil, err 80 } 81 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 82 // 2XX 成功,验证应答签名 83 err = wxpay_utility.ValidateResponse( 84 config.WechatPayPublicKeyId(), 85 config.WechatPayPublicKey(), 86 &httpResponse.Header, 87 respBody, 88 ) 89 if err != nil { 90 return nil, err 91 } 92 response := &SplitBillResponse{} 93 if err := json.Unmarshal(respBody, response); err != nil { 94 return nil, err 95 } 96 97 return response, nil 98 } else { 99 return nil, wxpay_utility.NewApiException( 100 httpResponse.StatusCode, 101 httpResponse.Header, 102 respBody, 103 ) 104 } 105} 106 107type SplitBillRequest struct { 108 BillDate *string `json:"bill_date,omitempty"` 109 TarType *SplitBillTarType `json:"tar_type,omitempty"` 110} 111 112func (o *SplitBillRequest) MarshalJSON() ([]byte, error) { 113 type Alias SplitBillRequest 114 a := &struct { 115 BillDate *string `json:"bill_date,omitempty"` 116 TarType *SplitBillTarType `json:"tar_type,omitempty"` 117 *Alias 118 }{ 119 // 序列化时移除非 Body 字段 120 BillDate: nil, 121 TarType: nil, 122 Alias: (*Alias)(o), 123 } 124 return json.Marshal(a) 125} 126 127type SplitBillResponse struct { 128 HashType *SplitBillHashType `json:"hash_type,omitempty"` 129 HashValue *string `json:"hash_value,omitempty"` 130 DownloadUrl *string `json:"download_url,omitempty"` 131} 132 133type SplitBillTarType string 134 135func (e SplitBillTarType) Ptr() *SplitBillTarType { 136 return &e 137} 138 139const ( 140 SPLITBILLTARTYPE_GZIP SplitBillTarType = "GZIP" 141) 142 143type SplitBillHashType string 144 145func (e SplitBillHashType) Ptr() *SplitBillHashType { 146 return &e 147} 148 149const ( 150 SPLITBILLHASHTYPE_SHA1 SplitBillHashType = "SHA1" 151) 152
应答参数
200 OK
hash_type 必填 string
【哈希类型】 原始账单(gzip需要解压缩)的摘要算法,用于校验文件的完整性
可选取值
SHA1
: Secure Hash Algorithm 1
hash_value 必填 string(1024)
【哈希值】 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性
download_url 必填 string(2048)
【下载地址】 供下一步请求账单文件的下载地址,该地址30s内有效
应答示例
200 OK
1{ 2 "hash_type" : "SHA1", 3 "hash_value" : "79bb0f45fc4c42234a918000b2668d689e2bde04", 4 "download_url" : "https://api.mch.weixin.qq.com/v3/bill/downloadurl?token=xxx" 5} 6
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示