开发指引

更新时间:2024.11.15

1. 接口规则

为了在保证支付安全的前提下,带给商户简单、一致且易用的开发体验,我们推出了全新的微信支付APIv3接口。该版本API的具体规则请参考APIv3接口规则

2. 开发准备

2.1. 搭建和配置开发环境

开发者应当依据自身的编程语言来构建并配置相应的开发环境。

2.2. 业务开发配置

2.2.1. 服务商开通连锁品牌工具箱

服务商可登录【服务商平台-合作工具箱】申请开通【连锁品牌工具箱】。进行品牌申请、查看品牌申请进度、邀请品牌总部授权、品牌门店管理、品牌流量场景管理等日常管理。

2.2.2. 设置分账比例

连锁工具箱开通后,品牌主在商户平台进入:“品牌专区-品牌交易-品牌供应链分账-供应链分账管理”中可进行分账比例的调整。

3. 快速接入

3.1. 业务流程图

重点步骤说明:

步骤4 分账前需调用《添加分账接收方》接口添加分账接收方。

步骤6 分账订单发起分账需调用《请求分账》接口进行分账,微信支付将会把结算资金分给分账接收方。

步骤8 分账完成后,微信会通过《分账动账通知》接口,主动通知商户。商户也可以通过《查询分账结果》接口,主动查询分账结果。

步骤12 分账后若产生退款,则需先调用《请求分账回退》接口,请求将已经分给分账方的资金回退,再处理退款。

步骤13 分账回退完成后,微信同样会通过《分账动账通知》接口,主动通知商户。商户也可以通过《查询分账回退结果》接口,主动查询分账结果。

步骤17 分账结束后,商户需调用《完结分账》接口结束分账订单。

3.2. API接入(含示例代码)

文档展示了如何使用微信支付服务端 SDK 快速接入连锁品牌分账产品,完成与微信支付对接的部分。

注意

  • 文档中的代码示例是用来阐述 API 基本使用方法,代码中的示例参数需替换成商户自己账号及请求参数才能跑通

  • 以下接入步骤仅提供参考,请商户结合自身业务需求进行评估、修改。

3.2.1. 【服务端】请求分账

步骤说明:微信订单支付成功后,由服务商发起分账请求,将结算后的资金分给分账接收方。

示例代码

JAVA

1public void ProfitSharing() throws Exception{
2    //请求URL
3    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders");
4    // 请求body参数
5    String reqdata = "{"
6            + "\"brand_mchid\":\"1900000108\","
7            + "\"sub_mchid\":\"1900000109\","
8            + "\"appid\":\"wx8888888888888888\","
9            + "\"sub_appid\":\"wx8888888888888889\","
10            + "\"transaction_id\":\"4208450740201411110007820472\","
11            + "\"out_order_no\":\"P20150806125346\","
12            + "\"receivers\": ["
13            + "{"
14            + "\"type\":\"MERCHANT_ID\","
15            + "\"account\":\"1900000110\","
16            + "\"amount\":100,"
17            + "\"description\":\"1900000109分给商户1900000110\""
18            + "}"
19            + "],"
20            + "\"finish\":true"
21            + "}";
22    StringEntity entity = new StringEntity(reqdata,"utf-8");
23    entity.setContentType("application/json");
24    httpPost.setEntity(entity);
25    httpPost.setHeader("Accept", "application/json");
26
27    //完成签名并执行请求
28    CloseableHttpResponse response = httpClient.execute(httpPost);
29
30    try {
31        int statusCode = response.getStatusLine().getStatusCode();
32        if (statusCode == 200) { //处理成功
33            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
34        } else if (statusCode == 204) { //处理成功,无返回Body
35            System.out.println("success");
36        } else {
37            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
38            throw new IOException("request failed");
39        }
40    } finally {
41        response.close();
42    }
43}

PHP

