查询注销单状态
更新时间:2024.11.05电商平台服务商发起注销申请后,通过本接口查询注销状态、进展。
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/ecommerce/account/cancel-applications/out-apply-no/{out_apply_no}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
out_apply_no 必填 string(32)
【商户注销申请单号】商户注销申请单号。由商户自定义生成的、在申请注销接口传入的单号。
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/ecommerce/account/cancel-applications/out-apply-no/123283928932 \ 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 GetCancelApplication { 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/cancel-applications/out-apply-no/{out_apply_no}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetCancelApplication client = new GetCancelApplication( 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 GetCancelApplicationRequest request = new GetCancelApplicationRequest(); 41 request.outApplyNo = "123283928932"; 42 try { 43 CancelApplicationsEntity 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 CancelApplicationsEntity run(GetCancelApplicationRequest request) { 53 String uri = PATH; 54 uri = uri.replace("{out_apply_no}", WXPayUtility.urlEncode(request.outApplyNo)); 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, CancelApplicationsEntity.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 GetCancelApplication(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 GetCancelApplicationRequest { 97 @SerializedName("out_apply_no") 98 @Expose(serialize = false) 99 public String outApplyNo; 100 } 101 102 public static class CancelApplicationsEntity { 103 @SerializedName("out_apply_no") 104 public String outApplyNo; 105 106 @SerializedName("sub_mchid") 107 public String subMchid; 108 109 @SerializedName("reject_reason") 110 public String rejectReason; 111 112 @SerializedName("cancel_state") 113 public CancelState cancelState; 114 115 @SerializedName("update_time") 116 public String updateTime; 117 } 118 119 public enum CancelState { 120 @SerializedName("REVIEWING") 121 REVIEWING, 122 @SerializedName("REJECTED") 123 REJECTED, 124 @SerializedName("CANCEL_SUCCESS") 125 CANCEL_SUCCESS 126 } 127 128} 129
需配合微信支付工具库 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 := &GetCancelApplicationRequest{ 27 OutApplyNo: wxpay_utility.String("123283928932"), 28 } 29 30 response, err := GetCancelApplication(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 GetCancelApplication(config *wxpay_utility.MchConfig, request *GetCancelApplicationRequest) (response *CancelApplicationsEntity, err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "GET" 45 path = "/v3/ecommerce/account/cancel-applications/out-apply-no/{out_apply_no}" 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, "{out_apply_no}", url.PathEscape(*request.OutApplyNo), -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 := &CancelApplicationsEntity{} 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 GetCancelApplicationRequest struct { 101 OutApplyNo *string `json:"out_apply_no,omitempty"` 102} 103 104func (o *GetCancelApplicationRequest) MarshalJSON() ([]byte, error) { 105 type Alias GetCancelApplicationRequest 106 a := &struct { 107 OutApplyNo *string `json:"out_apply_no,omitempty"` 108 *Alias 109 }{ 110 // 序列化时移除非 Body 字段 111 OutApplyNo: nil, 112 Alias: (*Alias)(o), 113 } 114 return json.Marshal(a) 115} 116 117type CancelApplicationsEntity struct { 118 OutApplyNo *string `json:"out_apply_no,omitempty"` 119 SubMchid *string `json:"sub_mchid,omitempty"` 120 RejectReason *string `json:"reject_reason,omitempty"` 121 CancelState *CancelState `json:"cancel_state,omitempty"` 122 UpdateTime *string `json:"update_time,omitempty"` 123} 124 125type CancelState string 126 127func (e CancelState) Ptr() *CancelState { 128 return &e 129} 130 131const ( 132 CANCELSTATE_REVIEWING CancelState = "REVIEWING" 133 CANCELSTATE_REJECTED CancelState = "REJECTED" 134 CANCELSTATE_CANCEL_SUCCESS CancelState = "CANCEL_SUCCESS" 135) 136
应答参数
|
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 | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
404 | NOT_FOUND | 申请单不存在 | 该申请单不存在,请正确传入申请单单号 |