查询批次关联门店列表
更新时间:2025.08.04品牌方可以通过该接口分页查询商品券批次所关联的门店列表
前置条件:已创建商品券批次且批次的 store_scope
为 SPECIFIC
接口说明
支持商户:【普通服务商】
请求方式:【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/200000001/stocks/123456789/associated-stores?page_size=20&page_token=MTIzMjUK&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 , 37 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 38 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 39 ); 40 41 ListAssociatedStoresRequest request = new ListAssociatedStoresRequest(); 42 request.productCouponId = "200000001"; 43 request.stockId = "123456789"; 44 request.pageSize = 20L; 45 request.pageToken = "MTIzMjUK"; 46 request.brandId = "120344"; 47 try { 48 ListAssociatedStoresResponse response = client.run(request); 49 // TODO: 请求成功,继续业务逻辑 50 System.out.println(response); 51 } catch (WXPayUtility.ApiException e) { 52 // TODO: 请求失败,根据状态码执行不同的逻辑 53 e.printStackTrace(); 54 } 55 } 56 57 public ListAssociatedStoresResponse run(ListAssociatedStoresRequest request) { 58 String uri = PATH; 59 uri = uri.replace("{product_coupon_id}", WXPayUtility.urlEncode(request.productCouponId)); 60 uri = uri.replace("{stock_id}", WXPayUtility.urlEncode(request.stockId)); 61 Map<String, Object> args = new HashMap<>(); 62 args.put("page_size", request.pageSize); 63 args.put("page_token", request.pageToken); 64 args.put("brand_id", request.brandId); 65 uri = uri + "?" + WXPayUtility.urlEncode(args); 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, ListAssociatedStoresResponse.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 ListAssociatedStores(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 ListAssociatedStoresRequest { 108 @SerializedName("product_coupon_id") 109 @Expose(serialize = false) 110 public String productCouponId; 111 112 @SerializedName("stock_id") 113 @Expose(serialize = false) 114 public String stockId; 115 116 @SerializedName("page_size") 117 @Expose(serialize = false) 118 public Long pageSize; 119 120 @SerializedName("page_token") 121 @Expose(serialize = false) 122 public String pageToken; 123 124 @SerializedName("brand_id") 125 @Expose(serialize = false) 126 public String brandId; 127 } 128 129 public static class ListAssociatedStoresResponse { 130 @SerializedName("total_count") 131 public Long totalCount; 132 133 @SerializedName("store_list") 134 public List<StoreInfo> storeList; 135 136 @SerializedName("next_page_token") 137 public String nextPageToken; 138 } 139 140 public static class StoreInfo { 141 @SerializedName("store_id") 142 public String storeId; 143 } 144 145} 146
需配合微信支付工具库 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("200000001"), 28 StockId: wxpay_utility.String("123456789"), 29 PageSize: wxpay_utility.Int64(20), 30 PageToken: wxpay_utility.String("MTIzMjUK"), 31 BrandId: wxpay_utility.String("120344"), 32 } 33 34 response, err := ListAssociatedStores(config, request) 35 if err != nil { 36 fmt.Printf("请求失败: %+v\n", err) 37 // TODO: 请求失败,根据状态码执行不同的处理 38 return 39 } 40 41 // TODO: 请求成功,继续业务逻辑 42 fmt.Printf("请求成功: %+v\n", response) 43} 44 45func ListAssociatedStores(config *wxpay_utility.MchConfig, request *ListAssociatedStoresRequest) (response *ListAssociatedStoresResponse, err error) { 46 const ( 47 host = "https://api.mch.weixin.qq.com" 48 method = "GET" 49 path = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/associated-stores" 50 ) 51 52 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 53 if err != nil { 54 return nil, err 55 } 56 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 57 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_id}", url.PathEscape(*request.StockId), -1) 58 query := reqUrl.Query() 59 if request.PageSize != nil { 60 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 61 } 62 if request.PageToken != nil { 63 query.Add("page_token", *request.PageToken) 64 } 65 if request.BrandId != nil { 66 query.Add("brand_id", *request.BrandId) 67 } 68 reqUrl.RawQuery = query.Encode() 69 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 70 if err != nil { 71 return nil, err 72 } 73 httpRequest.Header.Set("Accept", "application/json") 74 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 75 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 76 if err != nil { 77 return nil, err 78 } 79 httpRequest.Header.Set("Authorization", authorization) 80 81 client := &http.Client{} 82 httpResponse, err := client.Do(httpRequest) 83 if err != nil { 84 return nil, err 85 } 86 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 87 if err != nil { 88 return nil, err 89 } 90 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 91 // 2XX 成功,验证应答签名 92 err = wxpay_utility.ValidateResponse( 93 config.WechatPayPublicKeyId(), 94 config.WechatPayPublicKey(), 95 &httpResponse.Header, 96 respBody, 97 ) 98 if err != nil { 99 return nil, err 100 } 101 response := &ListAssociatedStoresResponse{} 102 if err := json.Unmarshal(respBody, response); err != nil { 103 return nil, err 104 } 105 106 return response, nil 107 } else { 108 return nil, wxpay_utility.NewApiException( 109 httpResponse.StatusCode, 110 httpResponse.Header, 111 respBody, 112 ) 113 } 114} 115 116type ListAssociatedStoresRequest struct { 117 ProductCouponId *string `json:"product_coupon_id,omitempty"` 118 StockId *string `json:"stock_id,omitempty"` 119 PageSize *int64 `json:"page_size,omitempty"` 120 PageToken *string `json:"page_token,omitempty"` 121 BrandId *string `json:"brand_id,omitempty"` 122} 123 124func (o *ListAssociatedStoresRequest) MarshalJSON() ([]byte, error) { 125 type Alias ListAssociatedStoresRequest 126 a := &struct { 127 ProductCouponId *string `json:"product_coupon_id,omitempty"` 128 StockId *string `json:"stock_id,omitempty"` 129 PageSize *int64 `json:"page_size,omitempty"` 130 PageToken *string `json:"page_token,omitempty"` 131 BrandId *string `json:"brand_id,omitempty"` 132 *Alias 133 }{ 134 // 序列化时移除非 Body 字段 135 ProductCouponId: nil, 136 StockId: nil, 137 PageSize: nil, 138 PageToken: nil, 139 BrandId: nil, 140 Alias: (*Alias)(o), 141 } 142 return json.Marshal(a) 143} 144 145type ListAssociatedStoresResponse struct { 146 TotalCount *int64 `json:"total_count,omitempty"` 147 StoreList []StoreInfo `json:"store_list,omitempty"` 148 NextPageToken *string `json:"next_page_token,omitempty"` 149} 150 151type StoreInfo struct { 152 StoreId *string `json:"store_id,omitempty"` 153} 154
应答参数
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" : 500, 3 "store_list" : [ 4 { 5 "store_id" : "100000001" 6 } 7 ], 8 "next_page_token" : "MTIzNDUK" 9} 10
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
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 再调用本接口 |
403 | NO_AUTH | 缺少业务相关权限 | 请确认已开通商品券权限 |
404 | NOT_FOUND | 未找到 product_coupon_id 对应的商品券 | 请确认 product_coupon_id 存在且属于当前品牌 |
404 | NOT_FOUND | 未找到 stock_id 对应的商品券批次 | 请确认 stock_id 存在且属于当前商品券 |
429 | RATELIMIT_EXCEEDED | 请求超过接口频率限制 | 请稍后使用原参数重试 |