添加商户标识
更新时间:2026.01.15添加商户标识。该接口允许服务商向已存在的可用商户范围中添加商户标识。根据商户标识类型,可以添加统一社会信用代码或微信支付订单号,用于精确控制额度卡的可用范围。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers
请求域名:【主域名】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】 出资服务商限制的额度卡可用商户范围列表的唯一标识
body 包体参数
sp_mchid 必填 string(32)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
merchant_identifier 必填 string(64)
【商户标识值】 根据商户标识类型传参:统一社会信用代码类型时传"统一社会信用代码",微信支付订单号类型时传"微信支付订单号"
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/webizpay/avail-mch-ranges/89f5123e-5ad4-4e0e-89b1-63ced0c798c5/merchant-identifiers \ 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 "merchant_identifier" : "91110000710926094P" 9 }' 10
需配合微信支付工具库 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 AddMerchantsToAvailMchRange { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 AddMerchantsToAvailMchRange client = new AddMerchantsToAvailMchRange( 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 AddMerchantsToAvailMchRangeRequest request = new AddMerchantsToAvailMchRangeRequest(); 41 request.rangeId = "89f5123e-5ad4-4e0e-89b1-63ced0c798c5"; 42 request.spMchid = "12341234"; 43 request.merchantIdentifier = "91110000710926094P"; 44 try { 45 AvailMchRangeAddMerchantsResponse 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 AvailMchRangeAddMerchantsResponse run(AddMerchantsToAvailMchRangeRequest request) { 55 String uri = PATH; 56 uri = uri.replace("{range_id}", WXPayUtility.urlEncode(request.rangeId)); 57 String reqBody = WXPayUtility.toJson(request); 58 59 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 60 reqBuilder.addHeader("Accept", "application/json"); 61 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 62 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 63 reqBuilder.addHeader("Content-Type", "application/json"); 64 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 65 reqBuilder.method(METHOD, requestBody); 66 Request httpRequest = reqBuilder.build(); 67 68 // 发送HTTP请求 69 OkHttpClient client = new OkHttpClient.Builder().build(); 70 try (Response httpResponse = client.newCall(httpRequest).execute()) { 71 String respBody = WXPayUtility.extractBody(httpResponse); 72 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 73 // 2XX 成功,验证应答签名 74 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 75 httpResponse.headers(), respBody); 76 77 // 从HTTP应答报文构建返回数据 78 return WXPayUtility.fromJson(respBody, AvailMchRangeAddMerchantsResponse.class); 79 } else { 80 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 81 } 82 } catch (IOException e) { 83 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 84 } 85 } 86 87 private final String mchid; 88 private final String certificateSerialNo; 89 private final PrivateKey privateKey; 90 private final String wechatPayPublicKeyId; 91 private final PublicKey wechatPayPublicKey; 92 93 public AddMerchantsToAvailMchRange(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 94 this.mchid = mchid; 95 this.certificateSerialNo = certificateSerialNo; 96 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 97 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 98 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 99 } 100 101 public static class AddMerchantsToAvailMchRangeRequest { 102 @SerializedName("sp_mchid") 103 public String spMchid; 104 105 @SerializedName("range_id") 106 @Expose(serialize = false) 107 public String rangeId; 108 109 @SerializedName("merchant_identifier") 110 public String merchantIdentifier; 111 } 112 113 public static class AvailMchRangeAddMerchantsResponse { 114 @SerializedName("range_id") 115 public String rangeId; 116 } 117 118} 119
需配合微信支付工具库 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 := &AddMerchantsToAvailMchRangeRequest{ 28 RangeId: wxpay_utility.String("89f5123e-5ad4-4e0e-89b1-63ced0c798c5"), 29 SpMchid: wxpay_utility.String("12341234"), 30 MerchantIdentifier: wxpay_utility.String("91110000710926094P"), 31 } 32 33 response, err := AddMerchantsToAvailMchRange(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 AddMerchantsToAvailMchRange(config *wxpay_utility.MchConfig, request *AddMerchantsToAvailMchRangeRequest) (response *AvailMchRangeAddMerchantsResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "POST" 48 path = "/v3/webizpay/avail-mch-ranges/{range_id}/merchant-identifiers" 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 reqBody, err := json.Marshal(request) 57 if err != nil { 58 return nil, err 59 } 60 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest.Header.Set("Accept", "application/json") 65 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 66 httpRequest.Header.Set("Content-Type", "application/json") 67 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 68 if err != nil { 69 return nil, err 70 } 71 httpRequest.Header.Set("Authorization", authorization) 72 73 client := &http.Client{} 74 httpResponse, err := client.Do(httpRequest) 75 if err != nil { 76 return nil, err 77 } 78 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 79 if err != nil { 80 return nil, err 81 } 82 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 83 // 2XX 成功,验证应答签名 84 err = wxpay_utility.ValidateResponse( 85 config.WechatPayPublicKeyId(), 86 config.WechatPayPublicKey(), 87 &httpResponse.Header, 88 respBody, 89 ) 90 if err != nil { 91 return nil, err 92 } 93 response := &AvailMchRangeAddMerchantsResponse{} 94 if err := json.Unmarshal(respBody, response); err != nil { 95 return nil, err 96 } 97 98 return response, nil 99 } else { 100 return nil, wxpay_utility.NewApiException( 101 httpResponse.StatusCode, 102 httpResponse.Header, 103 respBody, 104 ) 105 } 106} 107 108type AddMerchantsToAvailMchRangeRequest struct { 109 SpMchid *string `json:"sp_mchid,omitempty"` 110 RangeId *string `json:"range_id,omitempty"` 111 MerchantIdentifier *string `json:"merchant_identifier,omitempty"` 112} 113 114func (o *AddMerchantsToAvailMchRangeRequest) MarshalJSON() ([]byte, error) { 115 type Alias AddMerchantsToAvailMchRangeRequest 116 a := &struct { 117 RangeId *string `json:"range_id,omitempty"` 118 *Alias 119 }{ 120 // 序列化时移除非 Body 字段 121 RangeId: nil, 122 Alias: (*Alias)(o), 123 } 124 return json.Marshal(a) 125} 126 127type AvailMchRangeAddMerchantsResponse struct { 128 RangeId *string `json:"range_id,omitempty"` 129} 130
应答参数
200 OK
range_id 必填 string(64)
【可用商户范围id】 出资服务商限制的额度卡可用商户范围列表的唯一标识
应答示例
200 OK
1{ 2 "range_id" : "89f5123e-5ad4-4e0e-89b1-63ced0c798c5" 3} 4
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

