删除分账接收方
更新时间:2025.09.29商户发起删除分账接收方请求。删除后,不支持将分账方商户结算后的资金,分到该分账接收方
接口说明
支持商户:【普通商户】
请求方式:【POST】/v3/profitsharing/receivers/delete
请求域名:【主域名】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 包体参数
appid 必填 string(32)
【公众账号ID】 APPID是微信开放平台(移动应用)或微信公众平台(小程序、公众号)为开发者的应用程序提供的唯一标识。此处,可以填写这三种类型中的任意一种APPID,但请确保该appid与mchid有绑定关系。详见:开发必要参数说明
type 必填 string
【接收方类型】
可选取值
MERCHANT_ID
: 商户号PERSONAL_OPENID
: 个人openid(用户在商户appid下的唯一标识,详见 OpenID获取)
account 必填 string(64)
【接收方账号】
分账接收方类型为MERCHANT_ID时,分账接收方账号为商户号
分账接收方类型为PERSONAL_OPENID时,分账接收方账号为个人OpenID(由商户的AppID转换得到)
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/profitsharing/receivers/delete \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "appid" : "wx8888888888888888", 8 "type" : "MERCHANT_ID", 9 "account" : "1900000109" 10 }' 11
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/merchant/4014931831 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 DeleteReceiver { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/profitsharing/receivers/delete"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 32 DeleteReceiver client = new DeleteReceiver( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 DeleteReceiverRequest request = new DeleteReceiverRequest(); 41 request.appid = "wx8888888888888888"; 42 request.type = ReceiverType.MERCHANT_ID; 43 request.account = "1900000109"; 44 try { 45 DeleteReceiverResponse response = client.run(request); 46 // TODO: 请求成功,继续业务逻辑 47 System.out.println(response); 48 } catch (WXPayUtility.ApiException e) { 49 // TODO: 请求失败,根据状态码执行不同的逻辑 50 e.printStackTrace(); 51 } 52 } 53 54 public DeleteReceiverResponse run(DeleteReceiverRequest request) { 55 String uri = PATH; 56 String reqBody = WXPayUtility.toJson(request); 57 58 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 59 reqBuilder.addHeader("Accept", "application/json"); 60 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 61 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 62 reqBuilder.addHeader("Content-Type", "application/json"); 63 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 64 reqBuilder.method(METHOD, requestBody); 65 Request httpRequest = reqBuilder.build(); 66 67 // 发送HTTP请求 68 OkHttpClient client = new OkHttpClient.Builder().build(); 69 try (Response httpResponse = client.newCall(httpRequest).execute()) { 70 String respBody = WXPayUtility.extractBody(httpResponse); 71 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 72 // 2XX 成功,验证应答签名 73 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 74 httpResponse.headers(), respBody); 75 76 // 从HTTP应答报文构建返回数据 77 return WXPayUtility.fromJson(respBody, DeleteReceiverResponse.class); 78 } else { 79 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 80 } 81 } catch (IOException e) { 82 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 83 } 84 } 85 86 private final String mchid; 87 private final String certificateSerialNo; 88 private final PrivateKey privateKey; 89 private final String wechatPayPublicKeyId; 90 private final PublicKey wechatPayPublicKey; 91 92 public DeleteReceiver(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 93 this.mchid = mchid; 94 this.certificateSerialNo = certificateSerialNo; 95 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 96 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 97 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 98 } 99 100 public static class DeleteReceiverRequest { 101 @SerializedName("appid") 102 public String appid; 103 104 @SerializedName("type") 105 public ReceiverType type; 106 107 @SerializedName("account") 108 public String account; 109 } 110 111 public static class DeleteReceiverResponse { 112 @SerializedName("type") 113 public ReceiverType type; 114 115 @SerializedName("account") 116 public String account; 117 } 118 119 public enum ReceiverType { 120 @SerializedName("MERCHANT_ID") 121 MERCHANT_ID, 122 @SerializedName("PERSONAL_OPENID") 123 PERSONAL_OPENID 124 } 125 126} 127
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/merchant/4015119334 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/merchant/4013070756 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &DeleteReceiverRequest{ 27 Appid: wxpay_utility.String("wx8888888888888888"), 28 Type: RECEIVERTYPE_MERCHANT_ID.Ptr(), 29 Account: wxpay_utility.String("1900000109"), 30 } 31 32 response, err := DeleteReceiver(config, request) 33 if err != nil { 34 fmt.Printf("请求失败: %+v\n", err) 35 // TODO: 请求失败,根据状态码执行不同的处理 36 return 37 } 38 39 // TODO: 请求成功,继续业务逻辑 40 fmt.Printf("请求成功: %+v\n", response) 41} 42 43func DeleteReceiver(config *wxpay_utility.MchConfig, request *DeleteReceiverRequest) (response *DeleteReceiverResponse, err error) { 44 const ( 45 host = "https://api.mch.weixin.qq.com" 46 method = "POST" 47 path = "/v3/profitsharing/receivers/delete" 48 ) 49 50 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 51 if err != nil { 52 return nil, err 53 } 54 reqBody, err := json.Marshal(request) 55 if err != nil { 56 return nil, err 57 } 58 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 59 if err != nil { 60 return nil, err 61 } 62 httpRequest.Header.Set("Accept", "application/json") 63 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 64 httpRequest.Header.Set("Content-Type", "application/json") 65 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 66 if err != nil { 67 return nil, err 68 } 69 httpRequest.Header.Set("Authorization", authorization) 70 71 client := &http.Client{} 72 httpResponse, err := client.Do(httpRequest) 73 if err != nil { 74 return nil, err 75 } 76 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 77 if err != nil { 78 return nil, err 79 } 80 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 81 // 2XX 成功,验证应答签名 82 err = wxpay_utility.ValidateResponse( 83 config.WechatPayPublicKeyId(), 84 config.WechatPayPublicKey(), 85 &httpResponse.Header, 86 respBody, 87 ) 88 if err != nil { 89 return nil, err 90 } 91 response := &DeleteReceiverResponse{} 92 if err := json.Unmarshal(respBody, response); err != nil { 93 return nil, err 94 } 95 96 return response, nil 97 } else { 98 return nil, wxpay_utility.NewApiException( 99 httpResponse.StatusCode, 100 httpResponse.Header, 101 respBody, 102 ) 103 } 104} 105 106type DeleteReceiverRequest struct { 107 Appid *string `json:"appid,omitempty"` 108 Type *ReceiverType `json:"type,omitempty"` 109 Account *string `json:"account,omitempty"` 110} 111 112type DeleteReceiverResponse struct { 113 Type *ReceiverType `json:"type,omitempty"` 114 Account *string `json:"account,omitempty"` 115} 116 117type ReceiverType string 118 119func (e ReceiverType) Ptr() *ReceiverType { 120 return &e 121} 122 123const ( 124 RECEIVERTYPE_MERCHANT_ID ReceiverType = "MERCHANT_ID" 125 RECEIVERTYPE_PERSONAL_OPENID ReceiverType = "PERSONAL_OPENID" 126) 127
应答参数
200 OK
type 必填 string
【接收方类型】
可选取值
MERCHANT_ID
: 商户号PERSONAL_OPENID
: 个人openid(用户在商户appid下的唯一标识,详见 OpenID获取)
account 必填 string(64)
【接收方账号】
分账接收方类型为MERCHANT_ID时,分账接收方账号为商户号
分账接收方类型为PERSONAL_OPENID时,分账接收方账号为个人OpenID(由商户的AppID转换得到)
应答示例
200 OK
1{ 2 "type" : "MERCHANT_ID", 3 "account" : "1900000109" 4} 5
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示