查询分账结果

更新时间:2025.08.21

发起分账请求后,可调用此接口查询分账结果 。发起分账完结请求后,可调用此接口查询分账完结的结果。

接口说明

支持商户:【普通服务商】

请求方式:【GET】/v3/brand/profitsharing/orders

请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点

     【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看

请求参数

Header  HTTP头参数

 Authorization  必填 string

请参考签名认证生成认证信息


 Accept  必填 string

请设置为application/json


query  查询参数

 sub_mchid  必填   string(32)

【子商户号】 订单收款方商户号,填写微信支付分配的商户号


 transaction_id  必填   string(32)

【微信订单号】 微信支付订单号


 out_order_no  必填   string(64)

【商户分账单号】 商户系统内部的分账单号,在商户系统内部唯一(分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次

请求示例

Java
Go
curl

需配合微信支付工具库 WXPayUtility 使用,请参考 iwiki-document:inline_state 

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 QueryOrder {
26  private static String HOST = "https://api.mch.weixin.qq.com";
27  private static String METHOD = "GET";
28  private static String PATH = "/v3/brand/profitsharing/orders";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    QueryOrder client = new QueryOrder(
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    QueryOrderRequest request = new QueryOrderRequest();
41    request.subMchid = "1900000109";
42    request.transactionId = "4208450740201411110007820472";
43    request.outOrderNo = "P20150806125346";
44    try {
45      QueryOrderResponse 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 QueryOrderResponse run(QueryOrderRequest request) {
56    String uri = PATH;
57    Map<String, Object> args = new HashMap<>();
58    args.put("sub_mchid", request.subMchid);
59    args.put("transaction_id", request.transactionId);
60    args.put("out_order_no", request.outOrderNo);
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, QueryOrderResponse.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 QueryOrder(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 QueryOrderRequest {
104    @SerializedName("sub_mchid")
105    @Expose(serialize = false)
106    public String subMchid;
107  
108    @SerializedName("transaction_id")
109    @Expose(serialize = false)
110    public String transactionId;
111  
112    @SerializedName("out_order_no")
113    @Expose(serialize = false)
114    public String outOrderNo;
115  }
116  
117  public static class QueryOrderResponse {
118    @SerializedName("sub_mchid")
119    public String subMchid;
120  
121    @SerializedName("transaction_id")
122    public String transactionId;
123  
124    @SerializedName("out_order_no")
125    public String outOrderNo;
126  
127    @SerializedName("order_id")
128    public String orderId;
129  
130    @SerializedName("status")
131    public String status;
132  
133    @SerializedName("receivers")
134    public List<ReceiverResultEntity> receivers = new ArrayList<ReceiverResultEntity>();
135  
136    @SerializedName("finish_amount")
137    public Long finishAmount;
138  
139    @SerializedName("finish_description")
140    public String finishDescription;
141  }
142  
143  public static class ReceiverResultEntity {
144    @SerializedName("type")
145    public String type;
146  
147    @SerializedName("account")
148    public String account;
149  
150    @SerializedName("amount")
151    public Long amount;
152  
153    @SerializedName("description")
154    public String description;
155  
156    @SerializedName("result")
157    public String result;
158  
159    @SerializedName("finish_time")
160    public String finishTime;
161  
162    @SerializedName("fail_reason")
163    public String failReason;
164  
165    @SerializedName("detail_id")
166    public String detailId;
167  }
168  
169}
170

应答参数

200 OK

 sub_mchid  必填   string

【子商户号】 订单收款方商户号,可以是品牌主商户号,也可以是门店商户号,填写微信支付分配的商户号。


 transaction_id  必填   string

【微信订单号】 微信支付订单号


 out_order_no  必填   string

【商户分账单号】 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次,只能是数字、大小写字母_-|*@。


 order_id  必填   string

【微信分账单号】 微信分账单号,微信系统返回的唯一标识


 status  必填   string

【分账单状态】 分账单状态(每个接收方的分账结果请查看receivers中的result字段),枚举值:

  • PROCESSING:处理中 

  • FINISHED:分账完成


 receivers  必填   array[object]

【分账接收方列表】 分账接收方列表

属性

 finish_amount  选填   integer

【分账完结金额】 分账完结的分账金额,单位为分, 仅当查询分账完结的执行结果时,存在本字段


 finish_description  选填   string

【分账完结描述】 分账完结的原因描述,仅当查询分账完结的执行结果时,存在本字段

应答示例

200 OK

1{
2  "sub_mchid" : "1900000109",
3  "transaction_id" : "4208450740201411110007820472",
4  "out_order_no" : "P20150806125346",
5  "order_id" : "3008450740201411110007820472",
6  "status" : "FINISHED",
7  "receivers" : [
8    {
9      "type" : "MERCHANT_ID",
10      "account" : "1900000109",
11      "amount" : 10,
12      "description" : "分帐1900000110",
13      "result" : "SUCCESS",
14      "finish_time" : "2015-05-20T13:29:35.120+08:00",
15      "fail_reason" : "NO_RELATION",
16      "detail_id" : "36011111111111111111111"
17    }
18  ],
19  "finish_amount" : 100,
20  "finish_description" : "分账完结"
21}
22

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

请根据错误提示正确传入参数

400

INVALID_REQUEST

HTTP 请求不符合微信支付 APIv3 接口规则

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

更多技术问题
技术咨询
反馈
咨询
目录
置顶