删除商户标识
更新时间:2026.01.15删除商户标识。该接口允许服务商从已存在的可用商户范围中删除商户标识。当某个商户标识不再需要被包含在范围内时,可以通过此接口进行移除操作。
接口说明
支持商户:【普通服务商】
请求方式:【DELETE】/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers/{merchant_identifier}
请求域名:【主域名】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
path 路径参数
range_id 必填 string(64)
【可用商户范围id】 出资服务商限制的额度卡可用商户范围列表的唯一标识
merchant_identifier 必填 string(64)
【商户标识值】 根据商户标识类型传参:统一社会信用代码类型时传"统一社会信用代码",微信支付订单号类型时传"微信支付订单号"
body 包体参数
sp_mchid 必填 string(32)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
请求示例
DELETE
1curl -X DELETE \ 2 https://api.mch.weixin.qq.com/v3/webizpay/avail-mch-ranges/89f5123e-5ad4-4e0e-89b1-63ced0c798c5/merchant-identifiers/91110000710926094P \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "sp_mchid" : "12341234" 8 }' 9
需配合微信支付工具库 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 DeleteMerchantsFromAvailMchRange { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "DELETE"; 28 private static String PATH = "/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers/{merchant_identifier}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 DeleteMerchantsFromAvailMchRange client = new DeleteMerchantsFromAvailMchRange( 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 DeleteMerchantsFromAvailMchRangeRequest request = new DeleteMerchantsFromAvailMchRangeRequest(); 41 request.rangeId = "89f5123e-5ad4-4e0e-89b1-63ced0c798c5"; 42 request.merchantIdentifier = "91110000710926094P"; 43 request.spMchid = "12341234"; 44 try { 45 AvailMchRangeDeleteMerchantsResponse response = client.run(request); 46 // TODO: 请求成功,继续业务逻辑 47 System.out.println(response); 48 } catch (WXPayUtility.ApiException e) { 49 // TODO: 请求失败,根据状态码执行不同的逻辑 50 e.printStackTrace(); 51 } 52 } 53 54 public AvailMchRangeDeleteMerchantsResponse run(DeleteMerchantsFromAvailMchRangeRequest request) { 55 String uri = PATH; 56 uri = uri.replace("{range_id}", WXPayUtility.urlEncode(request.rangeId)); 57 uri = uri.replace("{merchant_identifier}", WXPayUtility.urlEncode(request.merchantIdentifier)); 58 String reqBody = WXPayUtility.toJson(request); 59 60 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 61 reqBuilder.addHeader("Accept", "application/json"); 62 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 63 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 64 reqBuilder.addHeader("Content-Type", "application/json"); 65 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 66 reqBuilder.method(METHOD, requestBody); 67 Request httpRequest = reqBuilder.build(); 68 69 // 发送HTTP请求 70 OkHttpClient client = new OkHttpClient.Builder().build(); 71 try (Response httpResponse = client.newCall(httpRequest).execute()) { 72 String respBody = WXPayUtility.extractBody(httpResponse); 73 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 74 // 2XX 成功,验证应答签名 75 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 76 httpResponse.headers(), respBody); 77 78 // 从HTTP应答报文构建返回数据 79 return WXPayUtility.fromJson(respBody, AvailMchRangeDeleteMerchantsResponse.class); 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 DeleteMerchantsFromAvailMchRange(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 DeleteMerchantsFromAvailMchRangeRequest { 103 @SerializedName("range_id") 104 @Expose(serialize = false) 105 public String rangeId; 106 107 @SerializedName("sp_mchid") 108 public String spMchid; 109 110 @SerializedName("merchant_identifier") 111 @Expose(serialize = false) 112 public String merchantIdentifier; 113 } 114 115 public static class AvailMchRangeDeleteMerchantsResponse { 116 @SerializedName("range_id") 117 public String rangeId; 118 } 119 120} 121
需配合微信支付工具库 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 "strings" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &DeleteMerchantsFromAvailMchRangeRequest{ 28 RangeId: wxpay_utility.String("89f5123e-5ad4-4e0e-89b1-63ced0c798c5"), 29 MerchantIdentifier: wxpay_utility.String("91110000710926094P"), 30 SpMchid: wxpay_utility.String("12341234"), 31 } 32 33 response, err := DeleteMerchantsFromAvailMchRange(config, request) 34 if err != nil { 35 fmt.Printf("请求失败: %+v\n", err) 36 // TODO: 请求失败,根据状态码执行不同的处理 37 return 38 } 39 40 // TODO: 请求成功,继续业务逻辑 41 fmt.Printf("请求成功: %+v\n", response) 42} 43 44func DeleteMerchantsFromAvailMchRange(config *wxpay_utility.MchConfig, request *DeleteMerchantsFromAvailMchRangeRequest) (response *AvailMchRangeDeleteMerchantsResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "DELETE" 48 path = "/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers/{merchant_identifier}" 49 ) 50 51 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 52 if err != nil { 53 return nil, err 54 } 55 reqUrl.Path = strings.Replace(reqUrl.Path, "{range_id}", url.PathEscape(*request.RangeId), -1) 56 reqUrl.Path = strings.Replace(reqUrl.Path, "{merchant_identifier}", url.PathEscape(*request.MerchantIdentifier), -1) 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 := &AvailMchRangeDeleteMerchantsResponse{} 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 DeleteMerchantsFromAvailMchRangeRequest struct { 110 RangeId *string `json:"range_id,omitempty"` 111 SpMchid *string `json:"sp_mchid,omitempty"` 112 MerchantIdentifier *string `json:"merchant_identifier,omitempty"` 113} 114 115func (o *DeleteMerchantsFromAvailMchRangeRequest) MarshalJSON() ([]byte, error) { 116 type Alias DeleteMerchantsFromAvailMchRangeRequest 117 a := &struct { 118 RangeId *string `json:"range_id,omitempty"` 119 MerchantIdentifier *string `json:"merchant_identifier,omitempty"` 120 *Alias 121 }{ 122 // 序列化时移除非 Body 字段 123 RangeId: nil, 124 MerchantIdentifier: nil, 125 Alias: (*Alias)(o), 126 } 127 return json.Marshal(a) 128} 129 130type AvailMchRangeDeleteMerchantsResponse struct { 131 RangeId *string `json:"range_id,omitempty"` 132} 133
应答参数
200 OK
range_id 必填 string(64)
【可用商户范围id】 出资服务商限制的额度卡可用商户范围列表的唯一标识
应答示例
200 OK
1{ 2 "range_id" : "89f5123e-5ad4-4e0e-89b1-63ced0c798c5" 3} 4
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

