查询商户标识列表
更新时间:2026.01.15查询商户标识列表。该接口允许服务商查询指定可用商户范围内的所有商户标识。支持分页查询,便于管理大量的商户数据,了解范围内包含的具体商户信息。
接口说明
支持商户:【普通服务商】
请求方式:【GET】/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
path 路径参数
range_id 必填 string(64)
【可用商户范围id】 出资服务商限制的额度卡可用商户范围列表的唯一标识
query 查询参数
sp_mchid 必填 string(32)
【服务商商户号】 是由微信支付系统生成并分配给每个服务商的唯一标识符,具体请参考服务商模式开发必要参数说明。
offset 必填 integer
【分页开始位置】 该次请求的分页开始位置,从0开始计数,例如offset=10,表示从第11条记录开始返回。
limit 必填 integer
【分页大小】 分页大小,默认100,最大500
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/webizpay/avail-mch-ranges/89f5123e-5ad4-4e0e-89b1-63ced0c798c5/merchant-identifiers?sp_mchid=12341234&offset=0&limit=100 \ 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 QueryMerchantsInAvailMchRange { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 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 QueryMerchantsInAvailMchRange client = new QueryMerchantsInAvailMchRange( 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 QueryMerchantsInAvailMchRangeRequest request = new QueryMerchantsInAvailMchRangeRequest(); 41 request.rangeId = "89f5123e-5ad4-4e0e-89b1-63ced0c798c5"; 42 request.spMchid = "12341234"; 43 request.offset = 0L; 44 request.limit = 100L; 45 try { 46 AvailMchRangeQueryMerchantsResponse response = client.run(request); 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public AvailMchRangeQueryMerchantsResponse run(QueryMerchantsInAvailMchRangeRequest request) { 56 String uri = PATH; 57 uri = uri.replace("{range_id}", WXPayUtility.urlEncode(request.rangeId)); 58 Map<String, Object> args = new HashMap<>(); 59 args.put("sp_mchid", request.spMchid); 60 args.put("offset", request.offset); 61 args.put("limit", request.limit); 62 String queryString = WXPayUtility.urlEncode(args); 63 if (!queryString.isEmpty()) { 64 uri = uri + "?" + queryString; 65 } 66 67 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 68 reqBuilder.addHeader("Accept", "application/json"); 69 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 70 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 71 reqBuilder.method(METHOD, null); 72 Request httpRequest = reqBuilder.build(); 73 74 // 发送HTTP请求 75 OkHttpClient client = new OkHttpClient.Builder().build(); 76 try (Response httpResponse = client.newCall(httpRequest).execute()) { 77 String respBody = WXPayUtility.extractBody(httpResponse); 78 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 79 // 2XX 成功,验证应答签名 80 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 81 httpResponse.headers(), respBody); 82 83 // 从HTTP应答报文构建返回数据 84 return WXPayUtility.fromJson(respBody, AvailMchRangeQueryMerchantsResponse.class); 85 } else { 86 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 87 } 88 } catch (IOException e) { 89 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 90 } 91 } 92 93 private final String mchid; 94 private final String certificateSerialNo; 95 private final PrivateKey privateKey; 96 private final String wechatPayPublicKeyId; 97 private final PublicKey wechatPayPublicKey; 98 99 public QueryMerchantsInAvailMchRange(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 100 this.mchid = mchid; 101 this.certificateSerialNo = certificateSerialNo; 102 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 103 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 104 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 105 } 106 107 public static class QueryMerchantsInAvailMchRangeRequest { 108 @SerializedName("range_id") 109 @Expose(serialize = false) 110 public String rangeId; 111 112 @SerializedName("sp_mchid") 113 @Expose(serialize = false) 114 public String spMchid; 115 116 @SerializedName("offset") 117 @Expose(serialize = false) 118 public Long offset; 119 120 @SerializedName("limit") 121 @Expose(serialize = false) 122 public Long limit; 123 } 124 125 public static class AvailMchRangeQueryMerchantsResponse { 126 @SerializedName("data") 127 public List<String> data; 128 129 @SerializedName("offset") 130 public Long offset; 131 132 @SerializedName("limit") 133 public Long limit; 134 135 @SerializedName("count") 136 public Long count; 137 138 @SerializedName("total_count") 139 public Long totalCount; 140 } 141 142} 143
需配合微信支付工具库 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 := &QueryMerchantsInAvailMchRangeRequest{ 27 RangeId: wxpay_utility.String("89f5123e-5ad4-4e0e-89b1-63ced0c798c5"), 28 SpMchid: wxpay_utility.String("12341234"), 29 Offset: wxpay_utility.Int64(0), 30 Limit: wxpay_utility.Int64(100), 31 } 32 33 response, err := QueryMerchantsInAvailMchRange(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 QueryMerchantsInAvailMchRange(config *wxpay_utility.MchConfig, request *QueryMerchantsInAvailMchRangeRequest) (response *AvailMchRangeQueryMerchantsResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "GET" 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 query := reqUrl.Query() 57 if request.SpMchid != nil { 58 query.Add("sp_mchid", *request.SpMchid) 59 } 60 if request.Offset != nil { 61 query.Add("offset", fmt.Sprintf("%v", *request.Offset)) 62 } 63 if request.Limit != nil { 64 query.Add("limit", fmt.Sprintf("%v", *request.Limit)) 65 } 66 reqUrl.RawQuery = query.Encode() 67 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 68 if err != nil { 69 return nil, err 70 } 71 httpRequest.Header.Set("Accept", "application/json") 72 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 73 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 74 if err != nil { 75 return nil, err 76 } 77 httpRequest.Header.Set("Authorization", authorization) 78 79 client := &http.Client{} 80 httpResponse, err := client.Do(httpRequest) 81 if err != nil { 82 return nil, err 83 } 84 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 85 if err != nil { 86 return nil, err 87 } 88 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 89 // 2XX 成功,验证应答签名 90 err = wxpay_utility.ValidateResponse( 91 config.WechatPayPublicKeyId(), 92 config.WechatPayPublicKey(), 93 &httpResponse.Header, 94 respBody, 95 ) 96 if err != nil { 97 return nil, err 98 } 99 response := &AvailMchRangeQueryMerchantsResponse{} 100 if err := json.Unmarshal(respBody, response); err != nil { 101 return nil, err 102 } 103 104 return response, nil 105 } else { 106 return nil, wxpay_utility.NewApiException( 107 httpResponse.StatusCode, 108 httpResponse.Header, 109 respBody, 110 ) 111 } 112} 113 114type QueryMerchantsInAvailMchRangeRequest struct { 115 RangeId *string `json:"range_id,omitempty"` 116 SpMchid *string `json:"sp_mchid,omitempty"` 117 Offset *int64 `json:"offset,omitempty"` 118 Limit *int64 `json:"limit,omitempty"` 119} 120 121func (o *QueryMerchantsInAvailMchRangeRequest) MarshalJSON() ([]byte, error) { 122 type Alias QueryMerchantsInAvailMchRangeRequest 123 a := &struct { 124 RangeId *string `json:"range_id,omitempty"` 125 SpMchid *string `json:"sp_mchid,omitempty"` 126 Offset *int64 `json:"offset,omitempty"` 127 Limit *int64 `json:"limit,omitempty"` 128 *Alias 129 }{ 130 // 序列化时移除非 Body 字段 131 RangeId: nil, 132 SpMchid: nil, 133 Offset: nil, 134 Limit: nil, 135 Alias: (*Alias)(o), 136 } 137 return json.Marshal(a) 138} 139 140type AvailMchRangeQueryMerchantsResponse struct { 141 Data []string `json:"data,omitempty"` 142 Offset *int64 `json:"offset,omitempty"` 143 Limit *int64 `json:"limit,omitempty"` 144 Count *int64 `json:"count,omitempty"` 145 TotalCount *int64 `json:"total_count,omitempty"` 146} 147
应答参数
200 OK
data 必填 array[string]
【商户标识列表】 商户标识列表,如果当次查询结果为空,返回空数组
offset 必填 integer
【分页开始位置】 该次请求的分页开始位置,从0开始计数,例如offset=10,表示从第11条记录开始返回。
limit 必填 integer
【分页大小】 该次请求的资源条数,同请求入参 limit
count 必填 integer
【实际返回数量】 该次请求实际返回的资源条数。实际返回资源条数应等于 limit,最后一页可小于等于 limit
total_count 必填 integer
【总数量】 该可用商户范围内商户标识的总数量。当 offset=0 或者当前查询为空时应该返回总条数
应答示例
200 OK
1{ 2 "data" : [ 3 "91110000710926094P" 4 ], 5 "offset" : 0, 6 "limit" : 100, 7 "count" : 100, 8 "total_count" : 1000 9} 10
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |

