通过业务申请编号查询申请状态
更新时间:2024.11.28接口适用场景:当服务商提交申请单后,需要定期调用此接口查询申请单的审核状态。
接口说明
支持商户:【平台商户】
请求方式:【GET】/v3/ecommerce/applyments/out-request-no/{out_request_no}
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
out_request_no 必填 string(124)
【业务申请编号】1、服务商自定义的商户唯一编号。
2、每个编号对应一个申请单,每个申请单审核通过后会生成一个微信支付商户号。
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/ecommerce/applyments/out-request-no/APPLYMENT_00000000001 \ 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 GetStateByOutRequestNo { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/ecommerce/applyments/out-request-no/{out_request_no}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 GetStateByOutRequestNo client = new GetStateByOutRequestNo( 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 GetStateByOutRequestNoRequest request = new GetStateByOutRequestNoRequest(); 41 request.outRequestNo = "APPLYMENT_00000000001"; 42 try { 43 GetStateResp 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 GetStateResp run(GetStateByOutRequestNoRequest request) { 53 String uri = PATH; 54 uri = uri.replace("{out_request_no}", WXPayUtility.urlEncode(request.outRequestNo)); 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, GetStateResp.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 GetStateByOutRequestNo(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 GetStateByOutRequestNoRequest { 97 @SerializedName("out_request_no") 98 @Expose(serialize = false) 99 public String outRequestNo; 100 } 101 102 public static class GetStateResp { 103 @SerializedName("applyment_state") 104 public String applymentState; 105 106 @SerializedName("applyment_state_desc") 107 public String applymentStateDesc; 108 109 @SerializedName("sign_url") 110 public String signUrl; 111 112 @SerializedName("sub_mchid") 113 public String subMchid; 114 115 @SerializedName("account_validation") 116 public UpwardBankValidate accountValidation; 117 118 @SerializedName("audit_detail") 119 public List<AuditDetail> auditDetail; 120 121 @SerializedName("legal_validation_url") 122 public String legalValidationUrl; 123 124 @SerializedName("out_request_no") 125 public String outRequestNo; 126 127 @SerializedName("applyment_id") 128 public Long applymentId; 129 130 @SerializedName("sign_state") 131 public String signState; 132 } 133 134 public static class UpwardBankValidate { 135 @SerializedName("account_name") 136 public String accountName; 137 138 @SerializedName("account_no") 139 public String accountNo; 140 141 @SerializedName("pay_amount") 142 public Long payAmount; 143 144 @SerializedName("destination_account_number") 145 public String destinationAccountNumber; 146 147 @SerializedName("destination_account_name") 148 public String destinationAccountName; 149 150 @SerializedName("destination_account_bank") 151 public String destinationAccountBank; 152 153 @SerializedName("city") 154 public String city; 155 156 @SerializedName("remark") 157 public String remark; 158 159 @SerializedName("deadline") 160 public String deadline; 161 } 162 163 public static class AuditDetail { 164 @SerializedName("param_name") 165 public String paramName; 166 167 @SerializedName("reject_reason") 168 public String rejectReason; 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 := &GetStateByOutRequestNoRequest{ 27 OutRequestNo: wxpay_utility.String("APPLYMENT_00000000001"), 28 } 29 30 response, err := GetStateByOutRequestNo(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 GetStateByOutRequestNo(config *wxpay_utility.MchConfig, request *GetStateByOutRequestNoRequest) (response *GetStateResp, err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "GET" 45 path = "/v3/ecommerce/applyments/out-request-no/{out_request_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_request_no}", url.PathEscape(*request.OutRequestNo), -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 := &GetStateResp{} 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 GetStateByOutRequestNoRequest struct { 101 OutRequestNo *string `json:"out_request_no,omitempty"` 102} 103 104func (o *GetStateByOutRequestNoRequest) MarshalJSON() ([]byte, error) { 105 type Alias GetStateByOutRequestNoRequest 106 a := &struct { 107 OutRequestNo *string `json:"out_request_no,omitempty"` 108 *Alias 109 }{ 110 // 序列化时移除非 Body 字段 111 OutRequestNo: nil, 112 Alias: (*Alias)(o), 113 } 114 return json.Marshal(a) 115} 116 117type GetStateResp struct { 118 ApplymentState *string `json:"applyment_state,omitempty"` 119 ApplymentStateDesc *string `json:"applyment_state_desc,omitempty"` 120 SignUrl *string `json:"sign_url,omitempty"` 121 SubMchid *string `json:"sub_mchid,omitempty"` 122 AccountValidation *UpwardBankValidate `json:"account_validation,omitempty"` 123 AuditDetail []AuditDetail `json:"audit_detail,omitempty"` 124 LegalValidationUrl *string `json:"legal_validation_url,omitempty"` 125 OutRequestNo *string `json:"out_request_no,omitempty"` 126 ApplymentId *int64 `json:"applyment_id,omitempty"` 127 SignState *string `json:"sign_state,omitempty"` 128} 129 130type UpwardBankValidate struct { 131 AccountName *string `json:"account_name,omitempty"` 132 AccountNo *string `json:"account_no,omitempty"` 133 PayAmount *int64 `json:"pay_amount,omitempty"` 134 DestinationAccountNumber *string `json:"destination_account_number,omitempty"` 135 DestinationAccountName *string `json:"destination_account_name,omitempty"` 136 DestinationAccountBank *string `json:"destination_account_bank,omitempty"` 137 City *string `json:"city,omitempty"` 138 Remark *string `json:"remark,omitempty"` 139 Deadline *string `json:"deadline,omitempty"` 140} 141 142type AuditDetail struct { 143 ParamName *string `json:"param_name,omitempty"` 144 RejectReason *string `json:"reject_reason,omitempty"` 145} 146
应答参数
200 OK
applyment_state 必填 string(32)
【申请状态】枚举值:
CHECKING:资料校验中
ACCOUNT_NEED_VERIFY:待账户验证
AUDITING:审核中
REJECTED:已驳回
NEED_SIGN:待签约
FINISH:完成
FROZEN:已冻结
CANCELED:已作废
applyment_state_desc 必填 string(1024)
【申请状态描述】申请状态描述, 示例:"审核中"
sign_url 选填 string(256)
【签约链接】1、当申请状态为NEED_SIGN时才返回。
2、建议将链接转为二维码展示,需让申请单-管理者用微信扫码打开,完成签约。
sub_mchid 选填 string(32)
【电商平台二级商户号】当申请状态为NEED_SIGN或FINISH时才返回。
account_validation 选填 object
【汇款账户验证信息】当申请状态为ACCOUNT_NEED_VERIFY 时有返回,可根据指引汇款,完成账户验证
属性 | |
account_name 必填 string(1024) 【付款户名】需商户使用该户名的账户进行汇款。 account_no 选填 string(1024) 【付款卡号】结算账户为对私时会返回,商户需使用该付款卡号进行汇款。 pay_amount 必填 integer 【汇款金额】需要汇款的金额(单位:分)。 destination_account_number 必填 string(128) 【收款卡号】收款账户的卡号 destination_account_name 必填 string(128) 【收款户名】收款账户名 destination_account_bank 必填 string(128) 【开户银行】收款账户的开户银行名称。 city 必填 string(128) 【省市信息】收款账户的省市。 remark 必填 string(128) 【备注信息】商户汇款时,需要填写的备注信息。 deadline 必填 string(128) 【汇款截止时间】请在此时间前完成汇款。 |
audit_detail 选填 array[object]
【驳回原因详情】各项资料的审核情况。当申请状态为REJECTED或 FROZEN时才返回。
属性 | |
param_name 必填 string(32) 【参数名称】提交申请单的资料项名称。 reject_reason 必填 string(1024) 【驳回原因】提交资料项被驳回原因。 |
legal_validation_url 选填 string(256)
【法人验证链接】1、当申请状态为
ACCOUNT_NEED_VERIFY,且通过系统校验的申请单,将返回链接。
2、建议将链接转为二维码展示,让商户法人用微信扫码打开,完成账户验证。
out_request_no 必填 string(128)
【业务申请编号】提交接口填写的业务申请编号
applyment_id 必填 integer
【微信支付申请单号】微信支付分配的申请单号
sign_state 选填 string(32)
【签约状态】1、未签约-UNSIGNED:该状态下,电商平台可查询获取签约链接,引导二级商户的超级管理员完成签约;
2、已签约-SIGNED :指二级商户的超级管理员已完成签约。注意:若申请单被驳回,商户修改了商户主体名称、法人名称、超级管理员信息、主体类型等信息,则需重新签约。
3、不可签约-NOT_SIGNABLE:该状态下,暂不支持超级管理员签约。一般为申请单处于已驳回、已冻结、机器校验中状态,无法签约。
应答示例
200 OK
1{ 2 "applyment_state" : "FINISH", 3 "applyment_state_desc" : "审核中", 4 "sign_url" : "https://pay.weixin.qq.com/public/apply4ec_sign/s?applymentId=2000002126198476&sign=b207b673049a32c858f3aabd7d27c7ec", 5 "sub_mchid" : "1542488631", 6 "account_validation" : { 7 "account_name" : "aOf7Gk2qT26kakkuTZpbFAn7Mb7xcar0LlQaYoi3+LnnWwgAsfaUUTg9+GmYJq6YCz+RiluWHeHFq1lt8n3eIkF0laVvqmAU80xIWGZgWJnRmnRuZxsg0HJZfnUac2JfqyuL8OoyM2YSuYDqdsyvcOlgUQgq8MPCR6pmvhBCmIeJvnVSm8J+L+yx912itUmTDxhdBlu1CFBIUefME9nYB70vCVTNAVXgURkf65mjHMBiE9Y+wrPZVmTIIz3C3PtPVMZYDEvBT4rDdICA3ZYXshYqeOSslSjSMf+MhhC4oaujiISFzq3AE+as7mAEDJly+DgRuVs74msmKUH8pl+3oA==", 8 "account_no" : "aOf7Gk2qT26kakkuTZpbFAn7Mb7xcar0LlQaYoi3+LnnWwgAsfaUUTg9+GmYJq6YCz+RiluWHeHFq1lt8n3eIkF0laVvqmAU80xIWGZgWJnRmnRuZxsg0HJZfnUac2JfqyuL8OoyM2YSuYDqdsyvcOlgUQgq8MPCR6pmvhBCmIeJvnVSm8J+L+yx912itUmTDxhdBlu1CFBIUefME9nYB70vCVTNAVXgURkf65mjHMBiE9Y+wrPZVmTIIz3C3PtPVMZYDEvBT4rDdICA3ZYXshYqeOSslSjSMf+MhhC4oaujiISFzq3AE+as7mAEDJly+DgRuVs74msmKUH8pl+3oA==", 9 "pay_amount" : 124, 10 "destination_account_number" : "7222223333322332", 11 "destination_account_name" : "财付通支付科技有限公司", 12 "destination_account_bank" : "招商银行威盛大厦支行", 13 "city" : "深圳", 14 "remark" : "入驻账户验证", 15 "deadline" : "2018-12-10 17:09:01" 16 }, 17 "audit_detail" : [ 18 { 19 "param_name" : "id_card_copy", 20 "reject_reason" : "身份证背面识别失败,请上传更清晰的身份证图片。" 21 } 22 ], 23 "legal_validation_url" : "https://pay.weixin.qq.com/public/apply4ec_sign/s?applymentId=2000002126198476&sign=b207b673049a32c858f3aabd7d27c7ec", 24 "out_request_no" : "APPLYMENT_00000000001", 25 "applyment_id" : 2000002124775691, 26 "sign_state" : "SIGNED" 27} 28
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | RESOURCE_ALREADY_EXISTS | 存在流程进行中的申请单,请检查是否重入 | 可通过查询申请状态查看此申请单的申请状态,或更换out_request_no提交新的申请单 |
403 | NO_AUTH | 商户权限异常 | 请确认是否已经开通相关权限 |
404 | RESOURCE_NOT_EXISTS | 申请单不存在 | 确认入参,传入正确的申请单编号 |
500 | RATELIMIT_EXCEEDED | 系统错误 | 系统异常,请使用相同参数稍后重新调用 |