微信支付申请单号查询申请单状态
更新时间:2025.03.13微信支付申请单号查询注销申请单状态,电商平台发起申请后, 电商平台调用此接口查询审批和出款进度
接口说明
支持商户:【平台商户】
请求方式:【GET】/v3/ecommerce/account/apply-cancel-withdraw/applyment-id/{applyment_id}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
applyment_id 必填 string(32)
【微信支付注销提现申请单号】 电商平台提交二级商户注销申请后,由微信支付返回的申请单号,作为查询申请状态的唯一标识。
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/ecommerce/account/apply-cancel-withdraw/applyment-id/X202410241010125346 \ 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 GetApplyByApplymentId { 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/applyment-id/{applyment_id}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetApplyByApplymentId client = new GetApplyByApplymentId( 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 GetApplyByApplymentIdRequest request = new GetApplyByApplymentIdRequest(); 41 request.applymentId = "X202410241010125346"; 42 try { 43 CancelWithdrawaApplyData 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 CancelWithdrawaApplyData run(GetApplyByApplymentIdRequest request) { 53 String uri = PATH; 54 uri = uri.replace("{applyment_id}", WXPayUtility.urlEncode(request.applymentId)); 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, CancelWithdrawaApplyData.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 GetApplyByApplymentId(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 GetApplyByApplymentIdRequest { 97 @SerializedName("applyment_id") 98 @Expose(serialize = false) 99 public String applymentId; 100 } 101 102 public static class CancelWithdrawaApplyData { 103 @SerializedName("applyment_id") 104 public String applymentId; 105 106 @SerializedName("out_request_no") 107 public String outRequestNo; 108 109 @SerializedName("cancel_state") 110 public CancelState cancelState; 111 112 @SerializedName("cancel_state_description") 113 public String cancelStateDescription; 114 115 @SerializedName("withdraw") 116 public ApplyWithdraw withdraw; 117 118 @SerializedName("withdraw_state") 119 public WithdrawState withdrawState; 120 121 @SerializedName("withdraw_state_description") 122 public String withdrawStateDescription; 123 124 @SerializedName("account_withdraw_result") 125 public List<AccountWithdrawResult> accountWithdrawResult; 126 127 @SerializedName("modify_time") 128 public String modifyTime; 129 130 @SerializedName("sub_mchid") 131 public String subMchid; 132 133 @SerializedName("account_info") 134 public List<AccountInfo> accountInfo; 135 } 136 137 public enum CancelState { 138 @SerializedName("ACCEPTED") 139 ACCEPTED, 140 @SerializedName("REVIEWING") 141 REVIEWING, 142 @SerializedName("REJECTED") 143 REJECTED, 144 @SerializedName("WAITING_MERCHANT_CONFIRM") 145 WAITING_MERCHANT_CONFIRM, 146 @SerializedName("REVOKED") 147 REVOKED, 148 @SerializedName("SYSTEM_PROCESSING") 149 SYSTEM_PROCESSING, 150 @SerializedName("CANCELED") 151 CANCELED, 152 @SerializedName("FUND_PROCESSING") 153 FUND_PROCESSING, 154 @SerializedName("FINISH") 155 FINISH 156 } 157 158 public enum ApplyWithdraw { 159 @SerializedName("NOT_APPLY_WITHDRAW") 160 NOT_APPLY_WITHDRAW, 161 @SerializedName("APPLY_WITHDRAW") 162 APPLY_WITHDRAW 163 } 164 165 public enum WithdrawState { 166 @SerializedName("WITHDRAW_PROCESSING") 167 WITHDRAW_PROCESSING, 168 @SerializedName("WITHDRAW_EXCEPTION") 169 WITHDRAW_EXCEPTION, 170 @SerializedName("WITHDRAW_SUCCEED") 171 WITHDRAW_SUCCEED 172 } 173 174 public static class AccountWithdrawResult { 175 @SerializedName("out_account_type") 176 public OutAccountType outAccountType; 177 178 @SerializedName("pay_state") 179 public PayState payState; 180 181 @SerializedName("state_description") 182 public String stateDescription; 183 } 184 185 public static class AccountInfo { 186 @SerializedName("out_account_type") 187 public OutAccountType outAccountType; 188 189 @SerializedName("amount") 190 public Long amount; 191 } 192 193 public enum OutAccountType { 194 @SerializedName("BASIC_ACCOUNT") 195 BASIC_ACCOUNT, 196 @SerializedName("OPERATE_ACCOUNT") 197 OPERATE_ACCOUNT, 198 @SerializedName("MARGIN_ACCOUNT") 199 MARGIN_ACCOUNT, 200 @SerializedName("TRADE_FEE_ACCOUNT") 201 TRADE_FEE_ACCOUNT 202 } 203 204 public enum PayState { 205 @SerializedName("PAY_PROCESSING") 206 PAY_PROCESSING, 207 @SerializedName("PAY_SUCCEED") 208 PAY_SUCCEED, 209 @SerializedName("PAY_FAIL") 210 PAY_FAIL, 211 @SerializedName("BANK_REFUNDED") 212 BANK_REFUNDED 213 } 214 215} 216
需配合微信支付工具库 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 := &GetApplyByApplymentIdRequest{ 27 ApplymentId: wxpay_utility.String("X202410241010125346"), 28 } 29 30 response, err := GetApplyByApplymentId(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 GetApplyByApplymentId(config *wxpay_utility.MchConfig, request *GetApplyByApplymentIdRequest) (response *CancelWithdrawaApplyData, err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "GET" 45 path = "/v3/ecommerce/account/apply-cancel-withdraw/applyment-id/{applyment_id}" 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, "{applyment_id}", url.PathEscape(*request.ApplymentId), -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 := &CancelWithdrawaApplyData{} 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 GetApplyByApplymentIdRequest struct { 101 ApplymentId *string `json:"applyment_id,omitempty"` 102} 103 104func (o *GetApplyByApplymentIdRequest) MarshalJSON() ([]byte, error) { 105 type Alias GetApplyByApplymentIdRequest 106 a := &struct { 107 ApplymentId *string `json:"applyment_id,omitempty"` 108 *Alias 109 }{ 110 // 序列化时移除非 Body 字段 111 ApplymentId: nil, 112 Alias: (*Alias)(o), 113 } 114 return json.Marshal(a) 115} 116 117type CancelWithdrawaApplyData struct { 118 ApplymentId *string `json:"applyment_id,omitempty"` 119 OutRequestNo *string `json:"out_request_no,omitempty"` 120 CancelState *CancelState `json:"cancel_state,omitempty"` 121 CancelStateDescription *string `json:"cancel_state_description,omitempty"` 122 Withdraw *ApplyWithdraw `json:"withdraw,omitempty"` 123 WithdrawState *WithdrawState `json:"withdraw_state,omitempty"` 124 WithdrawStateDescription *string `json:"withdraw_state_description,omitempty"` 125 AccountWithdrawResult []AccountWithdrawResult `json:"account_withdraw_result,omitempty"` 126 ModifyTime *string `json:"modify_time,omitempty"` 127 SubMchid *string `json:"sub_mchid,omitempty"` 128 AccountInfo []AccountInfo `json:"account_info,omitempty"` 129} 130 131type CancelState string 132 133func (e CancelState) Ptr() *CancelState { 134 return &e 135} 136 137const ( 138 CANCELSTATE_ACCEPTED CancelState = "ACCEPTED" 139 CANCELSTATE_REVIEWING CancelState = "REVIEWING" 140 CANCELSTATE_REJECTED CancelState = "REJECTED" 141 CANCELSTATE_WAITING_MERCHANT_CONFIRM CancelState = "WAITING_MERCHANT_CONFIRM" 142 CANCELSTATE_REVOKED CancelState = "REVOKED" 143 CANCELSTATE_SYSTEM_PROCESSING CancelState = "SYSTEM_PROCESSING" 144 CANCELSTATE_CANCELED CancelState = "CANCELED" 145 CANCELSTATE_FUND_PROCESSING CancelState = "FUND_PROCESSING" 146 CANCELSTATE_FINISH CancelState = "FINISH" 147) 148 149type ApplyWithdraw string 150 151func (e ApplyWithdraw) Ptr() *ApplyWithdraw { 152 return &e 153} 154 155const ( 156 APPLYWITHDRAW_NOT_APPLY_WITHDRAW ApplyWithdraw = "NOT_APPLY_WITHDRAW" 157 APPLYWITHDRAW_APPLY_WITHDRAW ApplyWithdraw = "APPLY_WITHDRAW" 158) 159 160type WithdrawState string 161 162func (e WithdrawState) Ptr() *WithdrawState { 163 return &e 164} 165 166const ( 167 WITHDRAWSTATE_WITHDRAW_PROCESSING WithdrawState = "WITHDRAW_PROCESSING" 168 WITHDRAWSTATE_WITHDRAW_EXCEPTION WithdrawState = "WITHDRAW_EXCEPTION" 169 WITHDRAWSTATE_WITHDRAW_SUCCEED WithdrawState = "WITHDRAW_SUCCEED" 170) 171 172type AccountWithdrawResult struct { 173 OutAccountType *OutAccountType `json:"out_account_type,omitempty"` 174 PayState *PayState `json:"pay_state,omitempty"` 175 StateDescription *string `json:"state_description,omitempty"` 176} 177 178type AccountInfo struct { 179 OutAccountType *OutAccountType `json:"out_account_type,omitempty"` 180 Amount *int64 `json:"amount,omitempty"` 181} 182 183type OutAccountType string 184 185func (e OutAccountType) Ptr() *OutAccountType { 186 return &e 187} 188 189const ( 190 OUTACCOUNTTYPE_BASIC_ACCOUNT OutAccountType = "BASIC_ACCOUNT" 191 OUTACCOUNTTYPE_OPERATE_ACCOUNT OutAccountType = "OPERATE_ACCOUNT" 192 OUTACCOUNTTYPE_MARGIN_ACCOUNT OutAccountType = "MARGIN_ACCOUNT" 193 OUTACCOUNTTYPE_TRADE_FEE_ACCOUNT OutAccountType = "TRADE_FEE_ACCOUNT" 194) 195 196type PayState string 197 198func (e PayState) Ptr() *PayState { 199 return &e 200} 201 202const ( 203 PAYSTATE_PAY_PROCESSING PayState = "PAY_PROCESSING" 204 PAYSTATE_PAY_SUCCEED PayState = "PAY_SUCCEED" 205 PAYSTATE_PAY_FAIL PayState = "PAY_FAIL" 206 PAYSTATE_BANK_REFUNDED PayState = "BANK_REFUNDED" 207) 208
应答参数
200 OK
applyment_id 选填 string(32)
【微信支付注销提现申请单号】 电商平台提交注销申请后,由微信支付返回的申请单号,作为查询申请状态的唯一标识。
out_request_no 选填 string(32)
【商户注销申请单号】 商户注销申请单号,由商户自定义生成,需要全局唯一
cancel_state 选填 string
【注销提现申请单状态】 发起注销提现申请后,整个流程可能流转的状态
可选取值
ACCEPTED
: 已受理REVIEWING
: 审核中REJECTED
: 审批驳回WAITING_MERCHANT_CONFIRM
: 等待商户确认REVOKED
: 已撤销SYSTEM_PROCESSING
: 系统处理中CANCELED
: 已注销FUND_PROCESSING
: 资金处理中FINISH
: 注销完成
cancel_state_description 选填 string(256)
【注销提现申请单状态描述】 注销提现申请单状态的文字描述
withdraw 选填 string
【是否提取资金】 在提交接口传入的是否提取资金标记
可选取值
NOT_APPLY_WITHDRAW
: 仅注销,不申请提现APPLY_WITHDRAW
: 申请提现
withdraw_state 选填 string
【提现状态】 当申请单进入「资金处理中」状态时,返回此状态,反映资金提现的处理进度
可选取值
WITHDRAW_PROCESSING
: 提现处理中WITHDRAW_EXCEPTION
: 提现异常WITHDRAW_SUCCEED
: 提现成功
withdraw_state_description 选填 string(256)
【提现状态描述】 提现申请单状态的文字描述
account_withdraw_result 选填 array[object]
【账户提现结果】 对具体账户发起提现操作后返回,商户已开通的账户参见account_info
字段返回,微信支付注销提现流程会将商户账户里所有遗留的资金全额清退,请平台做好资金对账。多个账户存在资金时,将会有多笔提现金额,请注意核对银行入账流水
属性 | |
out_account_type 必填 string 【二级商户号的出款子账户类型】 仅返回已开通的账户类型 可选取值
pay_state 必填 string 【付款状态】 付款状态 可选取值
state_description 必填 string(256) 【付款状态描述】 付款状态描述 |
modify_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秒。
sub_mchid 选填 string(32)
【申请注销的二级商户号】 平台商户的二级商户号,由微信支付生成并下发
account_info 选填 array[object]
【账户信息】 二级商户号已开通的账户信息,仅涉及提取资金类的申请单返回,单据受理及后续状态返回
属性 | |
out_account_type 必填 string 【二级商户号的出款子账户类型】 仅返回已开通的账户类型 可选取值
amount 选填 integer 【账户金额】 单位:分 |
应答示例
200 OK
1{ 2 "applyment_id" : "X202410241010125346", 3 "out_request_no" : "P202410241010125346", 4 "cancel_state" : "FUND_PROCESSING", 5 "cancel_state_description" : "资金处理中", 6 "withdraw" : "APPLY_WITHDRAW", 7 "withdraw_state" : "WITHDRAW_PROCESSING", 8 "withdraw_state_description" : "提现处理中", 9 "account_withdraw_result" : [ 10 { 11 "out_account_type" : "BASIC_ACCOUNT", 12 "pay_state" : "PAY_SUCCEED", 13 "state_description" : "付款成功" 14 } 15 ], 16 "modify_time" : "2015-05-20T13:29:35+08:00", 17 "sub_mchid" : "1900000109", 18 "account_info" : [ 19 { 20 "out_account_type" : "BASIC_ACCOUNT", 21 "amount" : 101 22 } 23 ] 24} 25
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |