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


