查询订单剩余待分金额

更新时间:2025.08.21

可调用此接口查询订单剩余待分金额

接口说明

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

请求方式:【GET】/v3/brand/profitsharing/orders/{transaction_id}/amounts

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

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

请求参数

Header  HTTP头参数

 Authorization  必填 string

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


 Accept  必填 string

请设置为application/json


path  路径参数

 transaction_id  必填   string(32)

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

请求示例

Java
Go
curl

需配合微信支付工具库 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 QueryOrderAmount {
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/{transaction_id}/amounts";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    QueryOrderAmount client = new QueryOrderAmount(
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    QueryOrderAmountRequest request = new QueryOrderAmountRequest();
41    request.transactionId = "4208450740201411110007820472";
42    try {
43      QueryOrderAmountResponse response = client.run(request);
44
45      // TODO: 请求成功,继续业务逻辑
46      System.out.println(response);
47    } catch (WXPayUtility.ApiException e) {
48      // TODO: 请求失败,根据状态码执行不同的逻辑
49      e.printStackTrace();
50    }
51  }
52
53  public QueryOrderAmountResponse run(QueryOrderAmountRequest request) {
54    String uri = PATH;
55    uri = uri.replace("{transaction_id}", WXPayUtility.urlEncode(request.transactionId));
56
57    Request.Builder reqBuilder = new Request.Builder().url(HOST + uri);
58    reqBuilder.addHeader("Accept", "application/json");
59    reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId);
60    reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null));
61    reqBuilder.method(METHOD, null);
62    Request httpRequest = reqBuilder.build();
63
64    // 发送HTTP请求
65    OkHttpClient client = new OkHttpClient.Builder().build();
66    try (Response httpResponse = client.newCall(httpRequest).execute()) {
67      String respBody = WXPayUtility.extractBody(httpResponse);
68      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
69        // 2XX 成功,验证应答签名
70        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
71            httpResponse.headers(), respBody);
72
73        // 从HTTP应答报文构建返回数据
74        return WXPayUtility.fromJson(respBody, QueryOrderAmountResponse.class);
75      } else {
76        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
77      }
78    } catch (IOException e) {
79      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
80    }
81  }
82
83  private final String mchid;
84  private final String certificateSerialNo;
85  private final PrivateKey privateKey;
86  private final String wechatPayPublicKeyId;
87  private final PublicKey wechatPayPublicKey;
88
89  public QueryOrderAmount(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
90    this.mchid = mchid;
91    this.certificateSerialNo = certificateSerialNo;
92    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
93    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
94    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
95  }
96
97  public static class QueryOrderAmountRequest {
98    @SerializedName("transaction_id")
99    @Expose(serialize = false)
100    public String transactionId;
101  }
102  
103  public static class QueryOrderAmountResponse {
104    @SerializedName("transaction_id")
105    public String transactionId;
106  
107    @SerializedName("unsplit_amount")
108    public Long unsplitAmount;
109  }
110  
111}
112

应答参数

200 OK

 transaction_id  必填   string(32)

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


 unsplit_amount  必填   integer

【订单剩余待分金额】 订单剩余待分金额,整数,单元为分

应答示例

200 OK

1{
2  "transaction_id" : "4208450740201411110007820472",
3  "unsplit_amount" : 1000
4}
5

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

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

400

INVALID_REQUEST

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

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

 

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