查询批次关联门店列表
更新时间:2025.11.07服务商可以通过该接口分页查询商品券批次所关联的门店列表
前置条件:
批次的
store_scope为SPECIFIC批次未失效或过期
频率限制:20/s
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/associated-stores
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
product_coupon_id 必填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成
stock_id 必填 string
【批次ID】 商品券批次的唯一标识,商品券批次创建时由微信支付生成(可使用创建商品券或添加商品券批次创建),请确保该批次属于 product_coupon_id 对应的商品券
query 查询参数
page_size 选填 integer
【分页大小】 单次拉取的数据条数上限,不填默认为20,最大值200
page_token 选填 string
【分页Token】 分页查询时,需要传入上一次调用返回的 next_page_token,首次调用不填
brand_id 必填 string
【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系
请求示例
GET
查询已关联门店列表
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/product-coupon/product-coupons/1000000013/stocks/1000000013001/associated-stores?page_size=2&brand_id=120344 \ 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 ListAssociatedStores { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/associated-stores"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ListAssociatedStores client = new ListAssociatedStores( 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 ListAssociatedStoresRequest request = new ListAssociatedStoresRequest(); 41 request.productCouponId = "1000000013"; 42 request.stockId = "1000000013001"; 43 request.pageSize = 2L; 44 request.brandId = "120344"; 45 try { 46 ListAssociatedStoresResponse 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 ListAssociatedStoresResponse run(ListAssociatedStoresRequest request) { 56 String uri = PATH; 57 uri = uri.replace("{product_coupon_id}", WXPayUtility.urlEncode(request.productCouponId)); 58 uri = uri.replace("{stock_id}", WXPayUtility.urlEncode(request.stockId)); 59 Map<String, Object> args = new HashMap<>(); 60 args.put("page_size", request.pageSize); 61 args.put("page_token", request.pageToken); 62 args.put("brand_id", request.brandId); 63 String queryString = WXPayUtility.urlEncode(args); 64 if (!queryString.isEmpty()) { 65 uri = uri + "?" + queryString; 66 } 67 68 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 69 reqBuilder.addHeader("Accept", "application/json"); 70 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 71 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 72 reqBuilder.method(METHOD, null); 73 Request httpRequest = reqBuilder.build(); 74 75 // 发送HTTP请求 76 OkHttpClient client = new OkHttpClient.Builder().build(); 77 try (Response httpResponse = client.newCall(httpRequest).execute()) { 78 String respBody = WXPayUtility.extractBody(httpResponse); 79 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 80 // 2XX 成功,验证应答签名 81 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 82 httpResponse.headers(), respBody); 83 84 // 从HTTP应答报文构建返回数据 85 return WXPayUtility.fromJson(respBody, ListAssociatedStoresResponse.class); 86 } else { 87 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 88 } 89 } catch (IOException e) { 90 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 91 } 92 } 93 94 private final String mchid; 95 private final String certificateSerialNo; 96 private final PrivateKey privateKey; 97 private final String wechatPayPublicKeyId; 98 private final PublicKey wechatPayPublicKey; 99 100 public ListAssociatedStores(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 101 this.mchid = mchid; 102 this.certificateSerialNo = certificateSerialNo; 103 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 104 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 105 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 106 } 107 108 public static class ListAssociatedStoresRequest { 109 @SerializedName("product_coupon_id") 110 @Expose(serialize = false) 111 public String productCouponId; 112 113 @SerializedName("stock_id") 114 @Expose(serialize = false) 115 public String stockId; 116 117 @SerializedName("page_size") 118 @Expose(serialize = false) 119 public Long pageSize; 120 121 @SerializedName("page_token") 122 @Expose(serialize = false) 123 public String pageToken; 124 125 @SerializedName("brand_id") 126 @Expose(serialize = false) 127 public String brandId; 128 } 129 130 public static class ListAssociatedStoresResponse { 131 @SerializedName("total_count") 132 public Long totalCount; 133 134 @SerializedName("store_list") 135 public List<StoreInfo> storeList; 136 137 @SerializedName("next_page_token") 138 public String nextPageToken; 139 } 140 141 public static class StoreInfo { 142 @SerializedName("store_id") 143 public String storeId; 144 } 145 146} 147
需配合微信支付工具库 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 := &ListAssociatedStoresRequest{ 27 ProductCouponId: wxpay_utility.String("1000000013"), 28 StockId: wxpay_utility.String("1000000013001"), 29 PageSize: wxpay_utility.Int64(2), 30 BrandId: wxpay_utility.String("120344"), 31 } 32 33 response, err := ListAssociatedStores(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 ListAssociatedStores(config *wxpay_utility.MchConfig, request *ListAssociatedStoresRequest) (response *ListAssociatedStoresResponse, err error) { 45 const ( 46 host = "https://api.mch.weixin.qq.com" 47 method = "GET" 48 path = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/associated-stores" 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, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 56 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_id}", url.PathEscape(*request.StockId), -1) 57 query := reqUrl.Query() 58 if request.PageSize != nil { 59 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 60 } 61 if request.PageToken != nil { 62 query.Add("page_token", *request.PageToken) 63 } 64 if request.BrandId != nil { 65 query.Add("brand_id", *request.BrandId) 66 } 67 reqUrl.RawQuery = query.Encode() 68 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 69 if err != nil { 70 return nil, err 71 } 72 httpRequest.Header.Set("Accept", "application/json") 73 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 74 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 75 if err != nil { 76 return nil, err 77 } 78 httpRequest.Header.Set("Authorization", authorization) 79 80 client := &http.Client{} 81 httpResponse, err := client.Do(httpRequest) 82 if err != nil { 83 return nil, err 84 } 85 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 86 if err != nil { 87 return nil, err 88 } 89 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 90 // 2XX 成功,验证应答签名 91 err = wxpay_utility.ValidateResponse( 92 config.WechatPayPublicKeyId(), 93 config.WechatPayPublicKey(), 94 &httpResponse.Header, 95 respBody, 96 ) 97 if err != nil { 98 return nil, err 99 } 100 response := &ListAssociatedStoresResponse{} 101 if err := json.Unmarshal(respBody, response); err != nil { 102 return nil, err 103 } 104 105 return response, nil 106 } else { 107 return nil, wxpay_utility.NewApiException( 108 httpResponse.StatusCode, 109 httpResponse.Header, 110 respBody, 111 ) 112 } 113} 114 115type ListAssociatedStoresRequest struct { 116 ProductCouponId *string `json:"product_coupon_id,omitempty"` 117 StockId *string `json:"stock_id,omitempty"` 118 PageSize *int64 `json:"page_size,omitempty"` 119 PageToken *string `json:"page_token,omitempty"` 120 BrandId *string `json:"brand_id,omitempty"` 121} 122 123func (o *ListAssociatedStoresRequest) MarshalJSON() ([]byte, error) { 124 type Alias ListAssociatedStoresRequest 125 a := &struct { 126 ProductCouponId *string `json:"product_coupon_id,omitempty"` 127 StockId *string `json:"stock_id,omitempty"` 128 PageSize *int64 `json:"page_size,omitempty"` 129 PageToken *string `json:"page_token,omitempty"` 130 BrandId *string `json:"brand_id,omitempty"` 131 *Alias 132 }{ 133 // 序列化时移除非 Body 字段 134 ProductCouponId: nil, 135 StockId: nil, 136 PageSize: nil, 137 PageToken: nil, 138 BrandId: nil, 139 Alias: (*Alias)(o), 140 } 141 return json.Marshal(a) 142} 143 144type ListAssociatedStoresResponse struct { 145 TotalCount *int64 `json:"total_count,omitempty"` 146 StoreList []StoreInfo `json:"store_list,omitempty"` 147 NextPageToken *string `json:"next_page_token,omitempty"` 148} 149 150type StoreInfo struct { 151 StoreId *string `json:"store_id,omitempty"` 152} 153
应答参数
200 OK
total_count 选填 integer
【总个数】 批次关联的门店总数,当且仅当 page_token 为空时提供
store_list 选填 array[object]
【门店列表】 批次关联的门店列表
| 属性 | |
store_id 必填 string 【门店ID】 门店的唯一标识,调用创建品牌门店时由微信支付生成 |
next_page_token 选填 string(100)
【下一页Token】 分页查询时,如果还有更多数据,会返回下一页的Token,请在下一次查询时设置在 page_token 中;如果已无更多数据,则不返回此字段。
应答示例
200 OK
查询已关联门店列表
1{ 2 "total_count" : 23, 3 "store_list" : [ 4 { 5 "store_id" : "100000001" 6 }, 7 { 8 "store_id" : "100000002" 9 }, 10 { 11 "store_id" : "100000003" 12 } 13 ], 14 "next_page_token" : "MTIzNDUK" 15} 16
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 已过期的批次不可查询关联门店 | 请确认批次是否处于有效期 |
400 | INVALID_REQUEST | 只有 store_scope 为 SPECIFIC 的批次可以查询关联门店 | 请确认批次 store_scope 为 SPECIFIC 再调用本接口 |
404 | NOT_FOUND | 未找到 product_coupon_id 对应的商品券 | 请确认 product_coupon_id 存在且属于当前品牌 |
404 | NOT_FOUND | 未找到 stock_id 对应的商品券批次 | 请确认 stock_id 存在且属于当前商品券 |
429 | RATELIMIT_EXCEEDED | 请求超过接口频率限制 | 请稍后使用原参数重试 |