1try {
2    $resp = $client->request(
3        'POST',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders', //请求URL
5        [
6            // JSON请求体
7            'json' => [
8                "brand_mchid" => "1900000108", 
9                "sub_mchid" => "1900000109", 
10                "appid" => "wx8888888888888888", 
11                "sub_appid" => "wx8888888888888889", 
12                "transaction_id" => "4208450740201411110007820472", 
13                "out_order_no" => "P20150806125346", 
14                "receivers" => [
15                    [
16                        "type" => "MERCHANT_ID", 
17                        "account" => "1900000110", 
18                        "amount" => 100, 
19                        "description" => "1900000109分给商户1900000110", 
20                    ],
21                ],
22                "finish" => true,
23            ],
24            'headers' => [ 'Accept' => 'application/json' ]
25        ]
26    );
27    $statusCode = $resp->getStatusCode();
28    if ($statusCode == 200) { //处理成功
29        echo "success,return body = " . $resp->getBody()->getContents()."\n";
30    } else if ($statusCode == 204) { //处理成功,无返回Body
31        echo "success";
32    }
33} catch (RequestException $e) {
34    // 进行错误处理
35    echo $e->getMessage()."\n";
36    if ($e->hasResponse()) {
37        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
38    }
39    return;
40}

重要入参说明:

  • brand_mchid:品牌主商户号,填写微信支付分配的商户号。

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

  • AppID:公众账号ID,微信分配的公众账号ID,这里指服务商的AppID。

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

更多参数、响应详情及错误码请参见请求分账接口文档。

3.2.2. 【服务端】查询分账结果

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

示例代码

JAVA

1public void QueryProfitSharing() throws Exception{
2    //请求URL
3    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders?sub_mchid=1900000109&transaction_id=4208450740201411110007820472&out_order_no=P20150806125346");
4    httpGet.setHeader("Accept", "application/json");
5    //完成签名并执行请求
6    CloseableHttpResponse response = httpClient.execute(httpGet);
7    try {
8        int statusCode = response.getStatusLine().getStatusCode();
9        if (statusCode == 200) { //处理成功
10            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
11        } else if (statusCode == 204) { //处理成功,无返回Body
12            System.out.println("success");
13        } else {
14            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
15            throw new IOException("request failed");
16        }
17    } finally {
18        response.close();
19    }
20}

PHP

1try {
2    $resp = $client->request(
3        'GET',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders?sub_mchid=1900000109&transaction_id=4208450740201411110007820472&out_order_no=P20150806125346', //请求URL
5        [
6            'headers' => [ 'Accept' => 'application/json']
7        ]
8    );
9    $statusCode = $resp->getStatusCode();
10    if ($statusCode == 200) { //处理成功
11        echo "success,return body = " . $resp->getBody()->getContents()."\n";
12    } else if ($statusCode == 204) { //处理成功,无返回Body
13        echo "success";
14    }
15} catch (RequestException $e) {
16    // 进行错误处理
17    echo $e->getMessage()."\n";
18    if ($e->hasResponse()) {
19        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
20    }
21    return;
22}

重要入参说明:

  • transaction_id:微信订单号, 微信支付订单号。

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

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

更多参数、响应详情及错误码请参见查询分账结果接口文档。

3.2.3. 【服务端】分账动账通知

步骤说明: 此功能仅针对分账接收方,当分账动账金额发生变动时,微信会把相关变动结果发送给需要实时关注的分账接收方。

注意

  • 分账动账通知是以POST 方法访问商户设置的通知URL,通知的数据以JSON 格式通过请求主体(BODY)传输。通知的数据包括了加密的支付结果详情。

  • 加密不能保证通知请求来自微信。微信会对发送给商户的通知进行签名,并将签名值放在通知的HTTP头Wechatpay-Signature。商户应当验证签名,以确认请求来自微信,而不是其他的第三方。签名验证的算法请参考《微信支付API v3签名验证》

  • 分账动账通知HTTP应答码为200或204才会当作正常接收,当回调处理异常时,应答的HTTP状态码应为500,或者4xx。

  • 商户成功接收到回调通知后应返回成功的HTTP应答码为200或204。

  • 同样的通知可能会多次发送给商户系统。商户系统必须能够正确处理重复的通知。 推荐的做法是,当商户系统收到通知进行处理时,先检查对应业务数据的状态,并判断该通知是否已经处理。如果未处理,则再进行处理;如果已处理,则直接返回结果成功。在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱。

更多参数、响应详情及错误码请参见分账动账通知接口文档。

3.2.4. 【服务端】请求分账回退

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

示例代码

JAVA

1public void ReturnProfitSharing() throws Exception{
2    //请求URL
3    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/brand/profitsharing/returnorders");
4    // 请求body参数
5    String reqdata = "{"
6            + "\"sub_mchid\":\"1900000109\","
7            + "\"order_id\":\"3008450740201411110007820472\","
8            + "\"out_order_no\":\"P20150806125346\","
9            + "\"out_return_no\":\"R20190516001\","
10            + "\"return_mchid\":\"86693852\","
11            + "\"amount\":10,"
12            + "\"description\":\"分账回退\""
13            + "}";
14    StringEntity entity = new StringEntity(reqdata,"utf-8");
15    entity.setContentType("application/json");
16    httpPost.setEntity(entity);
17    httpPost.setHeader("Accept", "application/json");
18    //完成签名并执行请求
19    CloseableHttpResponse response = httpClient.execute(httpPost);
20    try {
21        int statusCode = response.getStatusLine().getStatusCode();
22        if (statusCode == 200) { //处理成功
23            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
24        } else if (statusCode == 204) { //处理成功,无返回Body
25            System.out.println("success");
26        } else {
27            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
28            throw new IOException("request failed");
29        }
30    } finally {
31        response.close();
32    }
33}

PHP

1try {
2    $resp = $client->request(
3        'POST',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/returnorders', //请求URL
5        [
6            // JSON请求体
7            'json' => [
8                "sub_mchid" => "1900000109", 
9                "order_id" => "3008450740201411110007820472", 
10                "out_order_no" => "P20150806125346", 
11                "out_return_no" => "R20190516001", 
12                "return_mchid" => "86693852", 
13                "amount" => 10, 
14                "description" => "分账回退",
15            ],
16            'headers' => [ 'Accept' => 'application/json' ]
17        ]
18    );
19    $statusCode = $resp->getStatusCode();
20    if ($statusCode == 200) { //处理成功
21        echo "success,return body = " . $resp->getBody()->getContents()."\n";
22    } else if ($statusCode == 204) { //处理成功,无返回Body
23        echo "success";
24    }
25} catch (RequestException $e) {
26    // 进行错误处理
27    echo $e->getMessage()."\n";
28    if ($e->hasResponse()) {
29        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
30    }
31    return;
32}

重要入参说明:

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

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

  • out_return_no:商户回退单号,此回退单号是商户在自己后台生成的一个新的回退单号,在商户后台唯一,只能是数字、大小写字母_-|*@。

  • return_mchid:回退商户号,回退商户号只能填写原分账请求中接收分账的商户号。

更多参数、响应详情及错误码请参见请求分账回退接口文档。

3.2.5. 【服务端】查询分账回退结果

步骤说明:商户需要核实回退结果,可调用此接口查询回退结果。如果分账回退接口返回状态为处理中,可调用此接口查询回退结果。

示例代码

JAVA

1public void QueryReturnOrder() throws Exception{
2    //请求URL
3    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/brand/profitsharing/returnorders?sub_mchid=1900000109&out_return_no=R20190516001&order_id=4208450740201411110007820472");
4    httpGet.setHeader("Accept", "application/json");
5    //完成签名并执行请求
6    CloseableHttpResponse response = httpClient.execute(httpGet);
7    try {
8        int statusCode = response.getStatusLine().getStatusCode();
9        if (statusCode == 200) { //处理成功
10            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
11        } else if (statusCode == 204) { //处理成功,无返回Body
12            System.out.println("success");
13        } else {
14            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
15            throw new IOException("request failed");
16        }
17    } finally {
18        response.close();
19    }
20}

PHP

1try {
2    $resp = $client->request(
3        'GET',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/returnorders?sub_mchid=1900000109&out_return_no=R20190516001&order_id=4208450740201411110007820472', //请求URL
5        [
6            'headers' => [ 'Accept' => 'application/json']
7        ]
8    );
9    $statusCode = $resp->getStatusCode();
10    if ($statusCode == 200) { //处理成功
11        echo "success,return body = " . $resp->getBody()->getContents()."\n";
12    } else if ($statusCode == 204) { //处理成功,无返回Body
13        echo "success";
14    }
15} catch (RequestException $e) {
16    // 进行错误处理
17    echo $e->getMessage()."\n";
18    if ($e->hasResponse()) {
19        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
20    }
21    return;
22}

重要入参说明:

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

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

  • out_return_no:商户回退单号,调用回退接口提供的商户系统内部的回退单号。

更多参数、响应详情及错误码请参见查询分账回退结果接口文档。

3.2.6. 【服务端】完结分账

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

示例代码

JAVA

1public void FinishProfitSharing() throws Exception{
2    //请求URL
3    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/brand/profitsharing/finish-order");
4    // 请求body参数
5    String reqdata = "{"
6            + "\"sub_mchid\":\"1900000109\","
7            + "\"transaction_id\":\"4208450740201411110007820472\","
8            + "\"out_order_no\":\"P20150806125346\","
9            + "\"description\":\"分账完结\""
10            + "}";
11    StringEntity entity = new StringEntity(reqdata,"utf-8");
12    entity.setContentType("application/json");
13    httpPost.setEntity(entity);
14    httpPost.setHeader("Accept", "application/json");
15    //完成签名并执行请求
16    CloseableHttpResponse response = httpClient.execute(httpPost);
17    try {
18        int statusCode = response.getStatusLine().getStatusCode();
19        if (statusCode == 200) { //处理成功
20            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
21        } else if (statusCode == 204) { //处理成功,无返回Body
22            System.out.println("success");
23        } else {
24            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
25            throw new IOException("request failed");
26        }
27    } finally {
28        response.close();
29    }
30}

PHP

1try {
2    $resp = $client->request(
3        'POST',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/finish-order', //请求URL
5        [
6            // JSON请求体
7            'json' => [
8                "sub_mchid" => "1900000109", 
9                "transaction_id" => "4208450740201411110007820472", 
10                "out_order_no" => "P20150806125346", 
11                "description" => "分账完结",
12            ],
13            'headers' => [ 'Accept' => 'application/json' ]
14        ]
15    );
16    $statusCode = $resp->getStatusCode();
17    if ($statusCode == 200) { //处理成功
18        echo "success,return body = " . $resp->getBody()->getContents()."\n";
19    } else if ($statusCode == 204) { //处理成功,无返回Body
20        echo "success";
21    }
22} catch (RequestException $e) {
23    // 进行错误处理
24    echo $e->getMessage()."\n";
25    if ($e->hasResponse()) {
26        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
27    }
28    return;
29}

重要入参说明:

  • transaction_id:微信订单号, 微信支付订单号。

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

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

更多参数、响应详情及错误码请参见完结分账接口文档。

3.2.7. 【服务端】查询订单剩余待分金额

步骤说明: 可调用此接口查询订单剩余待分金额。

示例代码

JAVA

1public void QueryRemainAmounts() throws Exception{
2    //请求URL
3    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders/4208450740201411110007820472/amounts");
4    httpGet.setHeader("Accept", "application/json");
5    //完成签名并执行请求
6    CloseableHttpResponse response = httpClient.execute(httpGet);
7    try {
8        int statusCode = response.getStatusLine().getStatusCode();
9        if (statusCode == 200) { //处理成功
10            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
11        } else if (statusCode == 204) { //处理成功,无返回Body
12            System.out.println("success");
13        } else {
14            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
15            throw new IOException("request failed");
16        }
17    } finally {
18        response.close();
19    }
20}

PHP

1try {
2    $resp = $client->request(
3        'GET',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/orders/4208450740201411110007820472/amounts', //请求URL
5        [
6            'headers' => [ 'Accept' => 'application/json']
7        ]
8    );
9    $statusCode = $resp->getStatusCode();
10    if ($statusCode == 200) { //处理成功
11        echo "success,return body = " . $resp->getBody()->getContents()."\n";
12    } else if ($statusCode == 204) { //处理成功,无返回Body
13        echo "success";
14    }
15} catch (RequestException $e) {
16    // 进行错误处理
17    echo $e->getMessage()."\n";
18    if ($e->hasResponse()) {
19        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
20    }
21    return;
22}

重要入参说明:

  • transaction_id:微信订单号, 微信支付订单号。

更多参数、响应详情及错误码请参见查询订单剩余待分金额接口文档。

3.2.8. 【服务端】查询最大分账比例

步骤说明: 服务商可通过此接口添加分账接收方,建立分账接收方列表。连锁加盟模式下,服务商添加的分账接收方统一在品牌主商户号维度进行管理。

示例代码

JAVA

1public void QueryBrandConfigs() throws Exception{
2    //请求URL
3    HttpGet httpGet = new HttpGet("https://api.mch.weixin.qq.com/v3/brand/profitsharing/brand-configs/1900000109");
4    httpGet.setHeader("Accept", "application/json");
5    //完成签名并执行请求
6    CloseableHttpResponse response = httpClient.execute(httpGet);
7    try {
8        int statusCode = response.getStatusLine().getStatusCode();
9        if (statusCode == 200) { //处理成功
10            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
11        } else if (statusCode == 204) { //处理成功,无返回Body
12            System.out.println("success");
13        } else {
14            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
15            throw new IOException("request failed");
16        }
17    } finally {
18        response.close();
19    }
20}

PHP

1try {
2    $resp = $client->request(
3        'GET',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/brand-configs/1900000109', //请求URL
5        [
6            'headers' => [ 'Accept' => 'application/json']
7        ]
8    );
9    $statusCode = $resp->getStatusCode();
10    if ($statusCode == 200) { //处理成功
11        echo "success,return body = " . $resp->getBody()->getContents()."\n";
12    } else if ($statusCode == 204) { //处理成功,无返回Body
13        echo "success";
14    }
15} catch (RequestException $e) {
16    // 进行错误处理
17    echo $e->getMessage()."\n";
18    if ($e->hasResponse()) {
19        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
20    }
21    return;
22}

重要入参说明:

  • brand_mchid:品牌主商户号,通过微信支付认证的品牌主商户号,填写微信支付分配的商户号。

更多参数、响应详情及错误码请参见查询最大分账比例接口文档。

3.2.9. 【服务端】添加分账接收方

步骤说明: 服务商可通过此接口添加分账接收方,建立分账接收方列表。连锁加盟模式下,服务商添加的分账接收方统一在品牌主商户号维度进行管理。

示例代码

JAVA

1public void AddReceivers() throws Exception{
2    //请求URL
3    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/brand/profitsharing/receivers/add");
4    // 请求body参数
5    String reqdata = "{"
6            + "\"brand_mchid\":\"1900000108\","
7            + "\"appid\":\"wx8888888888888888\","
8            + "\"sub_appid\":\"wx8888888888888889\","
9            + "\"type\":\"MERCHANT_ID\","
10            + "\"account\":\"1900000109\","
11            + "\"name\":\"张三网络公司\","
12            + "\"relation_type\":\"SUPPLIER\""
13            + "}";
14    StringEntity entity = new StringEntity(reqdata,"utf-8");
15    entity.setContentType("application/json");
16    httpPost.setEntity(entity);
17    httpPost.setHeader("Accept", "application/json");
18    //完成签名并执行请求
19    CloseableHttpResponse response = httpClient.execute(httpPost);
20    try {
21        int statusCode = response.getStatusLine().getStatusCode();
22        if (statusCode == 200) { //处理成功
23            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
24        } else if (statusCode == 204) { //处理成功,无返回Body
25            System.out.println("success");
26        } else {
27            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
28            throw new IOException("request failed");
29        }
30    } finally {
31        response.close();
32    }
33}

