完结分账

更新时间:2025.08.21

不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给分账方商户



注意:

  1. 调用分账接口后,需要解冻剩余资金时,调用本接口将订单剩余的分账金额全部解冻给分账方商户。

接口说明

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

请求方式:【POST】/v3/brand/profitsharing/finish-order

请求域名:【主域名】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  包体参数

 sub_mchid  必填   string(32)

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


 transaction_id  必填   string(32)

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


 out_order_no  必填   string(64)

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


 description  必填   string(80)

【分账描述】 分账的原因描述,分账账单中需要体现

请求示例

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 FinishOrder {
26  private static String HOST = "https://api.mch.weixin.qq.com";
27  private static String METHOD = "POST";
28  private static String PATH = "/v3/brand/profitsharing/finish-order";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    FinishOrder client = new FinishOrder(
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    FinishOrderRequest request = new FinishOrderRequest();
41    request.subMchid = "1900000109";
42    request.transactionId = "4208450740201411110007820472";
43    request.outOrderNo = "P20150806125346";
44    request.description = "分账完结";
45    try {
46      FinishOrderResponse 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 FinishOrderResponse run(FinishOrderRequest 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, FinishOrderResponse.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 FinishOrder(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 FinishOrderRequest {
103    @SerializedName("sub_mchid")
104    public String subMchid;
105  
106    @SerializedName("transaction_id")
107    public String transactionId;
108  
109    @SerializedName("out_order_no")
110    public String outOrderNo;
111  
112    @SerializedName("description")
113    public String description;
114  }
115  
116  public static class FinishOrderResponse {
117    @SerializedName("sub_mchid")
118    public String subMchid;
119  
120    @SerializedName("transaction_id")
121    public String transactionId;
122  
123    @SerializedName("out_order_no")
124    public String outOrderNo;
125  
126    @SerializedName("order_id")
127    public String orderId;
128  }
129  
130}
131

应答参数

200 OK

 sub_mchid  必填   string

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


 transaction_id  必填   string

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


 out_order_no  必填   string

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


 order_id  必填   string

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

应答示例

200 OK

1{
2  "sub_mchid" : "1900000109",
3  "transaction_id" : "4208450740201411110007820472",
4  "out_order_no" : "P20150806125346",
5  "order_id" : "3008450740201411110007820472"
6}
7

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

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

400

INVALID_REQUEST

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

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

 

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