查询商品券批次列表
更新时间:2025.11.07品牌方可以通过该接口分页查询某个商品券的批次列表。
前置条件:已创建商品券
频率限制:20/s
接口说明
支持商户:【品牌商户】
请求方式:【GET】/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Wechatpay-Serial 必填 string
【微信支付公钥ID】 请传入brand_id对应的微信支付公钥ID,接口将会校验两者的关联关系,参考微信支付公钥产品简介及使用说明获取微信支付公钥ID和相关的介绍。以下两种场景将使用到微信支付公钥: 1、接收到接口的返回内容,需要使用微信支付公钥进行验签; 2、调用含有敏感信息参数(如姓名、身份证号码)的接口时,需要使用微信支付公钥加密敏感信息后再传输参数,加密指引请参考微信支付公钥加密敏感信息指引。
path 路径参数
product_coupon_id 必填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成
query 查询参数
state 选填 string
【批次状态】 不填默认查询所有状态的批次
可选取值
AUDITING: 审批中SENDING: 发放中PAUSED: 已暂停STOPPED: 已停止,当前已到达结束时间DEACTIVATED: 已失效,品牌方主动调用失效接口使批次失效
page_size 选填 integer
【分页大小】 单次拉取的数据条数上限,不填默认为20,最大值50
page_token 选填 string
【分页Token】 分页查询时,需要传入上一次调用返回的 next_page_token,首次调用不填
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/product-coupons/200000001/stocks?state=SENDING&page_size=20&page_token=MTIzMjUK \ 3 -H "Authorization: WECHATPAY-BRAND-SHA256-RSA2048 brand_id=\"XXXX\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: PUB_KEY_ID_XXXX" 6
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayBrandUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/brand/4015826861 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 ListStocks { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 ListStocks client = new ListStocks( 33 "xxxxxxxx", // 品牌ID,是由微信支付系统生成并分配给每个品牌方的唯一标识符,品牌ID获取方式参考 https://pay.weixin.qq.com/doc/brand/4015415289 34 "1DDE55AD98Exxxxxxxxxx", // 品牌API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015407570 35 "/path/to/apiclient_key.pem", // 品牌API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015453439 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 ListStocksRequest request = new ListStocksRequest(); 41 request.productCouponId = "200000001"; 42 request.state = StockState.SENDING; 43 request.pageSize = 20L; 44 request.pageToken = "MTIzMjUK"; 45 try { 46 ListStocksResponse response = client.run(request); 47 // TODO: 请求成功,继续业务逻辑 48 System.out.println(response); 49 } catch (WXPayBrandUtility.ApiException e) { 50 // TODO: 请求失败,根据状态码执行不同的逻辑 51 e.printStackTrace(); 52 } 53 } 54 55 public ListStocksResponse run(ListStocksRequest request) { 56 String uri = PATH; 57 uri = uri.replace("{product_coupon_id}", WXPayBrandUtility.urlEncode(request.productCouponId)); 58 Map<String, Object> args = new HashMap<>(); 59 args.put("state", request.state); 60 args.put("page_size", request.pageSize); 61 args.put("page_token", request.pageToken); 62 String queryString = WXPayBrandUtility.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", WXPayBrandUtility.buildAuthorization(brand_id, 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 = WXPayBrandUtility.extractBody(httpResponse); 78 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 79 // 2XX 成功,验证应答签名 80 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 81 httpResponse.headers(), respBody); 82 83 // 从HTTP应答报文构建返回数据 84 return WXPayBrandUtility.fromJson(respBody, ListStocksResponse.class); 85 } else { 86 throw new WXPayBrandUtility.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 brand_id; 94 private final String certificateSerialNo; 95 private final PrivateKey privateKey; 96 private final String wechatPayPublicKeyId; 97 private final PublicKey wechatPayPublicKey; 98 99 public ListStocks(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 100 this.brand_id = brand_id; 101 this.certificateSerialNo = certificateSerialNo; 102 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 103 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 104 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 105 } 106 107 public static class ListStocksRequest { 108 @SerializedName("product_coupon_id") 109 @Expose(serialize = false) 110 public String productCouponId; 111 112 @SerializedName("page_size") 113 @Expose(serialize = false) 114 public Long pageSize; 115 116 @SerializedName("page_token") 117 @Expose(serialize = false) 118 public String pageToken; 119 120 @SerializedName("state") 121 @Expose(serialize = false) 122 public StockState state; 123 } 124 125 public static class ListStocksResponse { 126 @SerializedName("total_count") 127 public Long totalCount; 128 129 @SerializedName("stock_list") 130 public List<StockEntity> stockList; 131 132 @SerializedName("next_page_token") 133 public String nextPageToken; 134 } 135 136 public enum StockState { 137 @SerializedName("AUDITING") 138 AUDITING, 139 @SerializedName("SENDING") 140 SENDING, 141 @SerializedName("PAUSED") 142 PAUSED, 143 @SerializedName("STOPPED") 144 STOPPED, 145 @SerializedName("DEACTIVATED") 146 DEACTIVATED 147 } 148 149 public static class StockEntity { 150 @SerializedName("product_coupon_id") 151 public String productCouponId; 152 153 @SerializedName("stock_id") 154 public String stockId; 155 156 @SerializedName("remark") 157 public String remark; 158 159 @SerializedName("coupon_code_mode") 160 public CouponCodeMode couponCodeMode; 161 162 @SerializedName("coupon_code_count_info") 163 public CouponCodeCountInfo couponCodeCountInfo; 164 165 @SerializedName("stock_send_rule") 166 public StockSendRule stockSendRule; 167 168 @SerializedName("single_usage_rule") 169 public SingleUsageRule singleUsageRule; 170 171 @SerializedName("sequential_usage_rule") 172 public SequentialUsageRule sequentialUsageRule; 173 174 @SerializedName("usage_rule_display_info") 175 public UsageRuleDisplayInfo usageRuleDisplayInfo; 176 177 @SerializedName("coupon_display_info") 178 public CouponDisplayInfo couponDisplayInfo; 179 180 @SerializedName("notify_config") 181 public NotifyConfig notifyConfig; 182 183 @SerializedName("store_scope") 184 public StockStoreScope storeScope; 185 186 @SerializedName("sent_count_info") 187 public StockSentCountInfo sentCountInfo; 188 189 @SerializedName("state") 190 public StockState state; 191 192 @SerializedName("deactivate_request_no") 193 public String deactivateRequestNo; 194 195 @SerializedName("deactivate_time") 196 public String deactivateTime; 197 198 @SerializedName("deactivate_reason") 199 public String deactivateReason; 200 } 201 202 public enum CouponCodeMode { 203 @SerializedName("WECHATPAY") 204 WECHATPAY, 205 @SerializedName("UPLOAD") 206 UPLOAD, 207 @SerializedName("API_ASSIGN") 208 API_ASSIGN 209 } 210 211 public static class CouponCodeCountInfo { 212 @SerializedName("total_count") 213 public Long totalCount; 214 215 @SerializedName("available_count") 216 public Long availableCount; 217 } 218 219 public static class StockSendRule { 220 @SerializedName("max_count") 221 public Long maxCount; 222 223 @SerializedName("max_count_per_day") 224 public Long maxCountPerDay; 225 226 @SerializedName("max_count_per_user") 227 public Long maxCountPerUser; 228 } 229 230 public static class SingleUsageRule { 231 @SerializedName("coupon_available_period") 232 public SingleCouponAvailablePeriod couponAvailablePeriod; 233 234 @SerializedName("normal_coupon") 235 public NormalCouponUsageRule normalCoupon; 236 237 @SerializedName("discount_coupon") 238 public DiscountCouponUsageRule discountCoupon; 239 240 @SerializedName("exchange_coupon") 241 public ExchangeCouponUsageRule exchangeCoupon; 242 } 243 244 public static class SequentialUsageRule { 245 @SerializedName("coupon_available_period") 246 public SequentialCouponAvailablePeriod couponAvailablePeriod; 247 248 @SerializedName("normal_coupon_list") 249 public List<NormalCouponUsageRule> normalCouponList; 250 251 @SerializedName("discount_coupon_list") 252 public List<DiscountCouponUsageRule> discountCouponList; 253 254 @SerializedName("exchange_coupon_list") 255 public List<ExchangeCouponUsageRule> exchangeCouponList; 256 257 @SerializedName("special_first") 258 public Boolean specialFirst; 259 } 260 261 public static class UsageRuleDisplayInfo { 262 @SerializedName("coupon_usage_method_list") 263 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 264 265 @SerializedName("mini_program_appid") 266 public String miniProgramAppid; 267 268 @SerializedName("mini_program_path") 269 public String miniProgramPath; 270 271 @SerializedName("app_path") 272 public String appPath; 273 274 @SerializedName("usage_description") 275 public String usageDescription; 276 277 @SerializedName("coupon_available_store_info") 278 public CouponAvailableStoreInfo couponAvailableStoreInfo; 279 } 280 281 public static class CouponDisplayInfo { 282 @SerializedName("code_display_mode") 283 public CouponCodeDisplayMode codeDisplayMode; 284 285 @SerializedName("background_color") 286 public String backgroundColor; 287 288 @SerializedName("entrance_mini_program") 289 public EntranceMiniProgram entranceMiniProgram; 290 291 @SerializedName("entrance_official_account") 292 public EntranceOfficialAccount entranceOfficialAccount; 293 294 @SerializedName("entrance_finder") 295 public EntranceFinder entranceFinder; 296 } 297 298 public static class NotifyConfig { 299 @SerializedName("notify_appid") 300 public String notifyAppid; 301 } 302 303 public enum StockStoreScope { 304 @SerializedName("NONE") 305 NONE, 306 @SerializedName("ALL") 307 ALL, 308 @SerializedName("SPECIFIC") 309 SPECIFIC 310 } 311 312 public static class StockSentCountInfo { 313 @SerializedName("total_count") 314 public Long totalCount; 315 316 @SerializedName("today_count") 317 public Long todayCount; 318 } 319 320 public static class SingleCouponAvailablePeriod { 321 @SerializedName("available_begin_time") 322 public String availableBeginTime; 323 324 @SerializedName("available_end_time") 325 public String availableEndTime; 326 327 @SerializedName("available_days") 328 public Long availableDays; 329 330 @SerializedName("wait_days_after_receive") 331 public Long waitDaysAfterReceive; 332 333 @SerializedName("weekly_available_period") 334 public FixedWeekPeriod weeklyAvailablePeriod; 335 336 @SerializedName("irregular_available_period_list") 337 public List<TimePeriod> irregularAvailablePeriodList; 338 } 339 340 public static class NormalCouponUsageRule { 341 @SerializedName("threshold") 342 public Long threshold; 343 344 @SerializedName("discount_amount") 345 public Long discountAmount; 346 } 347 348 public static class DiscountCouponUsageRule { 349 @SerializedName("threshold") 350 public Long threshold; 351 352 @SerializedName("percent_off") 353 public Long percentOff; 354 } 355 356 public static class ExchangeCouponUsageRule { 357 @SerializedName("threshold") 358 public Long threshold; 359 360 @SerializedName("exchange_price") 361 public Long exchangePrice; 362 } 363 364 public static class SequentialCouponAvailablePeriod { 365 @SerializedName("available_begin_time") 366 public String availableBeginTime; 367 368 @SerializedName("available_end_time") 369 public String availableEndTime; 370 371 @SerializedName("wait_days_after_receive") 372 public Long waitDaysAfterReceive; 373 374 @SerializedName("weekly_available_period") 375 public FixedWeekPeriod weeklyAvailablePeriod; 376 377 @SerializedName("irregular_available_period_list") 378 public List<TimePeriod> irregularAvailablePeriodList; 379 } 380 381 public enum CouponUsageMethod { 382 @SerializedName("OFFLINE") 383 OFFLINE, 384 @SerializedName("MINI_PROGRAM") 385 MINI_PROGRAM, 386 @SerializedName("APP") 387 APP, 388 @SerializedName("PAYMENT_CODE") 389 PAYMENT_CODE 390 } 391 392 public static class CouponAvailableStoreInfo { 393 @SerializedName("description") 394 public String description; 395 396 @SerializedName("mini_program_appid") 397 public String miniProgramAppid; 398 399 @SerializedName("mini_program_path") 400 public String miniProgramPath; 401 } 402 403 public enum CouponCodeDisplayMode { 404 @SerializedName("INVISIBLE") 405 INVISIBLE, 406 @SerializedName("BARCODE") 407 BARCODE, 408 @SerializedName("QRCODE") 409 QRCODE 410 } 411 412 public static class EntranceMiniProgram { 413 @SerializedName("appid") 414 public String appid; 415 416 @SerializedName("path") 417 public String path; 418 419 @SerializedName("entrance_wording") 420 public String entranceWording; 421 422 @SerializedName("guidance_wording") 423 public String guidanceWording; 424 } 425 426 public static class EntranceOfficialAccount { 427 @SerializedName("appid") 428 public String appid; 429 } 430 431 public static class EntranceFinder { 432 @SerializedName("finder_id") 433 public String finderId; 434 435 @SerializedName("finder_video_id") 436 public String finderVideoId; 437 438 @SerializedName("finder_video_cover_image_url") 439 public String finderVideoCoverImageUrl; 440 } 441 442 public static class FixedWeekPeriod { 443 @SerializedName("day_list") 444 public List<WeekEnum> dayList; 445 446 @SerializedName("day_period_list") 447 public List<PeriodOfTheDay> dayPeriodList; 448 } 449 450 public static class TimePeriod { 451 @SerializedName("begin_time") 452 public String beginTime; 453 454 @SerializedName("end_time") 455 public String endTime; 456 } 457 458 public enum WeekEnum { 459 @SerializedName("MONDAY") 460 MONDAY, 461 @SerializedName("TUESDAY") 462 TUESDAY, 463 @SerializedName("WEDNESDAY") 464 WEDNESDAY, 465 @SerializedName("THURSDAY") 466 THURSDAY, 467 @SerializedName("FRIDAY") 468 FRIDAY, 469 @SerializedName("SATURDAY") 470 SATURDAY, 471 @SerializedName("SUNDAY") 472 SUNDAY 473 } 474 475 public static class PeriodOfTheDay { 476 @SerializedName("begin_time") 477 public Long beginTime; 478 479 @SerializedName("end_time") 480 public Long endTime; 481 } 482 483} 484
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_brand_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/brand/4015826866 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 10 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 15 config, err := wxpay_brand_utility.CreateBrandConfig( 16 "xxxxxxxx", // 品牌ID,是由微信支付系统生成并分配给每个品牌方的唯一标识符,品牌ID获取方式参考 https://pay.weixin.qq.com/doc/brand/4015415289 17 "1DDE55AD98Exxxxxxxxxx", // 品牌API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015407570 18 "/path/to/apiclient_key.pem", // 品牌API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015453439 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &ListStocksRequest{ 28 ProductCouponId: wxpay_brand_utility.String("200000001"), 29 State: STOCKSTATE_SENDING.Ptr(), 30 PageSize: wxpay_brand_utility.Int64(20), 31 PageToken: wxpay_brand_utility.String("MTIzMjUK"), 32 } 33 34 response, err := ListStocks(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 ListStocks(config *wxpay_brand_utility.BrandConfig, request *ListStocksRequest) (response *ListStocksResponse, err error) { 46 const ( 47 host = "https://api.mch.weixin.qq.com" 48 method = "GET" 49 path = "/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks" 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 query := reqUrl.Query() 58 if request.State != nil { 59 query.Add("state", fmt.Sprintf("%v", *request.State)) 60 } 61 if request.PageSize != nil { 62 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 63 } 64 if request.PageToken != nil { 65 query.Add("page_token", *request.PageToken) 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_brand_utility.BuildAuthorization(config.BrandId(), 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_brand_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_brand_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 := &ListStocksResponse{} 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_brand_utility.NewApiException( 108 httpResponse.StatusCode, 109 httpResponse.Header, 110 respBody, 111 ) 112 } 113} 114 115type ListStocksRequest struct { 116 ProductCouponId *string `json:"product_coupon_id,omitempty"` 117 PageSize *int64 `json:"page_size,omitempty"` 118 PageToken *string `json:"page_token,omitempty"` 119 State *StockState `json:"state,omitempty"` 120} 121 122func (o *ListStocksRequest) MarshalJSON() ([]byte, error) { 123 type Alias ListStocksRequest 124 a := &struct { 125 ProductCouponId *string `json:"product_coupon_id,omitempty"` 126 PageSize *int64 `json:"page_size,omitempty"` 127 PageToken *string `json:"page_token,omitempty"` 128 State *StockState `json:"state,omitempty"` 129 *Alias 130 }{ 131 // 序列化时移除非 Body 字段 132 ProductCouponId: nil, 133 PageSize: nil, 134 PageToken: nil, 135 State: nil, 136 Alias: (*Alias)(o), 137 } 138 return json.Marshal(a) 139} 140 141type ListStocksResponse struct { 142 TotalCount *int64 `json:"total_count,omitempty"` 143 StockList []StockEntity `json:"stock_list,omitempty"` 144 NextPageToken *string `json:"next_page_token,omitempty"` 145} 146 147type StockState string 148 149func (e StockState) Ptr() *StockState { 150 return &e 151} 152 153const ( 154 STOCKSTATE_AUDITING StockState = "AUDITING" 155 STOCKSTATE_SENDING StockState = "SENDING" 156 STOCKSTATE_PAUSED StockState = "PAUSED" 157 STOCKSTATE_STOPPED StockState = "STOPPED" 158 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 159) 160 161type StockEntity struct { 162 ProductCouponId *string `json:"product_coupon_id,omitempty"` 163 StockId *string `json:"stock_id,omitempty"` 164 Remark *string `json:"remark,omitempty"` 165 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 166 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 167 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 168 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 169 SequentialUsageRule *SequentialUsageRule `json:"sequential_usage_rule,omitempty"` 170 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 171 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 172 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 173 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 174 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 175 State *StockState `json:"state,omitempty"` 176 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 177 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 178 DeactivateReason *string `json:"deactivate_reason,omitempty"` 179} 180 181type CouponCodeMode string 182 183func (e CouponCodeMode) Ptr() *CouponCodeMode { 184 return &e 185} 186 187const ( 188 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 189 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 190 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 191) 192 193type CouponCodeCountInfo struct { 194 TotalCount *int64 `json:"total_count,omitempty"` 195 AvailableCount *int64 `json:"available_count,omitempty"` 196} 197 198type StockSendRule struct { 199 MaxCount *int64 `json:"max_count,omitempty"` 200 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 201 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 202} 203 204type SingleUsageRule struct { 205 CouponAvailablePeriod *SingleCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 206 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 207 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 208 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 209} 210 211type SequentialUsageRule struct { 212 CouponAvailablePeriod *SequentialCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 213 NormalCouponList []NormalCouponUsageRule `json:"normal_coupon_list,omitempty"` 214 DiscountCouponList []DiscountCouponUsageRule `json:"discount_coupon_list,omitempty"` 215 ExchangeCouponList []ExchangeCouponUsageRule `json:"exchange_coupon_list,omitempty"` 216 SpecialFirst *bool `json:"special_first,omitempty"` 217} 218 219type UsageRuleDisplayInfo struct { 220 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 221 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 222 MiniProgramPath *string `json:"mini_program_path,omitempty"` 223 AppPath *string `json:"app_path,omitempty"` 224 UsageDescription *string `json:"usage_description,omitempty"` 225 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 226} 227 228type CouponDisplayInfo struct { 229 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 230 BackgroundColor *string `json:"background_color,omitempty"` 231 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 232 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 233 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 234} 235 236type NotifyConfig struct { 237 NotifyAppid *string `json:"notify_appid,omitempty"` 238} 239 240type StockStoreScope string 241 242func (e StockStoreScope) Ptr() *StockStoreScope { 243 return &e 244} 245 246const ( 247 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 248 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 249 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 250) 251 252type StockSentCountInfo struct { 253 TotalCount *int64 `json:"total_count,omitempty"` 254 TodayCount *int64 `json:"today_count,omitempty"` 255} 256 257type SingleCouponAvailablePeriod struct { 258 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 259 AvailableEndTime *string `json:"available_end_time,omitempty"` 260 AvailableDays *int64 `json:"available_days,omitempty"` 261 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 262 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 263 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 264} 265 266type NormalCouponUsageRule struct { 267 Threshold *int64 `json:"threshold,omitempty"` 268 DiscountAmount *int64 `json:"discount_amount,omitempty"` 269} 270 271type DiscountCouponUsageRule struct { 272 Threshold *int64 `json:"threshold,omitempty"` 273 PercentOff *int64 `json:"percent_off,omitempty"` 274} 275 276type ExchangeCouponUsageRule struct { 277 Threshold *int64 `json:"threshold,omitempty"` 278 ExchangePrice *int64 `json:"exchange_price,omitempty"` 279} 280 281type SequentialCouponAvailablePeriod struct { 282 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 283 AvailableEndTime *string `json:"available_end_time,omitempty"` 284 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 285 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 286 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 287} 288 289type CouponUsageMethod string 290 291func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 292 return &e 293} 294 295const ( 296 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 297 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 298 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 299 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 300) 301 302type CouponAvailableStoreInfo struct { 303 Description *string `json:"description,omitempty"` 304 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 305 MiniProgramPath *string `json:"mini_program_path,omitempty"` 306} 307 308type CouponCodeDisplayMode string 309 310func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 311 return &e 312} 313 314const ( 315 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 316 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 317 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 318) 319 320type EntranceMiniProgram struct { 321 Appid *string `json:"appid,omitempty"` 322 Path *string `json:"path,omitempty"` 323 EntranceWording *string `json:"entrance_wording,omitempty"` 324 GuidanceWording *string `json:"guidance_wording,omitempty"` 325} 326 327type EntranceOfficialAccount struct { 328 Appid *string `json:"appid,omitempty"` 329} 330 331type EntranceFinder struct { 332 FinderId *string `json:"finder_id,omitempty"` 333 FinderVideoId *string `json:"finder_video_id,omitempty"` 334 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 335} 336 337type FixedWeekPeriod struct { 338 DayList []WeekEnum `json:"day_list,omitempty"` 339 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 340} 341 342type TimePeriod struct { 343 BeginTime *string `json:"begin_time,omitempty"` 344 EndTime *string `json:"end_time,omitempty"` 345} 346 347type WeekEnum string 348 349func (e WeekEnum) Ptr() *WeekEnum { 350 return &e 351} 352 353const ( 354 WEEKENUM_MONDAY WeekEnum = "MONDAY" 355 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 356 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 357 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 358 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 359 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 360 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 361) 362 363type PeriodOfTheDay struct { 364 BeginTime *int64 `json:"begin_time,omitempty"` 365 EndTime *int64 `json:"end_time,omitempty"` 366} 367
应答参数
200 OK
total_count 必填 integer
【总个数】 符合查询条件的批次总数,当且仅当 page_token 为空时提供
stock_list 选填 array[object]
【批次列表】 符合查询条件的批次列表
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
product_coupon_id 必填 string(40) 【商品券ID】 商品券的唯一标识,由微信支付生成 stock_id 必填 string(40) 【批次ID】 商品券批次的唯一标识,由微信支付生成 remark 选填 string(20) 【备注】 仅配置品牌可见,用于自定义信息 coupon_code_mode 必填 string 【券Code分配模式】 决定发券时用户商品券Code如何产生 可选取值
coupon_code_count_info 选填 object 【品牌方预上传的券Code数量信息】 当且仅当
stock_send_rule 必填 object 【发放规则】 发放规则
single_usage_rule 选填 object 【单券使用规则】 当且仅当
sequential_usage_rule 选填 object 【多次优惠使用规则】 当且仅当
usage_rule_display_info 必填 object 【券使用规则展示信息】 券使用规则展示信息
coupon_display_info 必填 object 【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口
notify_config 必填 object 【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
store_scope 必填 string 【可用门店范围】 控制该批次可以在品牌下哪些门店使用 可选取值
sent_count_info 必填 object 【已发放次数】 本批次已发放次数
state 必填 string 【批次状态】 商品券批次状态 可选取值
deactivate_request_no 选填 string 【失效请求单号】 当且仅当 deactivate_time 选填 string 【失效时间】 当且仅当 deactivate_reason 选填 string 【失效原因】 当且仅当 |
next_page_token 选填 string(100)
【下一页Token】 分页查询时,如果还有更多数据,会返回下一页的Token,请在下一次查询时设置在 page_token 中;如果已无更多数据,则不返回此字段。
应答示例
200 OK
1{ 2 "total_count" : 100, 3 "stock_list" : [ 4 { 5 "product_coupon_id" : "200000001", 6 "stock_id" : "123456789", 7 "remark" : "满减券", 8 "coupon_code_mode" : "UPLOAD", 9 "coupon_code_count_info" : { 10 "total_count" : 10000, 11 "available_count" : 999 12 }, 13 "stock_send_rule" : { 14 "max_count" : 10000000, 15 "max_count_per_day" : 10000, 16 "max_count_per_user" : 1 17 }, 18 "single_usage_rule" : { 19 "coupon_available_period" : { 20 "available_begin_time" : "2025-01-01T00:00:00+08:00", 21 "available_end_time" : "2025-10-01T00:00:00+08:00", 22 "available_days" : 10, 23 "wait_days_after_receive" : 1, 24 "weekly_available_period" : { 25 "day_list" : [ 26 "MONDAY" 27 ], 28 "day_period_list" : [ 29 { 30 "begin_time" : 60, 31 "end_time" : 86399 32 } 33 ] 34 }, 35 "irregular_available_period_list" : [ 36 { 37 "begin_time" : "2025-01-01T00:00:00+08:00", 38 "end_time" : "2025-10-01T00:00:00+08:00" 39 } 40 ] 41 }, 42 "normal_coupon" : { 43 "threshold" : 10000, 44 "discount_amount" : 100 45 }, 46 "discount_coupon" : { 47 "threshold" : 10000, 48 "percent_off" : 30 49 }, 50 "exchange_coupon" : { 51 "threshold" : 10000, 52 "exchange_price" : 100 53 } 54 }, 55 "sequential_usage_rule" : { 56 "coupon_available_period" : { 57 "available_begin_time" : "2025-01-01T00:00:00+08:00", 58 "available_end_time" : "2025-10-01T00:00:00+08:00", 59 "wait_days_after_receive" : 1, 60 "weekly_available_period" : { 61 "day_list" : [ 62 "MONDAY" 63 ], 64 "day_period_list" : [ 65 { 66 "begin_time" : 60, 67 "end_time" : 86399 68 } 69 ] 70 }, 71 "irregular_available_period_list" : [ 72 { 73 "begin_time" : "2025-01-01T00:00:00+08:00", 74 "end_time" : "2025-10-01T00:00:00+08:00" 75 } 76 ] 77 }, 78 "normal_coupon_list" : [ 79 { 80 "threshold" : 10000, 81 "discount_amount" : 100 82 } 83 ], 84 "discount_coupon_list" : [ 85 { 86 "threshold" : 10000, 87 "percent_off" : 30 88 } 89 ], 90 "exchange_coupon_list" : [ 91 { 92 "threshold" : 10000, 93 "exchange_price" : 100 94 } 95 ], 96 "special_first" : false 97 }, 98 "usage_rule_display_info" : { 99 "coupon_usage_method_list" : [ 100 "MINI_PROGRAM" 101 ], 102 "mini_program_appid" : "wx1234567890", 103 "mini_program_path" : "/pages/index/product", 104 "app_path" : "https://www.example.com/jump-to-app", 105 "usage_description" : "全场可用", 106 "coupon_available_store_info" : { 107 "description" : "可在上海市区的所有门店使用,详细列表参考小程序内信息为准", 108 "mini_program_appid" : "wx1234567890", 109 "mini_program_path" : "/pages/index/store-list" 110 } 111 }, 112 "coupon_display_info" : { 113 "code_display_mode" : "QRCODE", 114 "background_color" : "Color010", 115 "entrance_mini_program" : { 116 "appid" : "wx1234567890", 117 "path" : "/pages/index/product", 118 "entrance_wording" : "欢迎选购", 119 "guidance_wording" : "获取更多优惠" 120 }, 121 "entrance_official_account" : { 122 "appid" : "wx1234567890" 123 }, 124 "entrance_finder" : { 125 "finder_id" : "gh_12345678", 126 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 127 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 128 } 129 }, 130 "notify_config" : { 131 "notify_appid" : "wx4fd12345678" 132 }, 133 "store_scope" : "SPECIFIC", 134 "sent_count_info" : { 135 "total_count" : 100, 136 "today_count" : 10 137 }, 138 "state" : "SENDING", 139 "deactivate_request_no" : "1002600620019090123143254436", 140 "deactivate_time" : "2025-01-01T00:00+08:00", 141 "deactivate_reason" : "批次信息有误,重新创建" 142 } 143 ], 144 "next_page_token" : "MTIzNDUK" 145} 146
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 单券使用模式的商品券批次,应该在「单券使用规则」中包含对应类型的优惠规则。对于文档中标记不应填写的优惠规则应删除。 | 请在「单券使用规则」中包含对应类型的优惠规则,并删除文档中标记不应填写的优惠规则。 |
400 | INVALID_REQUEST | 多次优惠使用模式的商品券批次,应该在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 | 在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 |
400 | INVALID_REQUEST | 单品满减券或单品折扣券不应在商品券中设置「满减券使用规则」或「折扣券使用规则」,而是应该在商品券批次中设置 | 请删除商品券中的「满减券使用规则」或「折扣券使用规则」,并在商品券批次中设置对应的优惠规则 |
403 | NO_AUTH | 品牌没有此接口权限 | 品牌没有此接口权限 |
400 | PARAM_ERROR | page_token 不合法,请确认 page_token 来自于上一个列表查询请求的 next_page_token | 请确认 page_token 来自于上一个列表查询请求的 next_page_token,如果是初次查询则不要填写 page_token 参数 |
400 | INVALID_REQUEST | 商品券支持APP核销时,必须提供「APP跳转路径」 | 请提供「APP跳转路径」参数 |
400 | PARAM_ERROR | 分页大小超出限制,请根据接口文档调整到允许的范围 | 请调整分页大小到规定范围 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序AppID」 | 请提供「小程序AppID」 |
400 | INVALID_REQUEST | 单品券必须提供商品原价,请补充 | 请补充商品原价 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序跳转路径」 | 请提供提供「小程序跳转路径」 |
400 | INVALID_REQUEST | 单品券必须提供商品券套餐组合信息,请补充 | 请提供商品券套餐组合信息 |
400 | PARAM_ERROR | 时间字符串格式错误,请使用 RFC3339 标准格式 | 请使用 RFC3339 标准格式 |
400 | INVALID_REQUEST | 单券模式下,全场折扣券应在商品券中提供折扣券使用规则信息 | 请在商品券中提供「折扣券使用规则信息」 |
400 | INVALID_REQUEST | 单券模式下,全场满减券应在商品券中提供满减券使用规则信息 | 请在商品券中提供「满减券使用规则信息」 |
400 | INVALID_REQUEST | 每周固定可用时间(weekly_available_period)中提供当天可用时间段时(day_period_list),每周可用星期数(day_list)必填 | 请补充 每周可用星期数(day_list) |
400 | INVALID_REQUEST | 单券模式下,全场券需要提供「单券模式信息(single_usage_info)」 | 请提供单券模式信息(single_usage_info) |
400 | INVALID_REQUEST | 多次优惠模式下必须提供「多次优惠模式信息(sequential_usage_info)」 | 请填写 多次优惠模式信息(sequential_usage_info) |
400 | INVALID_REQUEST | 传入的OpenID不合法 | 请使用参数 AppID 对应的的OpenID |