PHP

1try {
2    $resp = $client->request(
3        'POST',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/receivers/add', //请求URL
5        [
6            // JSON请求体
7            'json' => [
8                "brand_mchid" => "1900000108", 
9                "appid" => "wx8888888888888888", 
10                "sub_appid" => "wx8888888888888889", 
11                "type" => "MERCHANT_ID", 
12                "account" => "1900000109", 
13                "name" => "张三网络公司", 
14                "relation_type" => "SUPPLIER",
15            ],
16            'headers' => [ 'Accept' => 'application/json' ]
17        ]
18    );
19    $statusCode = $resp->getStatusCode();
20    if ($statusCode == 200) { //处理成功
21        echo "success,return body = " . $resp->getBody()->getContents()."\n";
22    } else if ($statusCode == 204) { //处理成功,无返回Body
23        echo "success";
24    }
25} catch (RequestException $e) {
26    // 进行错误处理
27    echo $e->getMessage()."\n";
28    if ($e->hasResponse()) {
29        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
30    }
31    return;
32}

重要入参说明:

  • brand_mchid:品牌主商户号,通过微信支付认证的品牌主商户号,填写微信支付分配的商户号。

  • AppID:公众账号ID,微信分配的公众账号ID,这里指服务商的AppID。

  • type:分账接收方类型,枚举值:

    • MERCHANT_ID:商户号(mch_id或者sub_mch_id)

    • PERSONAL_OPENID:个人OpenID(由服务商的AppID转换得到)

    • PERSONAL_SUB_OPENID:个人sub_openid(由品牌主的AppID转换得到)

  • account:分账接收方账号:

    • 分账接收方类型为:MERCHANT_ID时,分账接收方账号为商户号(mch_id或者sub_mch_id)

    • 分账接收方类型为:PERSONAL_OPENID时,分账接收方账号为个人OpenID

    • 分账接收方类型为:PESONAL_SUB_OPENID时,分账接收方账号为个人sub_openid

更多参数、响应详情及错误码请参见添加分账接收方接口文档。

3.2.10. 【服务端】删除分账接收方

步骤说明: 服务商发起删除分账接收方请求。删除后,不再支持品牌主或门店分到该分账接收方。

示例代码

JAVA

1public void DelReceivers() throws Exception{
2    //请求URL
3    HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/brand/profitsharing/receivers/delete");
4    // 请求body参数
5    String reqdata = "{"
6            + "\"brand_mchid\":\"1900000108\","
7            + "\"appid\":\"wx8888888888888888\","
8            + "\"sub_appid\":\"wx8888888888888889\","
9            + "\"type\":\"MERCHANT_ID\","
10            + "\"account\":\"1900000109\""
11            + "}";
12    StringEntity entity = new StringEntity(reqdata,"utf-8");
13    entity.setContentType("application/json");
14    httpPost.setEntity(entity);
15    httpPost.setHeader("Accept", "application/json");
16    //完成签名并执行请求
17    CloseableHttpResponse response = httpClient.execute(httpPost);
18    try {
19        int statusCode = response.getStatusLine().getStatusCode();
20        if (statusCode == 200) { //处理成功
21            System.out.println("success,return body = " + EntityUtils.toString(response.getEntity()));
22        } else if (statusCode == 204) { //处理成功,无返回Body
23            System.out.println("success");
24        } else {
25            System.out.println("failed,resp code = " + statusCode+ ",return body = " + EntityUtils.toString(response.getEntity()));
26            throw new IOException("request failed");
27        }
28    } finally {
29        response.close();
30    }
31}

PHP

1try {
2    $resp = $client->request(
3        'POST',
4        'https://api.mch.weixin.qq.com/v3/brand/profitsharing/receivers/delete', //请求URL
5        [
6            // JSON请求体
7            'json' => [
8                "brand_mchid" => "1900000108", 
9                "appid" => "wx8888888888888888", 
10                "sub_appid" => "wx8888888888888889", 
11                "type" => "MERCHANT_ID", 
12                "account" => "1900000109",
13            ],
14            'headers' => [ 'Accept' => 'application/json' ]
15        ]
16    );
17    $statusCode = $resp->getStatusCode();
18    if ($statusCode == 200) { //处理成功
19        echo "success,return body = " . $resp->getBody()->getContents()."\n";
20    } else if ($statusCode == 204) { //处理成功,无返回Body
21        echo "success";
22    }
23} catch (RequestException $e) {
24    // 进行错误处理
25    echo $e->getMessage()."\n";
26    if ($e->hasResponse()) {
27        echo "failed,resp code = " . $e->getResponse()->getStatusCode() . " return body = " . $e->getResponse()->getBody() . "\n";
28    }
29    return;
30}

重要入参说明:

  • brand_mchid:品牌主商户号,通过微信支付认证的品牌主商户号,填写微信支付分配的商户号。

  • AppID:公众账号ID,微信分配的公众账号ID,这里指服务商的AppID。

  • type:分账接收方类型,枚举值:

    • MERCHANT_ID:商户号(mch_id或者sub_mch_id)

    • PERSONAL_OPENID:个人OpenID(由服务商的AppID转换得到)

    • PERSONAL_SUB_OPENID:个人sub_openid(由品牌主的AppID转换得到)

  • account:分账接收方账号:

    • 分账接收方类型为:MERCHANT_ID时,分账接收方账号为商户号(mch_id或者sub_mch_id)

    • 分账接收方类型为:PERSONAL_OPENID时,分账接收方账号为个人OpenID

    • 分账接收方类型为:PESONAL_SUB_OPENID时,分账接收方账号为个人sub_openid

更多参数、响应详情及错误码请参见删除分账接收方接口文档。

4. 常见问题

Q:分账调用“请求分账接口”返回“非分账订单不支持分账”

A:请按照以下几点检查:

  1. 微信订单号填写错误;

  2. 下单的时候未传分账标识(profit_sharing)的订单,是没有分账权限的。

Q:分账调用“请求分账接口”返回“分账金额不足”

A:请按照以下几点检查:

  1. 该订单已全额退款,没有资金可以分账;

  2. 已经调用过“请求单次分账”,订单剩余的待分账金额已经解冻,已无分账资金;

  3. 超过订单可分账金额或者该订单已无可分账金额,请检查确认。

Q:分账调用“请求分账接口”返回“订单处理中,暂时无法分账,请稍后再试”

A:请按照以下几点检查:

  1. 请在订单支付成功1分钟后再调用分账接口;

  2. 未结算的订单,请在结算后再调用分账接口请求分账;

  3. 老资金流商户的订单,不支持分账;

  4. 商户开通了收支分离但手续费账户余额不足(手续费账户最低余额要求是100元以上,在充值手续费账户1小时后,订单会正常结算,即可正常调用分账接口)。

Q:分账调用“请求分账接口”返回“分账接收商户全称不匹配”

A:请按照以下几点检查:

  1. 分账接收商户全称填写错误,请填写正确的商户全称;

  2. 接口需要使用UTF-8编码。

Q:分账调用“添加分账接收方接口”返回“系统繁忙,请稍后重试”

A:receiver中的参数account错误,参数account的规则如下:

  1. 类型是MERCHANT_ID时,是商户ID;

  2. 类型是PERSONAL_OPENID时,是个人OpenID;

  3. 类型是PERSONAL_SUB_OPENID时,是个人sub_openid;

  4. AppID与mchid不匹配也会报该错误,请检查确认;

  5. 签名类型错误,分账接口签名类型目前支持SHA256-RSA、国密(又称商用加密算法,即商密SM)。