指定券状态查询用户商品券列表
更新时间:2025.11.06品牌方可以通过本接口查询已经发放给用户的特定状态的商品券
前置条件:已经给用户发券成功
频率限制:500/s
接口说明
支持商户:【品牌商户】
请求方式:【GET】/brand/marketing/product-coupon/users/{openid}/coupons
请求域名:【主域名】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 路径参数
openid 必填 string
【用户OpenID】 OpenID信息,用户在AppID下的唯一标识,获取方式参考OpenID
query 查询参数
product_coupon_id 选填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成。查询指定商品券下的用户商品券列表,不传入时查询范围扩大至品牌下的所有商品券
stock_id 选填 string
【批次ID】 商品券批次的唯一标识,商品券批次创建时由微信支付生成(可使用【创建商品券API】或【添加商品券批次API】创建)。查询指定商品券批次下的用户商品券列表。
appid 必填 string
【公众账号ID】 公众账号ID也称AppID,是(微信开放平台、微信公众平台)为开发者提供的一个唯一标识,用于识别开发者的应用程序(APP、小程序、公众号)。 开发者需要先在微信开放平台或微信公众平台中申请ID,然后在品牌经营平台中绑定,详见品牌经营平台指引。
coupon_state 选填 string
【用户商品券状态】 查询指定状态的用户商品券
可选取值
CONFIRMING: 待确认,用户商品券发放需要品牌方调用【确认发放用户商品券API(单券)】或【确认发放用户商品券API(多次优惠)】后才能生效PENDING: 已发放待生效,用户商品券已发放成功但尚未到达可用开始时间EFFECTIVE: 已生效,用户商品券已成功发放且到达可用开始时间USED: 已核销,用户商品券已核销EXPIRED: 已过期,用户商品券已超过有效期,不再可用DELETED: 已删除,用户主动删除该券DEACTIVATED: 已失效,品牌方主动调用【失效用户商品券API】或【失效用户商品券组API】使用户商品券失效
user_coupon_bundle_id 选填 string
【用户券组ID】 用户券组的唯一标识,【向用户发放商品券批次组】时由微信支付生成,用于查询特定用户券组内的券
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/users/oh-394z-6CGkNoJrsDLTTUKiAnp4/coupons?product_coupon_id=1000000013&stock_id=1000000013001&appid=wx233544546545989&page_size=10 \ 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 ListUserProductCoupons { 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/users/{openid}/coupons"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 ListUserProductCoupons client = new ListUserProductCoupons( 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 ListUserProductCouponsRequest request = new ListUserProductCouponsRequest(); 41 request.productCouponId = "1000000013"; 42 request.stockId = "1000000013001"; 43 request.appid = "wx233544546545989"; 44 request.openid = "oh-394z-6CGkNoJrsDLTTUKiAnp4"; 45 request.pageSize = 10L; 46 try { 47 ListUserProductCouponsResponse response = client.run(request); 48 // TODO: 请求成功,继续业务逻辑 49 System.out.println(response); 50 } catch (WXPayBrandUtility.ApiException e) { 51 // TODO: 请求失败,根据状态码执行不同的逻辑 52 e.printStackTrace(); 53 } 54 } 55 56 public ListUserProductCouponsResponse run(ListUserProductCouponsRequest request) { 57 String uri = PATH; 58 uri = uri.replace("{openid}", WXPayBrandUtility.urlEncode(request.openid)); 59 Map<String, Object> args = new HashMap<>(); 60 args.put("product_coupon_id", request.productCouponId); 61 args.put("stock_id", request.stockId); 62 args.put("appid", request.appid); 63 args.put("coupon_state", request.couponState); 64 args.put("user_coupon_bundle_id", request.userCouponBundleId); 65 args.put("page_size", request.pageSize); 66 args.put("page_token", request.pageToken); 67 String queryString = WXPayBrandUtility.urlEncode(args); 68 if (!queryString.isEmpty()) { 69 uri = uri + "?" + queryString; 70 } 71 72 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 73 reqBuilder.addHeader("Accept", "application/json"); 74 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 75 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo, privateKey, METHOD, uri, null)); 76 reqBuilder.method(METHOD, null); 77 Request httpRequest = reqBuilder.build(); 78 79 // 发送HTTP请求 80 OkHttpClient client = new OkHttpClient.Builder().build(); 81 try (Response httpResponse = client.newCall(httpRequest).execute()) { 82 String respBody = WXPayBrandUtility.extractBody(httpResponse); 83 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 84 // 2XX 成功,验证应答签名 85 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 86 httpResponse.headers(), respBody); 87 88 // 从HTTP应答报文构建返回数据 89 return WXPayBrandUtility.fromJson(respBody, ListUserProductCouponsResponse.class); 90 } else { 91 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 92 } 93 } catch (IOException e) { 94 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 95 } 96 } 97 98 private final String brand_id; 99 private final String certificateSerialNo; 100 private final PrivateKey privateKey; 101 private final String wechatPayPublicKeyId; 102 private final PublicKey wechatPayPublicKey; 103 104 public ListUserProductCoupons(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 105 this.brand_id = brand_id; 106 this.certificateSerialNo = certificateSerialNo; 107 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 108 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 109 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 110 } 111 112 public static class ListUserProductCouponsRequest { 113 @SerializedName("product_coupon_id") 114 @Expose(serialize = false) 115 public String productCouponId; 116 117 @SerializedName("stock_id") 118 @Expose(serialize = false) 119 public String stockId; 120 121 @SerializedName("appid") 122 @Expose(serialize = false) 123 public String appid; 124 125 @SerializedName("openid") 126 @Expose(serialize = false) 127 public String openid; 128 129 @SerializedName("user_coupon_bundle_id") 130 @Expose(serialize = false) 131 public String userCouponBundleId; 132 133 @SerializedName("page_size") 134 @Expose(serialize = false) 135 public Long pageSize; 136 137 @SerializedName("page_token") 138 @Expose(serialize = false) 139 public String pageToken; 140 141 @SerializedName("coupon_state") 142 @Expose(serialize = false) 143 public UserProductCouponState couponState; 144 } 145 146 public static class ListUserProductCouponsResponse { 147 @SerializedName("total_count") 148 public Long totalCount; 149 150 @SerializedName("user_coupon_list") 151 public List<UserProductCouponEntity> userCouponList; 152 153 @SerializedName("next_page_token") 154 public String nextPageToken; 155 } 156 157 public enum UserProductCouponState { 158 @SerializedName("CONFIRMING") 159 CONFIRMING, 160 @SerializedName("PENDING") 161 PENDING, 162 @SerializedName("EFFECTIVE") 163 EFFECTIVE, 164 @SerializedName("USED") 165 USED, 166 @SerializedName("EXPIRED") 167 EXPIRED, 168 @SerializedName("DELETED") 169 DELETED, 170 @SerializedName("DEACTIVATED") 171 DEACTIVATED 172 } 173 174 public static class UserProductCouponEntity { 175 @SerializedName("coupon_code") 176 public String couponCode; 177 178 @SerializedName("coupon_state") 179 public UserProductCouponState couponState; 180 181 @SerializedName("valid_begin_time") 182 public String validBeginTime; 183 184 @SerializedName("valid_end_time") 185 public String validEndTime; 186 187 @SerializedName("receive_time") 188 public String receiveTime; 189 190 @SerializedName("send_request_no") 191 public String sendRequestNo; 192 193 @SerializedName("send_channel") 194 public UserProductCouponSendChannel sendChannel; 195 196 @SerializedName("confirm_request_no") 197 public String confirmRequestNo; 198 199 @SerializedName("confirm_time") 200 public String confirmTime; 201 202 @SerializedName("deactivate_request_no") 203 public String deactivateRequestNo; 204 205 @SerializedName("deactivate_time") 206 public String deactivateTime; 207 208 @SerializedName("deactivate_reason") 209 public String deactivateReason; 210 211 @SerializedName("single_usage_detail") 212 public CouponUsageDetail singleUsageDetail; 213 214 @SerializedName("progressive_bundle_usage_detail") 215 public CouponUsageDetail progressiveBundleUsageDetail; 216 217 @SerializedName("user_product_coupon_bundle_info") 218 public UserProductCouponBundleInfo userProductCouponBundleInfo; 219 220 @SerializedName("product_coupon") 221 public ProductCouponEntity productCoupon; 222 223 @SerializedName("stock") 224 public StockEntity stock; 225 226 @SerializedName("attach") 227 public String attach; 228 229 @SerializedName("channel_custom_info") 230 public String channelCustomInfo; 231 232 @SerializedName("coupon_tag_info") 233 public CouponTagInfo couponTagInfo; 234 } 235 236 public enum UserProductCouponSendChannel { 237 @SerializedName("BRAND_MANAGE") 238 BRAND_MANAGE, 239 @SerializedName("API") 240 API, 241 @SerializedName("RECEIVE_COMPONENT") 242 RECEIVE_COMPONENT 243 } 244 245 public static class CouponUsageDetail { 246 @SerializedName("use_request_no") 247 public String useRequestNo; 248 249 @SerializedName("use_time") 250 public String useTime; 251 252 @SerializedName("return_request_no") 253 public String returnRequestNo; 254 255 @SerializedName("return_time") 256 public String returnTime; 257 258 @SerializedName("associated_order_info") 259 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 260 261 @SerializedName("associated_pay_score_order_info") 262 public UserProductCouponAssociatedPayScoreOrderInfo associatedPayScoreOrderInfo; 263 } 264 265 public static class UserProductCouponBundleInfo { 266 @SerializedName("user_coupon_bundle_id") 267 public String userCouponBundleId; 268 269 @SerializedName("user_coupon_bundle_index") 270 public Long userCouponBundleIndex; 271 272 @SerializedName("total_count") 273 public Long totalCount; 274 275 @SerializedName("used_count") 276 public Long usedCount; 277 } 278 279 public static class ProductCouponEntity { 280 @SerializedName("product_coupon_id") 281 public String productCouponId; 282 283 @SerializedName("scope") 284 public ProductCouponScope scope; 285 286 @SerializedName("type") 287 public ProductCouponType type; 288 289 @SerializedName("usage_mode") 290 public UsageMode usageMode; 291 292 @SerializedName("single_usage_info") 293 public SingleUsageInfo singleUsageInfo; 294 295 @SerializedName("progressive_bundle_usage_info") 296 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 297 298 @SerializedName("display_info") 299 public ProductCouponDisplayInfo displayInfo; 300 301 @SerializedName("out_product_no") 302 public String outProductNo; 303 304 @SerializedName("state") 305 public ProductCouponState state; 306 307 @SerializedName("deactivate_request_no") 308 public String deactivateRequestNo; 309 310 @SerializedName("deactivate_time") 311 public String deactivateTime; 312 313 @SerializedName("deactivate_reason") 314 public String deactivateReason; 315 } 316 317 public static class StockEntity { 318 @SerializedName("product_coupon_id") 319 public String productCouponId; 320 321 @SerializedName("stock_id") 322 public String stockId; 323 324 @SerializedName("remark") 325 public String remark; 326 327 @SerializedName("coupon_code_mode") 328 public CouponCodeMode couponCodeMode; 329 330 @SerializedName("coupon_code_count_info") 331 public CouponCodeCountInfo couponCodeCountInfo; 332 333 @SerializedName("stock_send_rule") 334 public StockSendRule stockSendRule; 335 336 @SerializedName("single_usage_rule") 337 public SingleUsageRule singleUsageRule; 338 339 @SerializedName("progressive_bundle_usage_rule") 340 public StockUsageRule progressiveBundleUsageRule; 341 342 @SerializedName("stock_bundle_info") 343 public StockBundleInfo stockBundleInfo; 344 345 @SerializedName("usage_rule_display_info") 346 public UsageRuleDisplayInfo usageRuleDisplayInfo; 347 348 @SerializedName("coupon_display_info") 349 public CouponDisplayInfo couponDisplayInfo; 350 351 @SerializedName("notify_config") 352 public NotifyConfig notifyConfig; 353 354 @SerializedName("store_scope") 355 public StockStoreScope storeScope; 356 357 @SerializedName("sent_count_info") 358 public StockSentCountInfo sentCountInfo; 359 360 @SerializedName("state") 361 public StockState state; 362 363 @SerializedName("deactivate_request_no") 364 public String deactivateRequestNo; 365 366 @SerializedName("deactivate_time") 367 public String deactivateTime; 368 369 @SerializedName("deactivate_reason") 370 public String deactivateReason; 371 } 372 373 public static class CouponTagInfo { 374 @SerializedName("coupon_tag_list") 375 public List<UserProductCouponTag> couponTagList; 376 377 @SerializedName("member_tag_info") 378 public MemberTagInfo memberTagInfo; 379 } 380 381 public static class UserProductCouponAssociatedOrderInfo { 382 @SerializedName("transaction_id") 383 public String transactionId; 384 385 @SerializedName("out_trade_no") 386 public String outTradeNo; 387 388 @SerializedName("mchid") 389 public String mchid; 390 391 @SerializedName("sub_mchid") 392 public String subMchid; 393 } 394 395 public static class UserProductCouponAssociatedPayScoreOrderInfo { 396 @SerializedName("order_id") 397 public String orderId; 398 399 @SerializedName("out_order_no") 400 public String outOrderNo; 401 402 @SerializedName("mchid") 403 public String mchid; 404 405 @SerializedName("sub_mchid") 406 public String subMchid; 407 } 408 409 public enum ProductCouponScope { 410 @SerializedName("ALL") 411 ALL, 412 @SerializedName("SINGLE") 413 SINGLE 414 } 415 416 public enum ProductCouponType { 417 @SerializedName("NORMAL") 418 NORMAL, 419 @SerializedName("DISCOUNT") 420 DISCOUNT, 421 @SerializedName("EXCHANGE") 422 EXCHANGE 423 } 424 425 public enum UsageMode { 426 @SerializedName("SINGLE") 427 SINGLE, 428 @SerializedName("PROGRESSIVE_BUNDLE") 429 PROGRESSIVE_BUNDLE 430 } 431 432 public static class SingleUsageInfo { 433 @SerializedName("normal_coupon") 434 public NormalCouponUsageRule normalCoupon; 435 436 @SerializedName("discount_coupon") 437 public DiscountCouponUsageRule discountCoupon; 438 } 439 440 public static class ProgressiveBundleUsageInfo { 441 @SerializedName("count") 442 public Long count; 443 444 @SerializedName("interval_days") 445 public Long intervalDays; 446 } 447 448 public static class ProductCouponDisplayInfo { 449 @SerializedName("name") 450 public String name; 451 452 @SerializedName("image_url") 453 public String imageUrl; 454 455 @SerializedName("background_url") 456 public String backgroundUrl; 457 458 @SerializedName("detail_image_url_list") 459 public List<String> detailImageUrlList; 460 461 @SerializedName("original_price") 462 public Long originalPrice; 463 464 @SerializedName("combo_package_list") 465 public List<ComboPackage> comboPackageList; 466 } 467 468 public enum ProductCouponState { 469 @SerializedName("AUDITING") 470 AUDITING, 471 @SerializedName("EFFECTIVE") 472 EFFECTIVE, 473 @SerializedName("DEACTIVATED") 474 DEACTIVATED 475 } 476 477 public enum CouponCodeMode { 478 @SerializedName("WECHATPAY") 479 WECHATPAY, 480 @SerializedName("UPLOAD") 481 UPLOAD, 482 @SerializedName("API_ASSIGN") 483 API_ASSIGN 484 } 485 486 public static class CouponCodeCountInfo { 487 @SerializedName("total_count") 488 public Long totalCount; 489 490 @SerializedName("available_count") 491 public Long availableCount; 492 } 493 494 public static class StockSendRule { 495 @SerializedName("max_count") 496 public Long maxCount; 497 498 @SerializedName("max_count_per_day") 499 public Long maxCountPerDay; 500 501 @SerializedName("max_count_per_user") 502 public Long maxCountPerUser; 503 } 504 505 public static class SingleUsageRule { 506 @SerializedName("coupon_available_period") 507 public CouponAvailablePeriod couponAvailablePeriod; 508 509 @SerializedName("normal_coupon") 510 public NormalCouponUsageRule normalCoupon; 511 512 @SerializedName("discount_coupon") 513 public DiscountCouponUsageRule discountCoupon; 514 515 @SerializedName("exchange_coupon") 516 public ExchangeCouponUsageRule exchangeCoupon; 517 } 518 519 public static class StockUsageRule { 520 @SerializedName("coupon_available_period") 521 public CouponAvailablePeriod couponAvailablePeriod; 522 523 @SerializedName("normal_coupon") 524 public NormalCouponUsageRule normalCoupon; 525 526 @SerializedName("discount_coupon") 527 public DiscountCouponUsageRule discountCoupon; 528 529 @SerializedName("exchange_coupon") 530 public ExchangeCouponUsageRule exchangeCoupon; 531 } 532 533 public static class StockBundleInfo { 534 @SerializedName("stock_bundle_id") 535 public String stockBundleId; 536 537 @SerializedName("stock_bundle_index") 538 public Long stockBundleIndex; 539 } 540 541 public static class UsageRuleDisplayInfo { 542 @SerializedName("coupon_usage_method_list") 543 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 544 545 @SerializedName("mini_program_appid") 546 public String miniProgramAppid; 547 548 @SerializedName("mini_program_path") 549 public String miniProgramPath; 550 551 @SerializedName("app_path") 552 public String appPath; 553 554 @SerializedName("usage_description") 555 public String usageDescription; 556 557 @SerializedName("coupon_available_store_info") 558 public CouponAvailableStoreInfo couponAvailableStoreInfo; 559 } 560 561 public static class CouponDisplayInfo { 562 @SerializedName("code_display_mode") 563 public CouponCodeDisplayMode codeDisplayMode; 564 565 @SerializedName("background_color") 566 public String backgroundColor; 567 568 @SerializedName("entrance_mini_program") 569 public EntranceMiniProgram entranceMiniProgram; 570 571 @SerializedName("entrance_official_account") 572 public EntranceOfficialAccount entranceOfficialAccount; 573 574 @SerializedName("entrance_finder") 575 public EntranceFinder entranceFinder; 576 } 577 578 public static class NotifyConfig { 579 @SerializedName("notify_appid") 580 public String notifyAppid; 581 } 582 583 public enum StockStoreScope { 584 @SerializedName("NONE") 585 NONE, 586 @SerializedName("ALL") 587 ALL, 588 @SerializedName("SPECIFIC") 589 SPECIFIC 590 } 591 592 public static class StockSentCountInfo { 593 @SerializedName("total_count") 594 public Long totalCount; 595 596 @SerializedName("today_count") 597 public Long todayCount; 598 } 599 600 public enum StockState { 601 @SerializedName("AUDITING") 602 AUDITING, 603 @SerializedName("SENDING") 604 SENDING, 605 @SerializedName("PAUSED") 606 PAUSED, 607 @SerializedName("STOPPED") 608 STOPPED, 609 @SerializedName("DEACTIVATED") 610 DEACTIVATED 611 } 612 613 public enum UserProductCouponTag { 614 @SerializedName("MEMBER") 615 MEMBER 616 } 617 618 public static class MemberTagInfo { 619 @SerializedName("member_card_id") 620 public String memberCardId; 621 } 622 623 public static class NormalCouponUsageRule { 624 @SerializedName("threshold") 625 public Long threshold; 626 627 @SerializedName("discount_amount") 628 public Long discountAmount; 629 } 630 631 public static class DiscountCouponUsageRule { 632 @SerializedName("threshold") 633 public Long threshold; 634 635 @SerializedName("percent_off") 636 public Long percentOff; 637 } 638 639 public static class ComboPackage { 640 @SerializedName("name") 641 public String name; 642 643 @SerializedName("pick_count") 644 public Long pickCount; 645 646 @SerializedName("choice_list") 647 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 648 } 649 650 public static class CouponAvailablePeriod { 651 @SerializedName("available_begin_time") 652 public String availableBeginTime; 653 654 @SerializedName("available_end_time") 655 public String availableEndTime; 656 657 @SerializedName("available_days") 658 public Long availableDays; 659 660 @SerializedName("wait_days_after_receive") 661 public Long waitDaysAfterReceive; 662 663 @SerializedName("weekly_available_period") 664 public FixedWeekPeriod weeklyAvailablePeriod; 665 666 @SerializedName("irregular_available_period_list") 667 public List<TimePeriod> irregularAvailablePeriodList; 668 } 669 670 public static class ExchangeCouponUsageRule { 671 @SerializedName("threshold") 672 public Long threshold; 673 674 @SerializedName("exchange_price") 675 public Long exchangePrice; 676 } 677 678 public enum CouponUsageMethod { 679 @SerializedName("OFFLINE") 680 OFFLINE, 681 @SerializedName("MINI_PROGRAM") 682 MINI_PROGRAM, 683 @SerializedName("APP") 684 APP, 685 @SerializedName("PAYMENT_CODE") 686 PAYMENT_CODE 687 } 688 689 public static class CouponAvailableStoreInfo { 690 @SerializedName("description") 691 public String description; 692 693 @SerializedName("mini_program_appid") 694 public String miniProgramAppid; 695 696 @SerializedName("mini_program_path") 697 public String miniProgramPath; 698 } 699 700 public enum CouponCodeDisplayMode { 701 @SerializedName("INVISIBLE") 702 INVISIBLE, 703 @SerializedName("BARCODE") 704 BARCODE, 705 @SerializedName("QRCODE") 706 QRCODE 707 } 708 709 public static class EntranceMiniProgram { 710 @SerializedName("appid") 711 public String appid; 712 713 @SerializedName("path") 714 public String path; 715 716 @SerializedName("entrance_wording") 717 public String entranceWording; 718 719 @SerializedName("guidance_wording") 720 public String guidanceWording; 721 } 722 723 public static class EntranceOfficialAccount { 724 @SerializedName("appid") 725 public String appid; 726 } 727 728 public static class EntranceFinder { 729 @SerializedName("finder_id") 730 public String finderId; 731 732 @SerializedName("finder_video_id") 733 public String finderVideoId; 734 735 @SerializedName("finder_video_cover_image_url") 736 public String finderVideoCoverImageUrl; 737 } 738 739 public static class ComboPackageChoice { 740 @SerializedName("name") 741 public String name; 742 743 @SerializedName("price") 744 public Long price; 745 746 @SerializedName("count") 747 public Long count; 748 749 @SerializedName("image_url") 750 public String imageUrl; 751 752 @SerializedName("mini_program_appid") 753 public String miniProgramAppid; 754 755 @SerializedName("mini_program_path") 756 public String miniProgramPath; 757 } 758 759 public static class FixedWeekPeriod { 760 @SerializedName("day_list") 761 public List<WeekEnum> dayList; 762 763 @SerializedName("day_period_list") 764 public List<PeriodOfTheDay> dayPeriodList; 765 } 766 767 public static class TimePeriod { 768 @SerializedName("begin_time") 769 public String beginTime; 770 771 @SerializedName("end_time") 772 public String endTime; 773 } 774 775 public enum WeekEnum { 776 @SerializedName("MONDAY") 777 MONDAY, 778 @SerializedName("TUESDAY") 779 TUESDAY, 780 @SerializedName("WEDNESDAY") 781 WEDNESDAY, 782 @SerializedName("THURSDAY") 783 THURSDAY, 784 @SerializedName("FRIDAY") 785 FRIDAY, 786 @SerializedName("SATURDAY") 787 SATURDAY, 788 @SerializedName("SUNDAY") 789 SUNDAY 790 } 791 792 public static class PeriodOfTheDay { 793 @SerializedName("begin_time") 794 public Long beginTime; 795 796 @SerializedName("end_time") 797 public Long endTime; 798 } 799 800} 801
需配合微信支付工具库 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 := &ListUserProductCouponsRequest{ 28 ProductCouponId: wxpay_brand_utility.String("1000000013"), 29 StockId: wxpay_brand_utility.String("1000000013001"), 30 Appid: wxpay_brand_utility.String("wx233544546545989"), 31 Openid: wxpay_brand_utility.String("oh-394z-6CGkNoJrsDLTTUKiAnp4"), 32 PageSize: wxpay_brand_utility.Int64(10), 33 } 34 35 response, err := ListUserProductCoupons(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 ListUserProductCoupons(config *wxpay_brand_utility.BrandConfig, request *ListUserProductCouponsRequest) (response *ListUserProductCouponsResponse, err error) { 47 const ( 48 host = "https://api.mch.weixin.qq.com" 49 method = "GET" 50 path = "/brand/marketing/product-coupon/users/{openid}/coupons" 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, "{openid}", url.PathEscape(*request.Openid), -1) 58 query := reqUrl.Query() 59 if request.ProductCouponId != nil { 60 query.Add("product_coupon_id", *request.ProductCouponId) 61 } 62 if request.StockId != nil { 63 query.Add("stock_id", *request.StockId) 64 } 65 if request.Appid != nil { 66 query.Add("appid", *request.Appid) 67 } 68 if request.CouponState != nil { 69 query.Add("coupon_state", fmt.Sprintf("%v", *request.CouponState)) 70 } 71 if request.UserCouponBundleId != nil { 72 query.Add("user_coupon_bundle_id", *request.UserCouponBundleId) 73 } 74 if request.PageSize != nil { 75 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 76 } 77 if request.PageToken != nil { 78 query.Add("page_token", *request.PageToken) 79 } 80 reqUrl.RawQuery = query.Encode() 81 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 82 if err != nil { 83 return nil, err 84 } 85 httpRequest.Header.Set("Accept", "application/json") 86 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 87 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 88 if err != nil { 89 return nil, err 90 } 91 httpRequest.Header.Set("Authorization", authorization) 92 93 client := &http.Client{} 94 httpResponse, err := client.Do(httpRequest) 95 if err != nil { 96 return nil, err 97 } 98 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 99 if err != nil { 100 return nil, err 101 } 102 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 103 // 2XX 成功,验证应答签名 104 err = wxpay_brand_utility.ValidateResponse( 105 config.WechatPayPublicKeyId(), 106 config.WechatPayPublicKey(), 107 &httpResponse.Header, 108 respBody, 109 ) 110 if err != nil { 111 return nil, err 112 } 113 response := &ListUserProductCouponsResponse{} 114 if err := json.Unmarshal(respBody, response); err != nil { 115 return nil, err 116 } 117 118 return response, nil 119 } else { 120 return nil, wxpay_brand_utility.NewApiException( 121 httpResponse.StatusCode, 122 httpResponse.Header, 123 respBody, 124 ) 125 } 126} 127 128type ListUserProductCouponsRequest struct { 129 ProductCouponId *string `json:"product_coupon_id,omitempty"` 130 StockId *string `json:"stock_id,omitempty"` 131 Appid *string `json:"appid,omitempty"` 132 Openid *string `json:"openid,omitempty"` 133 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 134 PageSize *int64 `json:"page_size,omitempty"` 135 PageToken *string `json:"page_token,omitempty"` 136 CouponState *UserProductCouponState `json:"coupon_state,omitempty"` 137} 138 139func (o *ListUserProductCouponsRequest) MarshalJSON() ([]byte, error) { 140 type Alias ListUserProductCouponsRequest 141 a := &struct { 142 ProductCouponId *string `json:"product_coupon_id,omitempty"` 143 StockId *string `json:"stock_id,omitempty"` 144 Appid *string `json:"appid,omitempty"` 145 Openid *string `json:"openid,omitempty"` 146 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 147 PageSize *int64 `json:"page_size,omitempty"` 148 PageToken *string `json:"page_token,omitempty"` 149 CouponState *UserProductCouponState `json:"coupon_state,omitempty"` 150 *Alias 151 }{ 152 // 序列化时移除非 Body 字段 153 ProductCouponId: nil, 154 StockId: nil, 155 Appid: nil, 156 Openid: nil, 157 UserCouponBundleId: nil, 158 PageSize: nil, 159 PageToken: nil, 160 CouponState: nil, 161 Alias: (*Alias)(o), 162 } 163 return json.Marshal(a) 164} 165 166type ListUserProductCouponsResponse struct { 167 TotalCount *int64 `json:"total_count,omitempty"` 168 UserCouponList []UserProductCouponEntity `json:"user_coupon_list,omitempty"` 169 NextPageToken *string `json:"next_page_token,omitempty"` 170} 171 172type UserProductCouponState string 173 174func (e UserProductCouponState) Ptr() *UserProductCouponState { 175 return &e 176} 177 178const ( 179 USERPRODUCTCOUPONSTATE_CONFIRMING UserProductCouponState = "CONFIRMING" 180 USERPRODUCTCOUPONSTATE_PENDING UserProductCouponState = "PENDING" 181 USERPRODUCTCOUPONSTATE_EFFECTIVE UserProductCouponState = "EFFECTIVE" 182 USERPRODUCTCOUPONSTATE_USED UserProductCouponState = "USED" 183 USERPRODUCTCOUPONSTATE_EXPIRED UserProductCouponState = "EXPIRED" 184 USERPRODUCTCOUPONSTATE_DELETED UserProductCouponState = "DELETED" 185 USERPRODUCTCOUPONSTATE_DEACTIVATED UserProductCouponState = "DEACTIVATED" 186) 187 188type UserProductCouponEntity struct { 189 CouponCode *string `json:"coupon_code,omitempty"` 190 CouponState *UserProductCouponState `json:"coupon_state,omitempty"` 191 ValidBeginTime *time.Time `json:"valid_begin_time,omitempty"` 192 ValidEndTime *time.Time `json:"valid_end_time,omitempty"` 193 ReceiveTime *string `json:"receive_time,omitempty"` 194 SendRequestNo *string `json:"send_request_no,omitempty"` 195 SendChannel *UserProductCouponSendChannel `json:"send_channel,omitempty"` 196 ConfirmRequestNo *string `json:"confirm_request_no,omitempty"` 197 ConfirmTime *time.Time `json:"confirm_time,omitempty"` 198 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 199 DeactivateTime *string `json:"deactivate_time,omitempty"` 200 DeactivateReason *string `json:"deactivate_reason,omitempty"` 201 SingleUsageDetail *CouponUsageDetail `json:"single_usage_detail,omitempty"` 202 ProgressiveBundleUsageDetail *CouponUsageDetail `json:"progressive_bundle_usage_detail,omitempty"` 203 UserProductCouponBundleInfo *UserProductCouponBundleInfo `json:"user_product_coupon_bundle_info,omitempty"` 204 ProductCoupon *ProductCouponEntity `json:"product_coupon,omitempty"` 205 Stock *StockEntity `json:"stock,omitempty"` 206 Attach *string `json:"attach,omitempty"` 207 ChannelCustomInfo *string `json:"channel_custom_info,omitempty"` 208 CouponTagInfo *CouponTagInfo `json:"coupon_tag_info,omitempty"` 209} 210 211type UserProductCouponSendChannel string 212 213func (e UserProductCouponSendChannel) Ptr() *UserProductCouponSendChannel { 214 return &e 215} 216 217const ( 218 USERPRODUCTCOUPONSENDCHANNEL_BRAND_MANAGE UserProductCouponSendChannel = "BRAND_MANAGE" 219 USERPRODUCTCOUPONSENDCHANNEL_API UserProductCouponSendChannel = "API" 220 USERPRODUCTCOUPONSENDCHANNEL_RECEIVE_COMPONENT UserProductCouponSendChannel = "RECEIVE_COMPONENT" 221) 222 223type CouponUsageDetail struct { 224 UseRequestNo *string `json:"use_request_no,omitempty"` 225 UseTime *time.Time `json:"use_time,omitempty"` 226 ReturnRequestNo *string `json:"return_request_no,omitempty"` 227 ReturnTime *time.Time `json:"return_time,omitempty"` 228 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 229 AssociatedPayScoreOrderInfo *UserProductCouponAssociatedPayScoreOrderInfo `json:"associated_pay_score_order_info,omitempty"` 230} 231 232type UserProductCouponBundleInfo struct { 233 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 234 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 235 TotalCount *int64 `json:"total_count,omitempty"` 236 UsedCount *int64 `json:"used_count,omitempty"` 237} 238 239type ProductCouponEntity struct { 240 ProductCouponId *string `json:"product_coupon_id,omitempty"` 241 Scope *ProductCouponScope `json:"scope,omitempty"` 242 Type *ProductCouponType `json:"type,omitempty"` 243 UsageMode *UsageMode `json:"usage_mode,omitempty"` 244 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 245 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 246 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 247 OutProductNo *string `json:"out_product_no,omitempty"` 248 State *ProductCouponState `json:"state,omitempty"` 249 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 250 DeactivateTime *string `json:"deactivate_time,omitempty"` 251 DeactivateReason *string `json:"deactivate_reason,omitempty"` 252} 253 254type StockEntity struct { 255 ProductCouponId *string `json:"product_coupon_id,omitempty"` 256 StockId *string `json:"stock_id,omitempty"` 257 Remark *string `json:"remark,omitempty"` 258 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 259 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 260 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 261 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 262 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 263 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 264 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 265 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 266 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 267 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 268 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 269 State *StockState `json:"state,omitempty"` 270 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 271 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 272 DeactivateReason *string `json:"deactivate_reason,omitempty"` 273} 274 275type CouponTagInfo struct { 276 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 277 MemberTagInfo *MemberTagInfo `json:"member_tag_info,omitempty"` 278} 279 280type UserProductCouponAssociatedOrderInfo struct { 281 TransactionId *string `json:"transaction_id,omitempty"` 282 OutTradeNo *string `json:"out_trade_no,omitempty"` 283 Mchid *string `json:"mchid,omitempty"` 284 SubMchid *string `json:"sub_mchid,omitempty"` 285} 286 287type UserProductCouponAssociatedPayScoreOrderInfo struct { 288 OrderId *string `json:"order_id,omitempty"` 289 OutOrderNo *string `json:"out_order_no,omitempty"` 290 Mchid *string `json:"mchid,omitempty"` 291 SubMchid *string `json:"sub_mchid,omitempty"` 292} 293 294type ProductCouponScope string 295 296func (e ProductCouponScope) Ptr() *ProductCouponScope { 297 return &e 298} 299 300const ( 301 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 302 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 303) 304 305type ProductCouponType string 306 307func (e ProductCouponType) Ptr() *ProductCouponType { 308 return &e 309} 310 311const ( 312 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 313 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 314 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 315) 316 317type UsageMode string 318 319func (e UsageMode) Ptr() *UsageMode { 320 return &e 321} 322 323const ( 324 USAGEMODE_SINGLE UsageMode = "SINGLE" 325 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 326) 327 328type SingleUsageInfo struct { 329 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 330 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 331} 332 333type ProgressiveBundleUsageInfo struct { 334 Count *int64 `json:"count,omitempty"` 335 IntervalDays *int64 `json:"interval_days,omitempty"` 336} 337 338type ProductCouponDisplayInfo struct { 339 Name *string `json:"name,omitempty"` 340 ImageUrl *string `json:"image_url,omitempty"` 341 BackgroundUrl *string `json:"background_url,omitempty"` 342 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 343 OriginalPrice *int64 `json:"original_price,omitempty"` 344 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 345} 346 347type ProductCouponState string 348 349func (e ProductCouponState) Ptr() *ProductCouponState { 350 return &e 351} 352 353const ( 354 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 355 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 356 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 357) 358 359type CouponCodeMode string 360 361func (e CouponCodeMode) Ptr() *CouponCodeMode { 362 return &e 363} 364 365const ( 366 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 367 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 368 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 369) 370 371type CouponCodeCountInfo struct { 372 TotalCount *int64 `json:"total_count,omitempty"` 373 AvailableCount *int64 `json:"available_count,omitempty"` 374} 375 376type StockSendRule struct { 377 MaxCount *int64 `json:"max_count,omitempty"` 378 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 379 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 380} 381 382type SingleUsageRule struct { 383 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 384 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 385 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 386 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 387} 388 389type StockUsageRule struct { 390 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 391 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 392 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 393 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 394} 395 396type StockBundleInfo struct { 397 StockBundleId *string `json:"stock_bundle_id,omitempty"` 398 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 399} 400 401type UsageRuleDisplayInfo struct { 402 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 403 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 404 MiniProgramPath *string `json:"mini_program_path,omitempty"` 405 AppPath *string `json:"app_path,omitempty"` 406 UsageDescription *string `json:"usage_description,omitempty"` 407 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 408} 409 410type CouponDisplayInfo struct { 411 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 412 BackgroundColor *string `json:"background_color,omitempty"` 413 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 414 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 415 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 416} 417 418type NotifyConfig struct { 419 NotifyAppid *string `json:"notify_appid,omitempty"` 420} 421 422type StockStoreScope string 423 424func (e StockStoreScope) Ptr() *StockStoreScope { 425 return &e 426} 427 428const ( 429 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 430 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 431 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 432) 433 434type StockSentCountInfo struct { 435 TotalCount *int64 `json:"total_count,omitempty"` 436 TodayCount *int64 `json:"today_count,omitempty"` 437} 438 439type StockState string 440 441func (e StockState) Ptr() *StockState { 442 return &e 443} 444 445const ( 446 STOCKSTATE_AUDITING StockState = "AUDITING" 447 STOCKSTATE_SENDING StockState = "SENDING" 448 STOCKSTATE_PAUSED StockState = "PAUSED" 449 STOCKSTATE_STOPPED StockState = "STOPPED" 450 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 451) 452 453type UserProductCouponTag string 454 455func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 456 return &e 457} 458 459const ( 460 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 461) 462 463type MemberTagInfo struct { 464 MemberCardId *string `json:"member_card_id,omitempty"` 465} 466 467type NormalCouponUsageRule struct { 468 Threshold *int64 `json:"threshold,omitempty"` 469 DiscountAmount *int64 `json:"discount_amount,omitempty"` 470} 471 472type DiscountCouponUsageRule struct { 473 Threshold *int64 `json:"threshold,omitempty"` 474 PercentOff *int64 `json:"percent_off,omitempty"` 475} 476 477type ComboPackage struct { 478 Name *string `json:"name,omitempty"` 479 PickCount *int64 `json:"pick_count,omitempty"` 480 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 481} 482 483type CouponAvailablePeriod struct { 484 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 485 AvailableEndTime *string `json:"available_end_time,omitempty"` 486 AvailableDays *int64 `json:"available_days,omitempty"` 487 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 488 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 489 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 490} 491 492type ExchangeCouponUsageRule struct { 493 Threshold *int64 `json:"threshold,omitempty"` 494 ExchangePrice *int64 `json:"exchange_price,omitempty"` 495} 496 497type CouponUsageMethod string 498 499func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 500 return &e 501} 502 503const ( 504 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 505 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 506 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 507 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 508) 509 510type CouponAvailableStoreInfo struct { 511 Description *string `json:"description,omitempty"` 512 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 513 MiniProgramPath *string `json:"mini_program_path,omitempty"` 514} 515 516type CouponCodeDisplayMode string 517 518func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 519 return &e 520} 521 522const ( 523 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 524 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 525 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 526) 527 528type EntranceMiniProgram struct { 529 Appid *string `json:"appid,omitempty"` 530 Path *string `json:"path,omitempty"` 531 EntranceWording *string `json:"entrance_wording,omitempty"` 532 GuidanceWording *string `json:"guidance_wording,omitempty"` 533} 534 535type EntranceOfficialAccount struct { 536 Appid *string `json:"appid,omitempty"` 537} 538 539type EntranceFinder struct { 540 FinderId *string `json:"finder_id,omitempty"` 541 FinderVideoId *string `json:"finder_video_id,omitempty"` 542 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 543} 544 545type ComboPackageChoice struct { 546 Name *string `json:"name,omitempty"` 547 Price *int64 `json:"price,omitempty"` 548 Count *int64 `json:"count,omitempty"` 549 ImageUrl *string `json:"image_url,omitempty"` 550 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 551 MiniProgramPath *string `json:"mini_program_path,omitempty"` 552} 553 554type FixedWeekPeriod struct { 555 DayList []WeekEnum `json:"day_list,omitempty"` 556 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 557} 558 559type TimePeriod struct { 560 BeginTime *string `json:"begin_time,omitempty"` 561 EndTime *string `json:"end_time,omitempty"` 562} 563 564type WeekEnum string 565 566func (e WeekEnum) Ptr() *WeekEnum { 567 return &e 568} 569 570const ( 571 WEEKENUM_MONDAY WeekEnum = "MONDAY" 572 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 573 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 574 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 575 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 576 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 577 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 578) 579 580type PeriodOfTheDay struct { 581 BeginTime *int64 `json:"begin_time,omitempty"` 582 EndTime *int64 `json:"end_time,omitempty"` 583} 584
应答参数
200 OK
total_count 必填 integer
【总个数】 满足条件的数据总条数,当且仅当 page_token 为空时提供。
user_coupon_list 选填 array[object]
【用户商品券列表】 指定状态的用户商品券列表信息
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coupon_code 必填 string(40) 【用户商品券Code】 用户商品券的唯一标识 coupon_state 必填 string 【用户商品券状态】 可选取值
valid_begin_time 必填 string 【有效期开始时间】 用户商品券可用开始时间,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) valid_end_time 必填 string 【有效期结束时间】 用户商品券可用结束时间。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) receive_time 必填 string 【领券时间】 用户领券时间。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) send_request_no 必填 string(128) 【发券请求单号】 发券时传入的请求流水号 send_channel 必填 string 【发券渠道】 描述用户商品券是经由什么渠道发送的 可选取值
confirm_request_no 选填 string 【确认请求单号】 品牌方确认发券请求时传入的的请求流水号。当且仅当 品牌方调用【确认发放用户商品券API】后提供。 confirm_time 选填 string 【确认发放时间】 品牌方确认发券时间,当且仅当 品牌方调用【确认发放用户商品券API】后提供。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) deactivate_request_no 选填 string(128) 【失效请求单号】 品牌方失效券请求时传入的的请求流水号。当且仅当 deactivate_time 选填 string 【失效时间】 失效时间,当且仅当 deactivate_reason 选填 string(150) 【失效原因】 失效券的原因,当且仅当 single_usage_detail 选填 object 【单券使用详情】 当且仅当
progressive_bundle_usage_detail 选填 object 【多次优惠使用详情】 当且仅当
user_product_coupon_bundle_info 选填 object 【用户券组信息】 当前用户券所属用户券组的信息,当且仅当
product_coupon 必填 object 【商品券信息】 该用户商品券对应的商品券详情
stock 必填 object 【批次信息】 该用户商品券发券时使用的批次详情
attach 选填 string 【自定义附加信息】 调用发券接口时品牌方使用 注: 发券渠道多样,只有品牌方通过发券接口发放的券才会在查询和回调中携带此字段,其他渠道发放的券 channel_custom_info 选填 string(1000) 【渠道自定义信息】 使用微信支付提供的其他渠道(比如「摇一摇有优惠」)发放商品券时,渠道可能会设置该渠道特定的自定义信息,请根据 coupon_tag_info 选填 object 【用户商品券标签信息】 用户商品券标签信息
|
next_page_token 选填 string(100)
【下一页Token】 分页查询时,如果还有更多数据,会返回下一页的Token,请在下一次查询时设置在 page_token 中;如果已无更多数据,则不返回此字段。
应答示例
200 OK
查询用户在某个批次下的券列表
1{ 2 "total_count" : 1, 3 "user_coupon_list" : [ 4 { 5 "coupon_code" : "Code_123456", 6 "coupon_state" : "EFFECTIVE", 7 "valid_begin_time" : "2025-08-02T00:00:00+08:00", 8 "valid_end_time" : "2025-08-31T23:59:59+08:00", 9 "receive_time" : "2025-08-02T00:00:00+08:00", 10 "send_request_no" : "MCHSEND202003101234", 11 "send_channel" : "API", 12 "confirm_request_no" : "MCHCONFIRM202003101234", 13 "confirm_time" : "2025-08-02T00:00:05+08:00", 14 "single_usage_detail" : { }, 15 "product_coupon" : { 16 "product_coupon_id" : "1000000013", 17 "scope" : "ALL", 18 "type" : "DISCOUNT", 19 "usage_mode" : "SINGLE", 20 "single_usage_info" : { 21 "discount_coupon" : { 22 "threshold" : 10000, 23 "percent_off" : 20 24 } 25 }, 26 "display_info" : { 27 "name" : "全场满100立打8折-新名字", 28 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 29 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 30 "detail_image_url_list" : [ 31 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 32 ] 33 }, 34 "state" : "EFFECTIVE", 35 "out_product_no" : "Product_1234567890" 36 }, 37 "stock" : { 38 "product_coupon_id" : "1000000013", 39 "stock_id" : "1000000013001", 40 "remark" : "8月工作日有效批次", 41 "coupon_code_mode" : "UPLOAD", 42 "coupon_code_count_info" : { 43 "total_count" : 0, 44 "available_count" : 0 45 }, 46 "stock_send_rule" : { 47 "max_count" : 10000000, 48 "max_count_per_user" : 1 49 }, 50 "single_usage_rule" : { 51 "coupon_available_period" : { 52 "available_begin_time" : "2025-08-01T00:00:00+08:00", 53 "available_end_time" : "2025-08-31T23:59:59+08:00", 54 "available_days" : 30, 55 "weekly_available_period" : { 56 "day_list" : [ 57 "MONDAY", 58 "TUESDAY", 59 "WEDNESDAY", 60 "THURSDAY", 61 "FRIDAY" 62 ] 63 } 64 } 65 }, 66 "usage_rule_display_info" : { 67 "coupon_usage_method_list" : [ 68 "OFFLINE", 69 "MINI_PROGRAM", 70 "PAYMENT_CODE" 71 ], 72 "mini_program_appid" : "wx1234567890", 73 "mini_program_path" : "/pages/index/product", 74 "usage_description" : "工作日可用", 75 "coupon_available_store_info" : { 76 "description" : "所有门店可用,可使用小程序查看门店列表", 77 "mini_program_appid" : "wx1234567890", 78 "mini_program_path" : "/pages/index/store-list" 79 } 80 }, 81 "coupon_display_info" : { 82 "code_display_mode" : "QRCODE", 83 "background_color" : "Color010", 84 "entrance_mini_program" : { 85 "appid" : "wx1234567890", 86 "path" : "/pages/index/product", 87 "entrance_wording" : "欢迎选购", 88 "guidance_wording" : "获取更多优惠" 89 }, 90 "entrance_official_account" : { 91 "appid" : "wx1234567890" 92 }, 93 "entrance_finder" : { 94 "finder_id" : "gh_12345678", 95 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 96 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 97 } 98 }, 99 "notify_config" : { 100 "notify_appid" : "wx4fd12345678" 101 }, 102 "store_scope" : "NONE", 103 "sent_count_info" : { 104 "total_count" : 0, 105 "today_count" : 0 106 }, 107 "state" : "SENDING" 108 }, 109 "attach" : "any attach content" 110 } 111 ] 112} 113
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
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 |


