撤销申请单
更新时间:2024.12.04服务商提交申请单后需要修改信息时,或者申请单审核结果为”已驳回“时服务商要修改申请材料时,均需要先调用撤销申请单接口。
接口说明
支持商户:【渠道商】 【从业机构(银行)】 【从业机构(支付机构)】
请求方式:【POST】/v3/apply4subject/applyment/{business_code}/cancel 或 /v3/apply4subject/applyment/{applyment_id}/cancel
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
business_code 选填 string(128)
【业务申请编号】
1、申请单编号和业务申请编号至少传一个。
2、服务商自定义的唯一编号。
3、每个编号对应一个申请单。
applyment_id 选填 integer
【申请单编号】
1、微信支付分配的申请单号。
2、申请单编号和业务申请编号至少传一个。
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/apply4subject/applyment/1900013511_10000/cancel?applyment_id=20000011111 \ 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 CancelApplyment { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/apply4subject/applyment/{business_code}/cancel"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 CancelApplyment client = new CancelApplyment( 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 CancelApplymentRequest request = new CancelApplymentRequest(); 41 request.businessCode = "1900013511_10000"; 42 request.applymentId = 20000011111L; 43 try { 44 client.run(request); 45 } catch (WXPayUtility.ApiException e) { 46 // TODO: 请求失败,根据状态码执行不同的逻辑 47 e.printStackTrace(); 48 } 49 } 50 51 public void run(CancelApplymentRequest request) { 52 String uri = PATH; 53 uri = uri.replace("{business_code}", WXPayUtility.urlEncode(request.businessCode)); 54 Map<String, Object> args = new HashMap<>(); 55 args.put("applyment_id", request.applymentId); 56 String queryString = WXPayUtility.urlEncode(args); 57 if (!queryString.isEmpty()) { 58 uri = uri + "?" + queryString; 59 } 60 61 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 62 reqBuilder.addHeader("Accept", "application/json"); 63 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 64 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 65 reqBuilder.addHeader("Content-Type", "application/json"); 66 RequestBody emptyBody = RequestBody.create(null, ""); 67 reqBuilder.method(METHOD, emptyBody); 68 Request httpRequest = reqBuilder.build(); 69 70 // 发送HTTP请求 71 OkHttpClient client = new OkHttpClient.Builder().build(); 72 try (Response httpResponse = client.newCall(httpRequest).execute()) { 73 String respBody = WXPayUtility.extractBody(httpResponse); 74 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 75 // 2XX 成功,验证应答签名 76 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 77 httpResponse.headers(), respBody); 78 79 return; 80 } else { 81 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 82 } 83 } catch (IOException e) { 84 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 85 } 86 } 87 88 private final String mchid; 89 private final String certificateSerialNo; 90 private final PrivateKey privateKey; 91 private final String wechatPayPublicKeyId; 92 private final PublicKey wechatPayPublicKey; 93 94 public CancelApplyment(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 95 this.mchid = mchid; 96 this.certificateSerialNo = certificateSerialNo; 97 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 98 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 99 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 100 } 101 102 public static class CancelApplymentRequest { 103 @SerializedName("applyment_id") 104 @Expose(serialize = false) 105 public Long applymentId; 106 107 @SerializedName("business_code") 108 @Expose(serialize = false) 109 public String businessCode; 110 } 111 112} 113
需配合微信支付工具库 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 := &CancelApplymentRequest{ 27 ApplymentId: wxpay_utility.Int64(20000011111), 28 BusinessCode: wxpay_utility.String("1900013511_10000"), 29 } 30 31 err = CancelApplyment(config, request) 32 if err != nil { 33 fmt.Printf("请求失败: %+v\n", err) 34 // TODO: 请求失败,根据状态码执行不同的处理 35 return 36 } 37 38 // TODO: 请求成功,继续业务逻辑 39 fmt.Println("请求成功") 40} 41 42func CancelApplyment(config *wxpay_utility.MchConfig, request *CancelApplymentRequest) (err error) { 43 const ( 44 host = "https://api.mch.weixin.qq.com" 45 method = "POST" 46 path = "/v3/apply4subject/applyment/{business_code}/cancel" 47 ) 48 49 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 50 if err != nil { 51 return err 52 } 53 reqUrl.Path = strings.Replace(reqUrl.Path, "{business_code}", url.PathEscape(*request.BusinessCode), -1) 54 query := reqUrl.Query() 55 if request.ApplymentId != nil { 56 query.Add("applyment_id", fmt.Sprintf("%v", *request.ApplymentId)) 57 } 58 reqUrl.RawQuery = query.Encode() 59 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 60 if err != nil { 61 return err 62 } 63 httpRequest.Header.Set("Accept", "application/json") 64 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 65 httpRequest.Header.Set("Content-Type", "application/json") 66 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 67 if err != nil { 68 return err 69 } 70 httpRequest.Header.Set("Authorization", authorization) 71 72 client := &http.Client{} 73 httpResponse, err := client.Do(httpRequest) 74 if err != nil { 75 return err 76 } 77 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 78 if err != nil { 79 return err 80 } 81 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 82 // 2XX 成功,验证应答签名 83 err = wxpay_utility.ValidateResponse( 84 config.WechatPayPublicKeyId(), 85 config.WechatPayPublicKey(), 86 &httpResponse.Header, 87 respBody, 88 ) 89 if err != nil { 90 return err 91 } 92 return nil 93 } else { 94 return wxpay_utility.NewApiException( 95 httpResponse.StatusCode, 96 httpResponse.Header, 97 respBody, 98 ) 99 } 100} 101 102type CancelApplymentRequest struct { 103 ApplymentId *int64 `json:"applyment_id,omitempty"` 104 BusinessCode *string `json:"business_code,omitempty"` 105} 106 107func (o *CancelApplymentRequest) MarshalJSON() ([]byte, error) { 108 type Alias CancelApplymentRequest 109 a := &struct { 110 ApplymentId *int64 `json:"applyment_id,omitempty"` 111 BusinessCode *string `json:"business_code,omitempty"` 112 *Alias 113 }{ 114 // 序列化时移除非 Body 字段 115 ApplymentId: nil, 116 BusinessCode: nil, 117 Alias: (*Alias)(o), 118 } 119 return json.Marshal(a) 120} 121
应答参数
无应答包体
应答示例
204 No Content
1'无应答包体' 2
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
500 | SYSTEM_ERROR | 系统错误 | 系统异常,请使用相同参数稍后重新调用 |
400 | INVALID_REQUEST | 无效请求 | 请查看返回的错误信息,根据错误信息进行操作 |
403 | NO_AUTH | 商户权限异常 | 请确认是否已经开通相关权限 |