请求分账回退

更新时间:2025.08.21

如果订单已经分账,在退款时,可以先调此接口,将已分账的资金从商户类型的分账接收方的账户回退给分账方,再发起退款。



注意:

  1. 分账回退以原分账单为依据,支持多次回退,申请回退总金额不能超过原分账单分给该接收方的金额。

  2. 此接口采用同步处理模式,即在接收到商户请求后,会实时返回处理结果。

  3. 退款和分账回退没有耦合,分账回退可以先于退款请求,也可以后于退款请求。

  4. 对同一笔分账单最多能发起50次分账回退请求。

  5. 不支持针对“分账到零钱”的分账单发起分账回退。

  6. 分账回退的时限是180天。

接口说明

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

请求方式:【POST】/v3/brand/profitsharing/returnorders

请求域名:【主域名】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)

【子商户号】 分账回退的接收商户,对应原分账出资的分账方商户,填写微信支付分配的商户号


 order_id  选填   string(64)

【微信分账单号】 微信分账单号,微信系统返回的唯一标识。微信分账单号和商户分账单号二选一填写


 out_order_no  选填   string(64)

【商户分账单号】 商户系统内部的分账单号,在商户系统内部唯一(单次分账、多次分账、完结分账应使用不同的商户分账单号),同一分账单号多次请求等同一次。微信分账单号和商户分账单号二选一填写 取值范围:[0-9a-zA-Z_*@-]


 out_return_no  必填   string(64)

【商户回退单号】 此回退单号是商户在自己后台生成的一个新的回退单号,在商户后台唯一


 return_mchid  必填   string(32)

【回退商户号】 分账回退的出资商户,只能对原分账请求中成功分给商户接收方进行回退


 amount  必填   integer

【回退金额】 需要从分账接收方回退的金额,单位为分,只能为整数,不能超过原始分账单分出给该接收方的金额


 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 CreateReturnOrder {
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/returnorders";
29
30  public static void main(String[] args) {
31    // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340
32    CreateReturnOrder client = new CreateReturnOrder(
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    CreateReturnOrderRequest request = new CreateReturnOrderRequest();
41    request.subMchid = "1900000109";
42    request.orderId = "3008450740201411110007820472";
43    request.outOrderNo = "P20150806125346";
44    request.outReturnNo = "R20190516001";
45    request.returnMchid = "R20190516001";
46    request.amount = 10L;
47    request.description = "分账回退";
48    try {
49      CreateReturnOrderResponse response = client.run(request);
50
51      // TODO: 请求成功,继续业务逻辑
52      System.out.println(response);
53    } catch (WXPayUtility.ApiException e) {
54      // TODO: 请求失败,根据状态码执行不同的逻辑
55      e.printStackTrace();
56    }
57  }
58
59  public CreateReturnOrderResponse run(CreateReturnOrderRequest request) {
60    String uri = PATH;
61    String reqBody = WXPayUtility.toJson(request);
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, reqBody));
67    reqBuilder.addHeader("Content-Type", "application/json");
68    RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody);
69    reqBuilder.method(METHOD, requestBody);
70    Request httpRequest = reqBuilder.build();
71
72    // 发送HTTP请求
73    OkHttpClient client = new OkHttpClient.Builder().build();
74    try (Response httpResponse = client.newCall(httpRequest).execute()) {
75      String respBody = WXPayUtility.extractBody(httpResponse);
76      if (httpResponse.code() >= 200 && httpResponse.code() < 300) {
77        // 2XX 成功,验证应答签名
78        WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey,
79            httpResponse.headers(), respBody);
80
81        // 从HTTP应答报文构建返回数据
82        return WXPayUtility.fromJson(respBody, CreateReturnOrderResponse.class);
83      } else {
84        throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers());
85      }
86    } catch (IOException e) {
87      throw new UncheckedIOException("Sending request to " + uri + " failed.", e);
88    }
89  }
90
91  private final String mchid;
92  private final String certificateSerialNo;
93  private final PrivateKey privateKey;
94  private final String wechatPayPublicKeyId;
95  private final PublicKey wechatPayPublicKey;
96
97  public CreateReturnOrder(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) {
98    this.mchid = mchid;
99    this.certificateSerialNo = certificateSerialNo;
100    this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath);
101    this.wechatPayPublicKeyId = wechatPayPublicKeyId;
102    this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath);
103  }
104
105  public static class CreateReturnOrderRequest {
106    @SerializedName("sub_mchid")
107    public String subMchid;
108  
109    @SerializedName("order_id")
110    public String orderId;
111  
112    @SerializedName("out_order_no")
113    public String outOrderNo;
114  
115    @SerializedName("out_return_no")
116    public String outReturnNo;
117  
118    @SerializedName("return_mchid")
119    public String returnMchid;
120  
121    @SerializedName("amount")
122    public Long amount;
123  
124    @SerializedName("description")
125    public String description;
126  }
127  
128  public static class CreateReturnOrderResponse {
129    @SerializedName("sub_mchid")
130    public String subMchid;
131  
132    @SerializedName("order_id")
133    public String orderId;
134  
135    @SerializedName("out_order_no")
136    public String outOrderNo;
137  
138    @SerializedName("out_return_no")
139    public String outReturnNo;
140  
141    @SerializedName("return_mchid")
142    public String returnMchid;
143  
144    @SerializedName("amount")
145    public Long amount;
146  
147    @SerializedName("return_no")
148    public String returnNo;
149  
150    @SerializedName("result")
151    public String result;
152  
153    @SerializedName("fail_reason")
154    public String failReason;
155  
156    @SerializedName("finish_time")
157    public String finishTime;
158  }
159  
160}
161

应答参数

200 OK

 sub_mchid  必填   string

【子商户号】 分账回退的接收商户,对应原分账出资的分账方商户,填写微信支付分配的商户号。


 order_id  必填   string

【微信分账单号】 参考请求参数


 out_order_no  必填   string

【商户分账单号】 参考请求参数


 out_return_no  必填   string

【商户回退单号】 此回退单号是商户在自己后台生成的一个新的回退单号,在商户后台唯一 只能是数字、大小写字母_-*@ ,同一回退单号多次请求等同一次。


 return_mchid  必填   string

【回退商户号】 回退商户号只能填写原分账请求中接收分账的商户号。


 amount  必填   integer

【回退金额】 需要从分账接收方回退的金额,单位为分,只能为整数,不能超过原始分账单分出给该接收方的金额


 return_no  必填   string

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


 result  必填   string

【回退结果】 如果请求返回为处理中,则商户可以通过调用回退结果查询接口获取请求的最终处理结果。如果返回为处理中,请勿变更商户回退单号,使用相同的参数再次发起分账回退,否则会出现资金风险。在处理中状态的回退单如果5天没有成功,会因为超时被设置为已失败
枚举值: 

  • PROCESSING:处理中 

  • SUCCESS:已成功 

  • FAIL:已失败


 fail_reason  选填   string

【失败原因】 回退失败的原因,此字段仅回退结果为FAIL时存在,枚举值:

  • ACCOUNT_ABNORMAL:原分账接收方账户异常

  • TIME_OUT_CLOSED:超时关单

  • PAYER_ACCOUNT_ABNORMAL: 原分账分出方账户异常


 finish_time  必填   string

【完成时间】 分账回退完成时间,遵循RFC3339标准格式,格式为
yyyy-MM-DDTHH:mm:ss.sss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss.sss表示时分秒毫秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35:120+08:00表示北京时间2015年05月20日13点29分35秒。

应答示例

200 OK

1{
2  "sub_mchid" : "1900000109",
3  "order_id" : "3008450740201411110007820472",
4  "out_order_no" : "P20150806125346",
5  "out_return_no" : "R20190516001",
6  "return_mchid" : "86693852",
7  "amount" : 10,
8  "return_no" : "3008450740201411110007820472",
9  "result" : "SUCCESS",
10  "fail_reason" : "TIME_OUT_CLOSED",
11  "finish_time" : "2015-05-20T13:29:35.120+08:00"
12}
13

 

错误码

公共错误码

状态码

错误码

描述

解决方案

400

PARAM_ERROR

参数错误

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

400

INVALID_REQUEST

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

请参阅 接口规则

401

SIGN_ERROR

验证不通过

请参阅 签名常见问题

500

SYSTEM_ERROR

系统异常,请稍后重试

请稍后重试

 

 

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