商户注销资格校验
更新时间:2025.11.05电商平台发起注销提现申请前,可通过该接口判断商户是否满足注销条件
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/ecommerce/account/apply-cancel-withdraw/validate-cancel/{sub_mchid}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
sub_mchid 必填 string(32)
【申请注销的二级商户号】 平台商户的二级商户号,由微信支付生成并下发
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/ecommerce/account/apply-cancel-withdraw/validate-cancel/1900000109 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 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 ValidateCancel { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/ecommerce/account/apply-cancel-withdraw/validate-cancel/{sub_mchid}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ValidateCancel client = new ValidateCancel( 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 ValidateCancelRequest request = new ValidateCancelRequest(); 41 request.subMchid = "1900000109"; 42 try { 43 ValidateCancelResponse response = client.run(request); 44 // TODO: 请求成功,继续业务逻辑 45 System.out.println(response); 46 } catch (WXPayUtility.ApiException e) { 47 // TODO: 请求失败,根据状态码执行不同的逻辑 48 e.printStackTrace(); 49 } 50 } 51 52 public ValidateCancelResponse run(ValidateCancelRequest request) { 53 String uri = PATH; 54 uri = uri.replace("{sub_mchid}", WXPayUtility.urlEncode(request.subMchid)); 55 56 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 57 reqBuilder.addHeader("Accept", "application/json"); 58 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 59 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 60 reqBuilder.method(METHOD, null); 61 Request httpRequest = reqBuilder.build(); 62 63 // 发送HTTP请求 64 OkHttpClient client = new OkHttpClient.Builder().build(); 65 try (Response httpResponse = client.newCall(httpRequest).execute()) { 66 String respBody = WXPayUtility.extractBody(httpResponse); 67 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 68 // 2XX 成功,验证应答签名 69 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 70 httpResponse.headers(), respBody); 71 72 // 从HTTP应答报文构建返回数据 73 return WXPayUtility.fromJson(respBody, ValidateCancelResponse.class); 74 } else { 75 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 76 } 77 } catch (IOException e) { 78 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 79 } 80 } 81 82 private final String mchid; 83 private final String certificateSerialNo; 84 private final PrivateKey privateKey; 85 private final String wechatPayPublicKeyId; 86 private final PublicKey wechatPayPublicKey; 87 88 public ValidateCancel(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 89 this.mchid = mchid; 90 this.certificateSerialNo = certificateSerialNo; 91 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 92 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 93 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 94 } 95 96 public static class ValidateCancelRequest { 97 @SerializedName("sub_mchid") 98 @Expose(serialize = false) 99 public String subMchid; 100 } 101 102 public static class ValidateCancelResponse { 103 @SerializedName("sub_mchid") 104 public String subMchid; 105 106 @SerializedName("merchant_state") 107 public MerchantState merchantState; 108 109 @SerializedName("validate_result") 110 public ValidateCancelResult validateResult; 111 112 @SerializedName("account_info") 113 public List<AccountInfo> accountInfo; 114 115 @SerializedName("block_reasons") 116 public List<BlockCancelReasonInfo> blockReasons; 117 } 118 119 public enum MerchantState { 120 @SerializedName("NORMAL") 121 NORMAL, 122 @SerializedName("HAS_BEEN_CANCELLED") 123 HAS_BEEN_CANCELLED 124 } 125 126 public enum ValidateCancelResult { 127 @SerializedName("ALLOW_CANCEL_WITHDRAW") 128 ALLOW_CANCEL_WITHDRAW, 129 @SerializedName("NOT_ALLOW_CANCEL_WITHDRAW") 130 NOT_ALLOW_CANCEL_WITHDRAW 131 } 132 133 public static class AccountInfo { 134 @SerializedName("out_account_type") 135 public OutAccountType outAccountType; 136 137 @SerializedName("amount") 138 public Long amount; 139 } 140 141 public static class BlockCancelReasonInfo { 142 @SerializedName("type") 143 public BlockCancelReasonType type; 144 145 @SerializedName("description") 146 public String description; 147 } 148 149 public enum OutAccountType { 150 @SerializedName("BASIC_ACCOUNT") 151 BASIC_ACCOUNT, 152 @SerializedName("OPERATE_ACCOUNT") 153 OPERATE_ACCOUNT, 154 @SerializedName("MARGIN_ACCOUNT") 155 MARGIN_ACCOUNT, 156 @SerializedName("TRADE_FEE_ACCOUNT") 157 TRADE_FEE_ACCOUNT 158 } 159 160 public enum BlockCancelReasonType { 161 @SerializedName("CONSUMER_COMPLAINT_UNPROCESSED") 162 CONSUMER_COMPLAINT_UNPROCESSED, 163 @SerializedName("HAS_BLOCKING_CONTROL") 164 HAS_BLOCKING_CONTROL, 165 @SerializedName("FUNDS_PENDING_PROCESSING") 166 FUNDS_PENDING_PROCESSING, 167 @SerializedName("OTHER_REASON") 168 OTHER_REASON 169 } 170 171} 172
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &ValidateCancelRequest{ 27 SubMchid: wxpay_utility.String("1900000109"), 28 } 29 30 response, err := ValidateCancel(config, request) 31 if err != nil { 32 fmt.Printf("请求失败: %+v\n", err) 33 // TODO: 请求失败,根据状态码执行不同的处理 34 return 35 } 36 37 // TODO: 请求成功,继续业务逻辑 38 fmt.Printf("请求成功: %+v\n", response) 39} 40 41func ValidateCancel(config *wxpay_utility.MchConfig, request *ValidateCancelRequest) (response *ValidateCancelResponse, err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "GET" 45 path = "/v3/ecommerce/account/apply-cancel-withdraw/validate-cancel/{sub_mchid}" 46 ) 47 48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 49 if err != nil { 50 return nil, err 51 } 52 reqUrl.Path = strings.Replace(reqUrl.Path, "{sub_mchid}", url.PathEscape(*request.SubMchid), -1) 53 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 54 if err != nil { 55 return nil, err 56 } 57 httpRequest.Header.Set("Accept", "application/json") 58 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 59 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest.Header.Set("Authorization", authorization) 64 65 client := &http.Client{} 66 httpResponse, err := client.Do(httpRequest) 67 if err != nil { 68 return nil, err 69 } 70 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 71 if err != nil { 72 return nil, err 73 } 74 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 75 // 2XX 成功,验证应答签名 76 err = wxpay_utility.ValidateResponse( 77 config.WechatPayPublicKeyId(), 78 config.WechatPayPublicKey(), 79 &httpResponse.Header, 80 respBody, 81 ) 82 if err != nil { 83 return nil, err 84 } 85 response := &ValidateCancelResponse{} 86 if err := json.Unmarshal(respBody, response); err != nil { 87 return nil, err 88 } 89 90 return response, nil 91 } else { 92 return nil, wxpay_utility.NewApiException( 93 httpResponse.StatusCode, 94 httpResponse.Header, 95 respBody, 96 ) 97 } 98} 99 100type ValidateCancelRequest struct { 101 SubMchid *string `json:"sub_mchid,omitempty"` 102} 103 104func (o *ValidateCancelRequest) MarshalJSON() ([]byte, error) { 105 type Alias ValidateCancelRequest 106 a := &struct { 107 SubMchid *string `json:"sub_mchid,omitempty"` 108 *Alias 109 }{ 110 // 序列化时移除非 Body 字段 111 SubMchid: nil, 112 Alias: (*Alias)(o), 113 } 114 return json.Marshal(a) 115} 116 117type ValidateCancelResponse struct { 118 SubMchid *string `json:"sub_mchid,omitempty"` 119 MerchantState *MerchantState `json:"merchant_state,omitempty"` 120 ValidateResult *ValidateCancelResult `json:"validate_result,omitempty"` 121 AccountInfo []AccountInfo `json:"account_info,omitempty"` 122 BlockReasons []BlockCancelReasonInfo `json:"block_reasons,omitempty"` 123} 124 125type MerchantState string 126 127func (e MerchantState) Ptr() *MerchantState { 128 return &e 129} 130 131const ( 132 MERCHANTSTATE_NORMAL MerchantState = "NORMAL" 133 MERCHANTSTATE_HAS_BEEN_CANCELLED MerchantState = "HAS_BEEN_CANCELLED" 134) 135 136type ValidateCancelResult string 137 138func (e ValidateCancelResult) Ptr() *ValidateCancelResult { 139 return &e 140} 141 142const ( 143 VALIDATECANCELRESULT_ALLOW_CANCEL_WITHDRAW ValidateCancelResult = "ALLOW_CANCEL_WITHDRAW" 144 VALIDATECANCELRESULT_NOT_ALLOW_CANCEL_WITHDRAW ValidateCancelResult = "NOT_ALLOW_CANCEL_WITHDRAW" 145) 146 147type AccountInfo struct { 148 OutAccountType *OutAccountType `json:"out_account_type,omitempty"` 149 Amount *int64 `json:"amount,omitempty"` 150} 151 152type BlockCancelReasonInfo struct { 153 Type *BlockCancelReasonType `json:"type,omitempty"` 154 Description *string `json:"description,omitempty"` 155} 156 157type OutAccountType string 158 159func (e OutAccountType) Ptr() *OutAccountType { 160 return &e 161} 162 163const ( 164 OUTACCOUNTTYPE_BASIC_ACCOUNT OutAccountType = "BASIC_ACCOUNT" 165 OUTACCOUNTTYPE_OPERATE_ACCOUNT OutAccountType = "OPERATE_ACCOUNT" 166 OUTACCOUNTTYPE_MARGIN_ACCOUNT OutAccountType = "MARGIN_ACCOUNT" 167 OUTACCOUNTTYPE_TRADE_FEE_ACCOUNT OutAccountType = "TRADE_FEE_ACCOUNT" 168) 169 170type BlockCancelReasonType string 171 172func (e BlockCancelReasonType) Ptr() *BlockCancelReasonType { 173 return &e 174} 175 176const ( 177 BLOCKCANCELREASONTYPE_CONSUMER_COMPLAINT_UNPROCESSED BlockCancelReasonType = "CONSUMER_COMPLAINT_UNPROCESSED" 178 BLOCKCANCELREASONTYPE_HAS_BLOCKING_CONTROL BlockCancelReasonType = "HAS_BLOCKING_CONTROL" 179 BLOCKCANCELREASONTYPE_FUNDS_PENDING_PROCESSING BlockCancelReasonType = "FUNDS_PENDING_PROCESSING" 180 BLOCKCANCELREASONTYPE_OTHER_REASON BlockCancelReasonType = "OTHER_REASON" 181) 182
应答参数
200 OK
sub_mchid 必填 string(32)
【注销检查的二级商户号】 平台商户的二级商户号,由微信支付生成并下发
merchant_state 必填 string
【商户号状态】 商户号状态
可选取值
NORMAL: 正常HAS_BEEN_CANCELLED: 已注销
validate_result 必填 string
【注销资格检查结果】 注销资格检查结果
可选取值
ALLOW_CANCEL_WITHDRAW: 可发起注销提现申请NOT_ALLOW_CANCEL_WITHDRAW: 不可发起注销提现申请
account_info 选填 array[object]
【商户资金账户余额】 二级商户号已开通的账户余额信息,接口返回的余额是实时数据。在查询后,商户可能仍有新的交易入账导致余额变动。发起资金清退申请前,请再次调用本接口进行确认。清退申请提交后,微信支付会将商户账户里所有遗留的资金全额清退。
| 属性 | |
out_account_type 必填 string 【二级商户号的出款子账户类型】 仅返回已开通的账户类型 可选取值
amount 必填 integer 【账户金额】 单位:分 |
block_reasons 选填 array[object]
【不可发起注销原因】 商户号未注销时返回此字段,同个商户可能返回多个不可注销原因,可引导商户进行处理
| 属性 | |
type 选填 string 【原因类型】 原因类型 可选取值
description 选填 string(512) 【原因描述】 原因描述 |
应答示例
200 OK
1{ 2 "sub_mchid" : "1900000109", 3 "merchant_state" : "NORMAL", 4 "validate_result" : "ALLOW_CANCEL_WITHDRAW", 5 "account_info" : [ 6 { 7 "out_account_type" : "BASIC_ACCOUNT", 8 "amount" : 101 9 } 10 ], 11 "block_reasons" : [ 12 { 13 "type" : "CONSUMER_COMPLAINT_UNPROCESSED", 14 "description" : "该商户存在冻结资金或在途资金,请先处理资金再申请注销" 15 } 16 ] 17} 18
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
403 | NO_AUTH | 请求非法 | 结合message描述信息,请检查后重试 |

