查询商品券批次列表
更新时间:2025.08.04品牌方可以通过该接口分页查询某个商品券的批次列表。
前置条件:已创建商品券
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/marketing/partner/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
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,首次调用不填
brand_id 必填 string
【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/product-coupon/product-coupons/200000001/stocks?state=SENDING&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 ListStocks { 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"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ListStocks client = new ListStocks( 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 ListStocksRequest request = new ListStocksRequest(); 41 request.productCouponId = "200000001"; 42 request.state = StockState.SENDING; 43 request.pageSize = 20L; 44 request.pageToken = "MTIzMjUK"; 45 request.brandId = "120344"; 46 try { 47 ListStocksResponse response = client.run(request); 48 // TODO: 请求成功,继续业务逻辑 49 System.out.println(response); 50 } catch (WXPayUtility.ApiException e) { 51 // TODO: 请求失败,根据状态码执行不同的逻辑 52 e.printStackTrace(); 53 } 54 } 55 56 public ListStocksResponse run(ListStocksRequest request) { 57 String uri = PATH; 58 uri = uri.replace("{product_coupon_id}", WXPayUtility.urlEncode(request.productCouponId)); 59 Map<String, Object> args = new HashMap<>(); 60 args.put("state", request.state); 61 args.put("page_size", request.pageSize); 62 args.put("page_token", request.pageToken); 63 args.put("brand_id", request.brandId); 64 String queryString = WXPayUtility.urlEncode(args); 65 if (!queryString.isEmpty()) { 66 uri = uri + "?" + queryString; 67 } 68 69 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 70 reqBuilder.addHeader("Accept", "application/json"); 71 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 72 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 73 reqBuilder.method(METHOD, null); 74 Request httpRequest = reqBuilder.build(); 75 76 // 发送HTTP请求 77 OkHttpClient client = new OkHttpClient.Builder().build(); 78 try (Response httpResponse = client.newCall(httpRequest).execute()) { 79 String respBody = WXPayUtility.extractBody(httpResponse); 80 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 81 // 2XX 成功,验证应答签名 82 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 83 httpResponse.headers(), respBody); 84 85 // 从HTTP应答报文构建返回数据 86 return WXPayUtility.fromJson(respBody, ListStocksResponse.class); 87 } else { 88 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 89 } 90 } catch (IOException e) { 91 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 92 } 93 } 94 95 private final String mchid; 96 private final String certificateSerialNo; 97 private final PrivateKey privateKey; 98 private final String wechatPayPublicKeyId; 99 private final PublicKey wechatPayPublicKey; 100 101 public ListStocks(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 102 this.mchid = mchid; 103 this.certificateSerialNo = certificateSerialNo; 104 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 105 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 106 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 107 } 108 109 public static class ListStocksRequest { 110 @SerializedName("product_coupon_id") 111 @Expose(serialize = false) 112 public String productCouponId; 113 114 @SerializedName("page_size") 115 @Expose(serialize = false) 116 public Long pageSize; 117 118 @SerializedName("page_token") 119 @Expose(serialize = false) 120 public String pageToken; 121 122 @SerializedName("brand_id") 123 @Expose(serialize = false) 124 public String brandId; 125 126 @SerializedName("state") 127 @Expose(serialize = false) 128 public StockState state; 129 } 130 131 public static class ListStocksResponse { 132 @SerializedName("total_count") 133 public Long totalCount; 134 135 @SerializedName("stock_list") 136 public List<StockEntity> stockList; 137 138 @SerializedName("next_page_token") 139 public String nextPageToken; 140 } 141 142 public enum StockState { 143 @SerializedName("AUDITING") 144 AUDITING, 145 @SerializedName("SENDING") 146 SENDING, 147 @SerializedName("PAUSED") 148 PAUSED, 149 @SerializedName("STOPPED") 150 STOPPED, 151 @SerializedName("DEACTIVATED") 152 DEACTIVATED 153 } 154 155 public static class StockEntity { 156 @SerializedName("product_coupon_id") 157 public String productCouponId; 158 159 @SerializedName("stock_id") 160 public String stockId; 161 162 @SerializedName("remark") 163 public String remark; 164 165 @SerializedName("coupon_code_mode") 166 public CouponCodeMode couponCodeMode; 167 168 @SerializedName("coupon_code_count_info") 169 public CouponCodeCountInfo couponCodeCountInfo; 170 171 @SerializedName("stock_send_rule") 172 public StockSendRule stockSendRule; 173 174 @SerializedName("single_usage_rule") 175 public SingleUsageRule singleUsageRule; 176 177 @SerializedName("sequential_usage_rule") 178 public SequentialUsageRule sequentialUsageRule; 179 180 @SerializedName("usage_rule_display_info") 181 public UsageRuleDisplayInfo usageRuleDisplayInfo; 182 183 @SerializedName("coupon_display_info") 184 public CouponDisplayInfo couponDisplayInfo; 185 186 @SerializedName("notify_config") 187 public NotifyConfig notifyConfig; 188 189 @SerializedName("store_scope") 190 public StockStoreScope storeScope; 191 192 @SerializedName("sent_count_info") 193 public StockSentCountInfo sentCountInfo; 194 195 @SerializedName("state") 196 public StockState state; 197 198 @SerializedName("deactivate_request_no") 199 public String deactivateRequestNo; 200 201 @SerializedName("deactivate_time") 202 public String deactivateTime; 203 204 @SerializedName("deactivate_reason") 205 public String deactivateReason; 206 207 @SerializedName("brand_id") 208 public String brandId; 209 } 210 211 public enum CouponCodeMode { 212 @SerializedName("WECHATPAY") 213 WECHATPAY, 214 @SerializedName("UPLOAD") 215 UPLOAD, 216 @SerializedName("API_ASSIGN") 217 API_ASSIGN 218 } 219 220 public static class CouponCodeCountInfo { 221 @SerializedName("total_count") 222 public Long totalCount; 223 224 @SerializedName("available_count") 225 public Long availableCount; 226 } 227 228 public static class StockSendRule { 229 @SerializedName("max_count") 230 public Long maxCount; 231 232 @SerializedName("max_count_per_day") 233 public Long maxCountPerDay; 234 235 @SerializedName("max_count_per_user") 236 public Long maxCountPerUser; 237 } 238 239 public static class SingleUsageRule { 240 @SerializedName("coupon_available_period") 241 public SingleCouponAvailablePeriod couponAvailablePeriod; 242 243 @SerializedName("normal_coupon") 244 public NormalCouponUsageRule normalCoupon; 245 246 @SerializedName("discount_coupon") 247 public DiscountCouponUsageRule discountCoupon; 248 249 @SerializedName("exchange_coupon") 250 public ExchangeCouponUsageRule exchangeCoupon; 251 } 252 253 public static class SequentialUsageRule { 254 @SerializedName("coupon_available_period") 255 public SequentialCouponAvailablePeriod couponAvailablePeriod; 256 257 @SerializedName("normal_coupon_list") 258 public List<NormalCouponUsageRule> normalCouponList; 259 260 @SerializedName("discount_coupon_list") 261 public List<DiscountCouponUsageRule> discountCouponList; 262 263 @SerializedName("exchange_coupon_list") 264 public List<ExchangeCouponUsageRule> exchangeCouponList; 265 266 @SerializedName("special_first") 267 public Boolean specialFirst; 268 } 269 270 public static class UsageRuleDisplayInfo { 271 @SerializedName("coupon_usage_method_list") 272 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 273 274 @SerializedName("mini_program_appid") 275 public String miniProgramAppid; 276 277 @SerializedName("mini_program_path") 278 public String miniProgramPath; 279 280 @SerializedName("app_path") 281 public String appPath; 282 283 @SerializedName("usage_description") 284 public String usageDescription; 285 286 @SerializedName("coupon_available_store_info") 287 public CouponAvailableStoreInfo couponAvailableStoreInfo; 288 } 289 290 public static class CouponDisplayInfo { 291 @SerializedName("code_display_mode") 292 public CouponCodeDisplayMode codeDisplayMode; 293 294 @SerializedName("background_color") 295 public String backgroundColor; 296 297 @SerializedName("entrance_mini_program") 298 public EntranceMiniProgram entranceMiniProgram; 299 300 @SerializedName("entrance_official_account") 301 public EntranceOfficialAccount entranceOfficialAccount; 302 303 @SerializedName("entrance_finder") 304 public EntranceFinder entranceFinder; 305 } 306 307 public static class NotifyConfig { 308 @SerializedName("notify_appid") 309 public String notifyAppid; 310 } 311 312 public enum StockStoreScope { 313 @SerializedName("NONE") 314 NONE, 315 @SerializedName("ALL") 316 ALL, 317 @SerializedName("SPECIFIC") 318 SPECIFIC 319 } 320 321 public static class StockSentCountInfo { 322 @SerializedName("total_count") 323 public Long totalCount; 324 325 @SerializedName("today_count") 326 public Long todayCount; 327 } 328 329 public static class SingleCouponAvailablePeriod { 330 @SerializedName("available_begin_time") 331 public String availableBeginTime; 332 333 @SerializedName("available_end_time") 334 public String availableEndTime; 335 336 @SerializedName("available_days") 337 public Long availableDays; 338 339 @SerializedName("wait_days_after_receive") 340 public Long waitDaysAfterReceive; 341 342 @SerializedName("weekly_available_period") 343 public FixedWeekPeriod weeklyAvailablePeriod; 344 345 @SerializedName("irregular_available_period_list") 346 public List<TimePeriod> irregularAvailablePeriodList; 347 } 348 349 public static class NormalCouponUsageRule { 350 @SerializedName("threshold") 351 public Long threshold; 352 353 @SerializedName("discount_amount") 354 public Long discountAmount; 355 } 356 357 public static class DiscountCouponUsageRule { 358 @SerializedName("threshold") 359 public Long threshold; 360 361 @SerializedName("percent_off") 362 public Long percentOff; 363 } 364 365 public static class ExchangeCouponUsageRule { 366 @SerializedName("threshold") 367 public Long threshold; 368 369 @SerializedName("exchange_price") 370 public Long exchangePrice; 371 } 372 373 public static class SequentialCouponAvailablePeriod { 374 @SerializedName("available_begin_time") 375 public String availableBeginTime; 376 377 @SerializedName("available_end_time") 378 public String availableEndTime; 379 380 @SerializedName("wait_days_after_receive") 381 public Long waitDaysAfterReceive; 382 383 @SerializedName("weekly_available_period") 384 public FixedWeekPeriod weeklyAvailablePeriod; 385 386 @SerializedName("irregular_available_period_list") 387 public List<TimePeriod> irregularAvailablePeriodList; 388 } 389 390 public enum CouponUsageMethod { 391 @SerializedName("OFFLINE") 392 OFFLINE, 393 @SerializedName("MINI_PROGRAM") 394 MINI_PROGRAM, 395 @SerializedName("APP") 396 APP, 397 @SerializedName("PAYMENT_CODE") 398 PAYMENT_CODE 399 } 400 401 public static class CouponAvailableStoreInfo { 402 @SerializedName("description") 403 public String description; 404 405 @SerializedName("mini_program_appid") 406 public String miniProgramAppid; 407 408 @SerializedName("mini_program_path") 409 public String miniProgramPath; 410 } 411 412 public enum CouponCodeDisplayMode { 413 @SerializedName("INVISIBLE") 414 INVISIBLE, 415 @SerializedName("BARCODE") 416 BARCODE, 417 @SerializedName("QRCODE") 418 QRCODE 419 } 420 421 public static class EntranceMiniProgram { 422 @SerializedName("appid") 423 public String appid; 424 425 @SerializedName("path") 426 public String path; 427 428 @SerializedName("entrance_wording") 429 public String entranceWording; 430 431 @SerializedName("guidance_wording") 432 public String guidanceWording; 433 } 434 435 public static class EntranceOfficialAccount { 436 @SerializedName("appid") 437 public String appid; 438 } 439 440 public static class EntranceFinder { 441 @SerializedName("finder_id") 442 public String finderId; 443 444 @SerializedName("finder_video_id") 445 public String finderVideoId; 446 447 @SerializedName("finder_video_cover_image_url") 448 public String finderVideoCoverImageUrl; 449 } 450 451 public static class FixedWeekPeriod { 452 @SerializedName("day_list") 453 public List<WeekEnum> dayList; 454 455 @SerializedName("day_period_list") 456 public List<PeriodOfTheDay> dayPeriodList; 457 } 458 459 public static class TimePeriod { 460 @SerializedName("begin_time") 461 public String beginTime; 462 463 @SerializedName("end_time") 464 public String endTime; 465 } 466 467 public enum WeekEnum { 468 @SerializedName("MONDAY") 469 MONDAY, 470 @SerializedName("TUESDAY") 471 TUESDAY, 472 @SerializedName("WEDNESDAY") 473 WEDNESDAY, 474 @SerializedName("THURSDAY") 475 THURSDAY, 476 @SerializedName("FRIDAY") 477 FRIDAY, 478 @SerializedName("SATURDAY") 479 SATURDAY, 480 @SerializedName("SUNDAY") 481 SUNDAY 482 } 483 484 public static class PeriodOfTheDay { 485 @SerializedName("begin_time") 486 public Long beginTime; 487 488 @SerializedName("end_time") 489 public Long endTime; 490 } 491 492} 493
需配合微信支付工具库 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 "time" 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 := &ListStocksRequest{ 28 ProductCouponId: wxpay_utility.String("200000001"), 29 State: STOCKSTATE_SENDING.Ptr(), 30 PageSize: wxpay_utility.Int64(20), 31 PageToken: wxpay_utility.String("MTIzMjUK"), 32 BrandId: wxpay_utility.String("120344"), 33 } 34 35 response, err := ListStocks(config, request) 36 if err != nil { 37 fmt.Printf("请求失败: %+v\n", err) 38 // TODO: 请求失败,根据状态码执行不同的处理 39 return 40 } 41 42 // TODO: 请求成功,继续业务逻辑 43 fmt.Printf("请求成功: %+v\n", response) 44} 45 46func ListStocks(config *wxpay_utility.MchConfig, request *ListStocksRequest) (response *ListStocksResponse, err error) { 47 const ( 48 host = "https://api.mch.weixin.qq.com" 49 method = "GET" 50 path = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks" 51 ) 52 53 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 54 if err != nil { 55 return nil, err 56 } 57 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 58 query := reqUrl.Query() 59 if request.State != nil { 60 query.Add("state", fmt.Sprintf("%v", *request.State)) 61 } 62 if request.PageSize != nil { 63 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 64 } 65 if request.PageToken != nil { 66 query.Add("page_token", *request.PageToken) 67 } 68 if request.BrandId != nil { 69 query.Add("brand_id", *request.BrandId) 70 } 71 reqUrl.RawQuery = query.Encode() 72 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 73 if err != nil { 74 return nil, err 75 } 76 httpRequest.Header.Set("Accept", "application/json") 77 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 78 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 79 if err != nil { 80 return nil, err 81 } 82 httpRequest.Header.Set("Authorization", authorization) 83 84 client := &http.Client{} 85 httpResponse, err := client.Do(httpRequest) 86 if err != nil { 87 return nil, err 88 } 89 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 90 if err != nil { 91 return nil, err 92 } 93 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 94 // 2XX 成功,验证应答签名 95 err = wxpay_utility.ValidateResponse( 96 config.WechatPayPublicKeyId(), 97 config.WechatPayPublicKey(), 98 &httpResponse.Header, 99 respBody, 100 ) 101 if err != nil { 102 return nil, err 103 } 104 response := &ListStocksResponse{} 105 if err := json.Unmarshal(respBody, response); err != nil { 106 return nil, err 107 } 108 109 return response, nil 110 } else { 111 return nil, wxpay_utility.NewApiException( 112 httpResponse.StatusCode, 113 httpResponse.Header, 114 respBody, 115 ) 116 } 117} 118 119type ListStocksRequest struct { 120 ProductCouponId *string `json:"product_coupon_id,omitempty"` 121 PageSize *int64 `json:"page_size,omitempty"` 122 PageToken *string `json:"page_token,omitempty"` 123 BrandId *string `json:"brand_id,omitempty"` 124 State *StockState `json:"state,omitempty"` 125} 126 127func (o *ListStocksRequest) MarshalJSON() ([]byte, error) { 128 type Alias ListStocksRequest 129 a := &struct { 130 ProductCouponId *string `json:"product_coupon_id,omitempty"` 131 PageSize *int64 `json:"page_size,omitempty"` 132 PageToken *string `json:"page_token,omitempty"` 133 BrandId *string `json:"brand_id,omitempty"` 134 State *StockState `json:"state,omitempty"` 135 *Alias 136 }{ 137 // 序列化时移除非 Body 字段 138 ProductCouponId: nil, 139 PageSize: nil, 140 PageToken: nil, 141 BrandId: nil, 142 State: nil, 143 Alias: (*Alias)(o), 144 } 145 return json.Marshal(a) 146} 147 148type ListStocksResponse struct { 149 TotalCount *int64 `json:"total_count,omitempty"` 150 StockList []StockEntity `json:"stock_list,omitempty"` 151 NextPageToken *string `json:"next_page_token,omitempty"` 152} 153 154type StockState string 155 156func (e StockState) Ptr() *StockState { 157 return &e 158} 159 160const ( 161 STOCKSTATE_AUDITING StockState = "AUDITING" 162 STOCKSTATE_SENDING StockState = "SENDING" 163 STOCKSTATE_PAUSED StockState = "PAUSED" 164 STOCKSTATE_STOPPED StockState = "STOPPED" 165 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 166) 167 168type StockEntity struct { 169 ProductCouponId *string `json:"product_coupon_id,omitempty"` 170 StockId *string `json:"stock_id,omitempty"` 171 Remark *string `json:"remark,omitempty"` 172 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 173 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 174 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 175 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 176 SequentialUsageRule *SequentialUsageRule `json:"sequential_usage_rule,omitempty"` 177 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 178 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 179 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 180 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 181 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 182 State *StockState `json:"state,omitempty"` 183 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 184 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 185 DeactivateReason *string `json:"deactivate_reason,omitempty"` 186 BrandId *string `json:"brand_id,omitempty"` 187} 188 189type CouponCodeMode string 190 191func (e CouponCodeMode) Ptr() *CouponCodeMode { 192 return &e 193} 194 195const ( 196 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 197 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 198 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 199) 200 201type CouponCodeCountInfo struct { 202 TotalCount *int64 `json:"total_count,omitempty"` 203 AvailableCount *int64 `json:"available_count,omitempty"` 204} 205 206type StockSendRule struct { 207 MaxCount *int64 `json:"max_count,omitempty"` 208 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 209 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 210} 211 212type SingleUsageRule struct { 213 CouponAvailablePeriod *SingleCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 214 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 215 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 216 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 217} 218 219type SequentialUsageRule struct { 220 CouponAvailablePeriod *SequentialCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 221 NormalCouponList []NormalCouponUsageRule `json:"normal_coupon_list,omitempty"` 222 DiscountCouponList []DiscountCouponUsageRule `json:"discount_coupon_list,omitempty"` 223 ExchangeCouponList []ExchangeCouponUsageRule `json:"exchange_coupon_list,omitempty"` 224 SpecialFirst *bool `json:"special_first,omitempty"` 225} 226 227type UsageRuleDisplayInfo struct { 228 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 229 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 230 MiniProgramPath *string `json:"mini_program_path,omitempty"` 231 AppPath *string `json:"app_path,omitempty"` 232 UsageDescription *string `json:"usage_description,omitempty"` 233 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 234} 235 236type CouponDisplayInfo struct { 237 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 238 BackgroundColor *string `json:"background_color,omitempty"` 239 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 240 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 241 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 242} 243 244type NotifyConfig struct { 245 NotifyAppid *string `json:"notify_appid,omitempty"` 246} 247 248type StockStoreScope string 249 250func (e StockStoreScope) Ptr() *StockStoreScope { 251 return &e 252} 253 254const ( 255 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 256 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 257 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 258) 259 260type StockSentCountInfo struct { 261 TotalCount *int64 `json:"total_count,omitempty"` 262 TodayCount *int64 `json:"today_count,omitempty"` 263} 264 265type SingleCouponAvailablePeriod struct { 266 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 267 AvailableEndTime *string `json:"available_end_time,omitempty"` 268 AvailableDays *int64 `json:"available_days,omitempty"` 269 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 270 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 271 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 272} 273 274type NormalCouponUsageRule struct { 275 Threshold *int64 `json:"threshold,omitempty"` 276 DiscountAmount *int64 `json:"discount_amount,omitempty"` 277} 278 279type DiscountCouponUsageRule struct { 280 Threshold *int64 `json:"threshold,omitempty"` 281 PercentOff *int64 `json:"percent_off,omitempty"` 282} 283 284type ExchangeCouponUsageRule struct { 285 Threshold *int64 `json:"threshold,omitempty"` 286 ExchangePrice *int64 `json:"exchange_price,omitempty"` 287} 288 289type SequentialCouponAvailablePeriod struct { 290 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 291 AvailableEndTime *string `json:"available_end_time,omitempty"` 292 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 293 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 294 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 295} 296 297type CouponUsageMethod string 298 299func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 300 return &e 301} 302 303const ( 304 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 305 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 306 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 307 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 308) 309 310type CouponAvailableStoreInfo struct { 311 Description *string `json:"description,omitempty"` 312 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 313 MiniProgramPath *string `json:"mini_program_path,omitempty"` 314} 315 316type CouponCodeDisplayMode string 317 318func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 319 return &e 320} 321 322const ( 323 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 324 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 325 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 326) 327 328type EntranceMiniProgram struct { 329 Appid *string `json:"appid,omitempty"` 330 Path *string `json:"path,omitempty"` 331 EntranceWording *string `json:"entrance_wording,omitempty"` 332 GuidanceWording *string `json:"guidance_wording,omitempty"` 333} 334 335type EntranceOfficialAccount struct { 336 Appid *string `json:"appid,omitempty"` 337} 338 339type EntranceFinder struct { 340 FinderId *string `json:"finder_id,omitempty"` 341 FinderVideoId *string `json:"finder_video_id,omitempty"` 342 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 343} 344 345type FixedWeekPeriod struct { 346 DayList []WeekEnum `json:"day_list,omitempty"` 347 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 348} 349 350type TimePeriod struct { 351 BeginTime *string `json:"begin_time,omitempty"` 352 EndTime *string `json:"end_time,omitempty"` 353} 354 355type WeekEnum string 356 357func (e WeekEnum) Ptr() *WeekEnum { 358 return &e 359} 360 361const ( 362 WEEKENUM_MONDAY WeekEnum = "MONDAY" 363 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 364 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 365 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 366 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 367 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 368 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 369) 370 371type PeriodOfTheDay struct { 372 BeginTime *int64 `json:"begin_time,omitempty"` 373 EndTime *int64 `json:"end_time,omitempty"` 374} 375
应答参数
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 【失效原因】 当且仅当 brand_id 必填 string 【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系 |
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 "brand_id" : "120344" 143 } 144 ], 145 "next_page_token" : "MTIzNDUK" 146} 147
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
403 | NO_AUTH | 缺少业务相关权限 | 请确认已开通商品券权限 |
404 | NOT_FOUND | 未找到 product_coupon_id 对应的商品券 | 请确认 product_coupon_id 存在且属于当前品牌 |
429 | RATELIMIT_EXCEEDED | 请求超过接口频率限制 | 请稍后使用原参数重试 |

