提交注销申请单
更新时间:2025.02.17电商子商户需注销商户号时,由其所属电商平台服务商调用本接口发起注销申请。
接口说明
支持商户:【平台商户】
请求方式:【POST】/v3/ecommerce/account/cancel-applications
请求域名:【主域名】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)
【申请注销的二级商户号】电商平台二级商户号,由微信支付生成并下发
out_apply_no 必填 string(32)
【商户注销申请单号】商户注销申请单号,由商户自定义生成,要求在服务商维度下是唯一的,必须仅包含大小写字母与数字
application_info 必填 array[CancelApplicationInfo]
【注销申请材料】注销申请材料,详见下方文档:
属性 | |
application_type 必填 string 【注销申请材料类型】注销申请材料类型,详见下方文档: 可选取值:
application_media_id 必填 string(512) 【注销申请材料照片ID】注销申请材料照片ID,请填写通过上传图片接口预先上传图片生成好的media_id |
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/ecommerce/account/cancel-applications \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sub_mchid" : "1900000109", 8 "out_apply_no" : "2019061122222222122", 9 "application_info" : [ 10 { 11 "application_type" : "SP_CANCEL_ACCOUNT_APPLICATION", 12 "application_media_id" : "abc123456" 13 } 14 ] 15 }' 16
需配合微信支付工具库 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 CreateCancelApplication { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/ecommerce/account/cancel-applications"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CreateCancelApplication client = new CreateCancelApplication( 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 CancelApplicationCreateRequest request = new CancelApplicationCreateRequest(); 41 request.subMchid = "1900000109"; 42 request.outApplyNo = "2019061122222222122"; 43 request.applicationInfo = new ArrayList<>(); 44 { 45 CancelApplicationInfo applicationInfoItem = new CancelApplicationInfo(); 46 applicationInfoItem.applicationType = ApplicationType.SP_CANCEL_ACCOUNT_APPLICATION; 47 applicationInfoItem.applicationMediaId = "abc123456"; 48 request.applicationInfo.add(applicationInfoItem); 49 }; 50 try { 51 CancelApplicationsEntity response = client.run(request); 52 // TODO: 请求成功,继续业务逻辑 53 System.out.println(response); 54 } catch (WXPayUtility.ApiException e) { 55 // TODO: 请求失败,根据状态码执行不同的逻辑 56 e.printStackTrace(); 57 } 58 } 59 60 public CancelApplicationsEntity run(CancelApplicationCreateRequest request) { 61 String uri = PATH; 62 String reqBody = WXPayUtility.toJson(request); 63 64 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 65 reqBuilder.addHeader("Accept", "application/json"); 66 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 67 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 68 reqBuilder.addHeader("Content-Type", "application/json"); 69 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 70 reqBuilder.method(METHOD, requestBody); 71 Request httpRequest = reqBuilder.build(); 72 73 // 发送HTTP请求 74 OkHttpClient client = new OkHttpClient.Builder().build(); 75 try (Response httpResponse = client.newCall(httpRequest).execute()) { 76 String respBody = WXPayUtility.extractBody(httpResponse); 77 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 78 // 2XX 成功,验证应答签名 79 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 80 httpResponse.headers(), respBody); 81 82 // 从HTTP应答报文构建返回数据 83 return WXPayUtility.fromJson(respBody, CancelApplicationsEntity.class); 84 } else { 85 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 86 } 87 } catch (IOException e) { 88 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 89 } 90 } 91 92 private final String mchid; 93 private final String certificateSerialNo; 94 private final PrivateKey privateKey; 95 private final String wechatPayPublicKeyId; 96 private final PublicKey wechatPayPublicKey; 97 98 public CreateCancelApplication(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 99 this.mchid = mchid; 100 this.certificateSerialNo = certificateSerialNo; 101 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 102 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 103 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 104 } 105 106 public static class CancelApplicationCreateRequest { 107 @SerializedName("sub_mchid") 108 public String subMchid; 109 110 @SerializedName("out_apply_no") 111 public String outApplyNo; 112 113 @SerializedName("application_info") 114 public List<CancelApplicationInfo> applicationInfo = new ArrayList<CancelApplicationInfo>(); 115 } 116 117 public static class CancelApplicationsEntity { 118 @SerializedName("out_apply_no") 119 public String outApplyNo; 120 121 @SerializedName("sub_mchid") 122 public String subMchid; 123 124 @SerializedName("reject_reason") 125 public String rejectReason; 126 127 @SerializedName("cancel_state") 128 public CancelState cancelState; 129 130 @SerializedName("update_time") 131 public String updateTime; 132 } 133 134 public static class CancelApplicationInfo { 135 @SerializedName("application_type") 136 public ApplicationType applicationType; 137 138 @SerializedName("application_media_id") 139 public String applicationMediaId; 140 } 141 142 public enum CancelState { 143 @SerializedName("REVIEWING") 144 REVIEWING, 145 @SerializedName("REJECTED") 146 REJECTED, 147 @SerializedName("CANCEL_SUCCESS") 148 CANCEL_SUCCESS 149 } 150 151 public enum ApplicationType { 152 @SerializedName("SP_MERCHANT_APPLICATION") 153 SP_MERCHANT_APPLICATION, 154 @SerializedName("SUB_MERCHANT_APPLICATION") 155 SUB_MERCHANT_APPLICATION, 156 @SerializedName("MISSING_OFFICIAL_SEAL_LETTER") 157 MISSING_OFFICIAL_SEAL_LETTER, 158 @SerializedName("SP_CANCEL_ACCOUNT_APPLICATION") 159 SP_CANCEL_ACCOUNT_APPLICATION, 160 @SerializedName("SUB_CANCEL_ACCOUNT_APPLICATION") 161 SUB_CANCEL_ACCOUNT_APPLICATION 162 } 163 164} 165
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 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 := &CancelApplicationCreateRequest{ 27 SubMchid: wxpay_utility.String("1900000109"), 28 OutApplyNo: wxpay_utility.String("2019061122222222122"), 29 ApplicationInfo: []CancelApplicationInfo{CancelApplicationInfo{ 30 ApplicationType: APPLICATIONTYPE_SP_CANCEL_ACCOUNT_APPLICATION.Ptr(), 31 ApplicationMediaId: wxpay_utility.String("abc123456"), 32 }}, 33 } 34 35 response, err := CreateCancelApplication(config, request) 36 if err != nil { 37 fmt.Printf("请求失败: %+v\n", err) 38 // TODO: 请求失败,根据状态码执行不同的处理 39 return 40 } 41 42 // TODO: 请求成功,继续业务逻辑 43 fmt.Printf("请求成功: %+v\n", response) 44} 45 46func CreateCancelApplication(config *wxpay_utility.MchConfig, request *CancelApplicationCreateRequest) (response *CancelApplicationsEntity, err error) { 47 const ( 48 host = "https://api.mch.weixin.qq.com" 49 method = "POST" 50 path = "/v3/ecommerce/account/cancel-applications" 51 ) 52 53 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 54 if err != nil { 55 return nil, err 56 } 57 reqBody, err := json.Marshal(request) 58 if err != nil { 59 return nil, err 60 } 61 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 62 if err != nil { 63 return nil, err 64 } 65 httpRequest.Header.Set("Accept", "application/json") 66 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 67 httpRequest.Header.Set("Content-Type", "application/json") 68 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 69 if err != nil { 70 return nil, err 71 } 72 httpRequest.Header.Set("Authorization", authorization) 73 74 client := &http.Client{} 75 httpResponse, err := client.Do(httpRequest) 76 if err != nil { 77 return nil, err 78 } 79 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 80 if err != nil { 81 return nil, err 82 } 83 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 84 // 2XX 成功,验证应答签名 85 err = wxpay_utility.ValidateResponse( 86 config.WechatPayPublicKeyId(), 87 config.WechatPayPublicKey(), 88 &httpResponse.Header, 89 respBody, 90 ) 91 if err != nil { 92 return nil, err 93 } 94 response := &CancelApplicationsEntity{} 95 if err := json.Unmarshal(respBody, response); err != nil { 96 return nil, err 97 } 98 99 return response, nil 100 } else { 101 return nil, wxpay_utility.NewApiException( 102 httpResponse.StatusCode, 103 httpResponse.Header, 104 respBody, 105 ) 106 } 107} 108 109type CancelApplicationCreateRequest struct { 110 SubMchid *string `json:"sub_mchid,omitempty"` 111 OutApplyNo *string `json:"out_apply_no,omitempty"` 112 ApplicationInfo []CancelApplicationInfo `json:"application_info,omitempty"` 113} 114 115type CancelApplicationsEntity struct { 116 OutApplyNo *string `json:"out_apply_no,omitempty"` 117 SubMchid *string `json:"sub_mchid,omitempty"` 118 RejectReason *string `json:"reject_reason,omitempty"` 119 CancelState *CancelState `json:"cancel_state,omitempty"` 120 UpdateTime *string `json:"update_time,omitempty"` 121} 122 123type CancelApplicationInfo struct { 124 ApplicationType *ApplicationType `json:"application_type,omitempty"` 125 ApplicationMediaId *string `json:"application_media_id,omitempty"` 126} 127 128type CancelState string 129 130func (e CancelState) Ptr() *CancelState { 131 return &e 132} 133 134const ( 135 CANCELSTATE_REVIEWING CancelState = "REVIEWING" 136 CANCELSTATE_REJECTED CancelState = "REJECTED" 137 CANCELSTATE_CANCEL_SUCCESS CancelState = "CANCEL_SUCCESS" 138) 139 140type ApplicationType string 141 142func (e ApplicationType) Ptr() *ApplicationType { 143 return &e 144} 145 146const ( 147 APPLICATIONTYPE_SP_MERCHANT_APPLICATION ApplicationType = "SP_MERCHANT_APPLICATION" 148 APPLICATIONTYPE_SUB_MERCHANT_APPLICATION ApplicationType = "SUB_MERCHANT_APPLICATION" 149 APPLICATIONTYPE_MISSING_OFFICIAL_SEAL_LETTER ApplicationType = "MISSING_OFFICIAL_SEAL_LETTER" 150 APPLICATIONTYPE_SP_CANCEL_ACCOUNT_APPLICATION ApplicationType = "SP_CANCEL_ACCOUNT_APPLICATION" 151 APPLICATIONTYPE_SUB_CANCEL_ACCOUNT_APPLICATION ApplicationType = "SUB_CANCEL_ACCOUNT_APPLICATION" 152) 153
应答参数
|
out_apply_no 选填 string(32)
【商户注销申请单号】商户注销申请单号,原样返回请求参数里的内容
sub_mchid 选填 string(32)
【二级商户号】二级商户号
reject_reason 选填 string(512)
【驳回原因】受理失败原因
cancel_state 选填 string
【注销状态】注销状态
可选取值:
REVIEWING
: 审核中
REJECTED
: 审核驳回,驳回原因详见reject_reason
CANCEL_SUCCESS
: 注销成功
update_time 选填 string(32)
【最后更新时间】最后更新时间。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
应答示例
200 OK
1{ 2 "out_apply_no" : "abcd12345FEGH", 3 "sub_mchid" : "123456789", 4 "reject_reason" : "非电商服务商,无权调用此接口", 5 "cancel_state" : "REVIEWING", 6 "update_time" : "2023-01-20T13:29:35+08:00" 7} 8
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | INVALID_REQUEST | 该商户当前不允许注销 | 根据错误提示,对子商户完成相应处理后再申请注销 |
400 | INVALID_REQUEST | “服务商注销电商子申请书”或“子商户注销电商子申请书”缺失 | 根据错误提示,正确传入该参数 |
400 | INVALID_REQUEST | media_id对应的图片不存在 | 使用对应上传API返回的media_id |
400 | INVALID_REQUEST | 服务商或子商户不存在 | 请确认mchid填写无误 |
400 | INVALID_REQUEST | 服务商或子商户已注销 | 商户已注销,不可申请注销 |
400 | INVALID_REQUEST | 服务商非电商服务商 | 服务商非电商服务商,不可申请注销 |
400 | INVALID_REQUEST | 子商户非电商子商户 | 子商户非电商子商户,不可申请注销 |
400 | INVALID_REQUEST | 服务商和子商户无受理关系 | 服务商和子商户无受理关系,不可申请注销 |
400 | INVALID_REQUEST | 重试请求和原请求数据不一致 | 请使用和原请求一致的参数发起请求 |
400 | INVALID_REQUEST | 重试请求距离上次请求间隔太久 | 时间间隔过久,不允许重试该请求 |
409 | ALREADY_EXISTS | 申请单已存在 | 该申请单已受理,无需重试 |