指定券状态查询用户商品券列表
更新时间:2025.11.07品牌方可以通过本接口查询已经发放给用户的特定状态的商品券
前置条件:已经给用户发券成功
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/marketing/partner/product-coupon/users/{openid}/coupons
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
接口限频:500/秒(商户号维度)
请求参数
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(单券)】或【确认发放用户商品券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("return_request_no") 262 public String returnRequestNo; 263 264 @SerializedName("return_time") 265 public String returnTime; 266 267 @SerializedName("associated_order_info") 268 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 269 270 @SerializedName("associated_pay_score_order_info") 271 public UserProductCouponAssociatedPayScoreOrderInfo associatedPayScoreOrderInfo; 272 273 @SerializedName("saved_amount") 274 public Long savedAmount; 275 } 276 277 public static class UserProductCouponBundleInfo { 278 @SerializedName("user_coupon_bundle_id") 279 public String userCouponBundleId; 280 281 @SerializedName("user_coupon_bundle_index") 282 public Long userCouponBundleIndex; 283 284 @SerializedName("total_count") 285 public Long totalCount; 286 287 @SerializedName("used_count") 288 public Long usedCount; 289 } 290 291 public static class ProductCouponEntity { 292 @SerializedName("product_coupon_id") 293 public String productCouponId; 294 295 @SerializedName("scope") 296 public ProductCouponScope scope; 297 298 @SerializedName("type") 299 public ProductCouponType type; 300 301 @SerializedName("usage_mode") 302 public UsageMode usageMode; 303 304 @SerializedName("single_usage_info") 305 public SingleUsageInfo singleUsageInfo; 306 307 @SerializedName("progressive_bundle_usage_info") 308 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 309 310 @SerializedName("display_info") 311 public ProductCouponDisplayInfo displayInfo; 312 313 @SerializedName("out_product_no") 314 public String outProductNo; 315 316 @SerializedName("state") 317 public ProductCouponState state; 318 319 @SerializedName("deactivate_request_no") 320 public String deactivateRequestNo; 321 322 @SerializedName("deactivate_time") 323 public String deactivateTime; 324 325 @SerializedName("deactivate_reason") 326 public String deactivateReason; 327 328 @SerializedName("brand_id") 329 public String brandId; 330 } 331 332 public static class StockEntity { 333 @SerializedName("product_coupon_id") 334 public String productCouponId; 335 336 @SerializedName("stock_id") 337 public String stockId; 338 339 @SerializedName("remark") 340 public String remark; 341 342 @SerializedName("coupon_code_mode") 343 public CouponCodeMode couponCodeMode; 344 345 @SerializedName("coupon_code_count_info") 346 public CouponCodeCountInfo couponCodeCountInfo; 347 348 @SerializedName("stock_send_rule") 349 public StockSendRule stockSendRule; 350 351 @SerializedName("single_usage_rule") 352 public SingleUsageRule singleUsageRule; 353 354 @SerializedName("progressive_bundle_usage_rule") 355 public StockUsageRule progressiveBundleUsageRule; 356 357 @SerializedName("stock_bundle_info") 358 public StockBundleInfo stockBundleInfo; 359 360 @SerializedName("usage_rule_display_info") 361 public UsageRuleDisplayInfo usageRuleDisplayInfo; 362 363 @SerializedName("coupon_display_info") 364 public CouponDisplayInfo couponDisplayInfo; 365 366 @SerializedName("notify_config") 367 public NotifyConfig notifyConfig; 368 369 @SerializedName("store_scope") 370 public StockStoreScope storeScope; 371 372 @SerializedName("sent_count_info") 373 public StockSentCountInfo sentCountInfo; 374 375 @SerializedName("state") 376 public StockState state; 377 378 @SerializedName("deactivate_request_no") 379 public String deactivateRequestNo; 380 381 @SerializedName("deactivate_time") 382 public String deactivateTime; 383 384 @SerializedName("deactivate_reason") 385 public String deactivateReason; 386 387 @SerializedName("brand_id") 388 public String brandId; 389 } 390 391 public static class CouponTagInfo { 392 @SerializedName("coupon_tag_list") 393 public List<UserProductCouponTag> couponTagList; 394 395 @SerializedName("member_tag_info") 396 public MemberTagInfo memberTagInfo; 397 } 398 399 public static class UserProductCouponAssociatedOrderInfo { 400 @SerializedName("transaction_id") 401 public String transactionId; 402 403 @SerializedName("out_trade_no") 404 public String outTradeNo; 405 406 @SerializedName("mchid") 407 public String mchid; 408 409 @SerializedName("sub_mchid") 410 public String subMchid; 411 } 412 413 public static class UserProductCouponAssociatedPayScoreOrderInfo { 414 @SerializedName("order_id") 415 public String orderId; 416 417 @SerializedName("out_order_no") 418 public String outOrderNo; 419 420 @SerializedName("mchid") 421 public String mchid; 422 423 @SerializedName("sub_mchid") 424 public String subMchid; 425 } 426 427 public enum ProductCouponScope { 428 @SerializedName("ALL") 429 ALL, 430 @SerializedName("SINGLE") 431 SINGLE 432 } 433 434 public enum ProductCouponType { 435 @SerializedName("NORMAL") 436 NORMAL, 437 @SerializedName("DISCOUNT") 438 DISCOUNT, 439 @SerializedName("EXCHANGE") 440 EXCHANGE 441 } 442 443 public enum UsageMode { 444 @SerializedName("SINGLE") 445 SINGLE, 446 @SerializedName("PROGRESSIVE_BUNDLE") 447 PROGRESSIVE_BUNDLE 448 } 449 450 public static class SingleUsageInfo { 451 @SerializedName("normal_coupon") 452 public NormalCouponUsageRule normalCoupon; 453 454 @SerializedName("discount_coupon") 455 public DiscountCouponUsageRule discountCoupon; 456 } 457 458 public static class ProgressiveBundleUsageInfo { 459 @SerializedName("count") 460 public Long count; 461 462 @SerializedName("interval_days") 463 public Long intervalDays; 464 } 465 466 public static class ProductCouponDisplayInfo { 467 @SerializedName("name") 468 public String name; 469 470 @SerializedName("image_url") 471 public String imageUrl; 472 473 @SerializedName("background_url") 474 public String backgroundUrl; 475 476 @SerializedName("detail_image_url_list") 477 public List<String> detailImageUrlList; 478 479 @SerializedName("original_price") 480 public Long originalPrice; 481 482 @SerializedName("combo_package_list") 483 public List<ComboPackage> comboPackageList; 484 } 485 486 public enum ProductCouponState { 487 @SerializedName("AUDITING") 488 AUDITING, 489 @SerializedName("EFFECTIVE") 490 EFFECTIVE, 491 @SerializedName("DEACTIVATED") 492 DEACTIVATED 493 } 494 495 public enum CouponCodeMode { 496 @SerializedName("WECHATPAY") 497 WECHATPAY, 498 @SerializedName("UPLOAD") 499 UPLOAD, 500 @SerializedName("API_ASSIGN") 501 API_ASSIGN 502 } 503 504 public static class CouponCodeCountInfo { 505 @SerializedName("total_count") 506 public Long totalCount; 507 508 @SerializedName("available_count") 509 public Long availableCount; 510 } 511 512 public static class StockSendRule { 513 @SerializedName("max_count") 514 public Long maxCount; 515 516 @SerializedName("max_count_per_day") 517 public Long maxCountPerDay; 518 519 @SerializedName("max_count_per_user") 520 public Long maxCountPerUser; 521 } 522 523 public static class SingleUsageRule { 524 @SerializedName("coupon_available_period") 525 public CouponAvailablePeriod couponAvailablePeriod; 526 527 @SerializedName("normal_coupon") 528 public NormalCouponUsageRule normalCoupon; 529 530 @SerializedName("discount_coupon") 531 public DiscountCouponUsageRule discountCoupon; 532 533 @SerializedName("exchange_coupon") 534 public ExchangeCouponUsageRule exchangeCoupon; 535 } 536 537 public static class StockUsageRule { 538 @SerializedName("coupon_available_period") 539 public CouponAvailablePeriod couponAvailablePeriod; 540 541 @SerializedName("normal_coupon") 542 public NormalCouponUsageRule normalCoupon; 543 544 @SerializedName("discount_coupon") 545 public DiscountCouponUsageRule discountCoupon; 546 547 @SerializedName("exchange_coupon") 548 public ExchangeCouponUsageRule exchangeCoupon; 549 } 550 551 public static class StockBundleInfo { 552 @SerializedName("stock_bundle_id") 553 public String stockBundleId; 554 555 @SerializedName("stock_bundle_index") 556 public Long stockBundleIndex; 557 } 558 559 public static class UsageRuleDisplayInfo { 560 @SerializedName("coupon_usage_method_list") 561 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 562 563 @SerializedName("mini_program_appid") 564 public String miniProgramAppid; 565 566 @SerializedName("mini_program_path") 567 public String miniProgramPath; 568 569 @SerializedName("app_path") 570 public String appPath; 571 572 @SerializedName("usage_description") 573 public String usageDescription; 574 575 @SerializedName("coupon_available_store_info") 576 public CouponAvailableStoreInfo couponAvailableStoreInfo; 577 } 578 579 public static class CouponDisplayInfo { 580 @SerializedName("code_display_mode") 581 public CouponCodeDisplayMode codeDisplayMode; 582 583 @SerializedName("background_color") 584 public String backgroundColor; 585 586 @SerializedName("entrance_mini_program") 587 public EntranceMiniProgram entranceMiniProgram; 588 589 @SerializedName("entrance_official_account") 590 public EntranceOfficialAccount entranceOfficialAccount; 591 592 @SerializedName("entrance_finder") 593 public EntranceFinder entranceFinder; 594 } 595 596 public static class NotifyConfig { 597 @SerializedName("notify_appid") 598 public String notifyAppid; 599 } 600 601 public enum StockStoreScope { 602 @SerializedName("NONE") 603 NONE, 604 @SerializedName("ALL") 605 ALL, 606 @SerializedName("SPECIFIC") 607 SPECIFIC 608 } 609 610 public static class StockSentCountInfo { 611 @SerializedName("total_count") 612 public Long totalCount; 613 614 @SerializedName("today_count") 615 public Long todayCount; 616 } 617 618 public enum StockState { 619 @SerializedName("AUDITING") 620 AUDITING, 621 @SerializedName("SENDING") 622 SENDING, 623 @SerializedName("PAUSED") 624 PAUSED, 625 @SerializedName("STOPPED") 626 STOPPED, 627 @SerializedName("DEACTIVATED") 628 DEACTIVATED 629 } 630 631 public enum UserProductCouponTag { 632 @SerializedName("MEMBER") 633 MEMBER 634 } 635 636 public static class MemberTagInfo { 637 @SerializedName("member_card_id") 638 public String memberCardId; 639 } 640 641 public static class NormalCouponUsageRule { 642 @SerializedName("threshold") 643 public Long threshold; 644 645 @SerializedName("discount_amount") 646 public Long discountAmount; 647 } 648 649 public static class DiscountCouponUsageRule { 650 @SerializedName("threshold") 651 public Long threshold; 652 653 @SerializedName("percent_off") 654 public Long percentOff; 655 } 656 657 public static class ComboPackage { 658 @SerializedName("name") 659 public String name; 660 661 @SerializedName("pick_count") 662 public Long pickCount; 663 664 @SerializedName("choice_list") 665 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 666 } 667 668 public static class CouponAvailablePeriod { 669 @SerializedName("available_begin_time") 670 public String availableBeginTime; 671 672 @SerializedName("available_end_time") 673 public String availableEndTime; 674 675 @SerializedName("available_days") 676 public Long availableDays; 677 678 @SerializedName("wait_days_after_receive") 679 public Long waitDaysAfterReceive; 680 681 @SerializedName("weekly_available_period") 682 public FixedWeekPeriod weeklyAvailablePeriod; 683 684 @SerializedName("irregular_available_period_list") 685 public List<TimePeriod> irregularAvailablePeriodList; 686 } 687 688 public static class ExchangeCouponUsageRule { 689 @SerializedName("threshold") 690 public Long threshold; 691 692 @SerializedName("exchange_price") 693 public Long exchangePrice; 694 } 695 696 public enum CouponUsageMethod { 697 @SerializedName("OFFLINE") 698 OFFLINE, 699 @SerializedName("MINI_PROGRAM") 700 MINI_PROGRAM, 701 @SerializedName("APP") 702 APP, 703 @SerializedName("PAYMENT_CODE") 704 PAYMENT_CODE 705 } 706 707 public static class CouponAvailableStoreInfo { 708 @SerializedName("description") 709 public String description; 710 711 @SerializedName("mini_program_appid") 712 public String miniProgramAppid; 713 714 @SerializedName("mini_program_path") 715 public String miniProgramPath; 716 } 717 718 public enum CouponCodeDisplayMode { 719 @SerializedName("INVISIBLE") 720 INVISIBLE, 721 @SerializedName("BARCODE") 722 BARCODE, 723 @SerializedName("QRCODE") 724 QRCODE 725 } 726 727 public static class EntranceMiniProgram { 728 @SerializedName("appid") 729 public String appid; 730 731 @SerializedName("path") 732 public String path; 733 734 @SerializedName("entrance_wording") 735 public String entranceWording; 736 737 @SerializedName("guidance_wording") 738 public String guidanceWording; 739 } 740 741 public static class EntranceOfficialAccount { 742 @SerializedName("appid") 743 public String appid; 744 } 745 746 public static class EntranceFinder { 747 @SerializedName("finder_id") 748 public String finderId; 749 750 @SerializedName("finder_video_id") 751 public String finderVideoId; 752 753 @SerializedName("finder_video_cover_image_url") 754 public String finderVideoCoverImageUrl; 755 } 756 757 public static class ComboPackageChoice { 758 @SerializedName("name") 759 public String name; 760 761 @SerializedName("price") 762 public Long price; 763 764 @SerializedName("count") 765 public Long count; 766 767 @SerializedName("image_url") 768 public String imageUrl; 769 770 @SerializedName("mini_program_appid") 771 public String miniProgramAppid; 772 773 @SerializedName("mini_program_path") 774 public String miniProgramPath; 775 } 776 777 public static class FixedWeekPeriod { 778 @SerializedName("day_list") 779 public List<WeekEnum> dayList = new ArrayList<WeekEnum>(); 780 781 @SerializedName("day_period_list") 782 public List<PeriodOfTheDay> dayPeriodList; 783 } 784 785 public static class TimePeriod { 786 @SerializedName("begin_time") 787 public String beginTime; 788 789 @SerializedName("end_time") 790 public String endTime; 791 } 792 793 public enum WeekEnum { 794 @SerializedName("MONDAY") 795 MONDAY, 796 @SerializedName("TUESDAY") 797 TUESDAY, 798 @SerializedName("WEDNESDAY") 799 WEDNESDAY, 800 @SerializedName("THURSDAY") 801 THURSDAY, 802 @SerializedName("FRIDAY") 803 FRIDAY, 804 @SerializedName("SATURDAY") 805 SATURDAY, 806 @SerializedName("SUNDAY") 807 SUNDAY 808 } 809 810 public static class PeriodOfTheDay { 811 @SerializedName("begin_time") 812 public Long beginTime; 813 814 @SerializedName("end_time") 815 public Long endTime; 816 } 817 818} 819
需配合微信支付工具库 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 ReturnRequestNo *string `json:"return_request_no,omitempty"` 235 ReturnTime *time.Time `json:"return_time,omitempty"` 236 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 237 AssociatedPayScoreOrderInfo *UserProductCouponAssociatedPayScoreOrderInfo `json:"associated_pay_score_order_info,omitempty"` 238 SavedAmount *int64 `json:"saved_amount,omitempty"` 239} 240 241type UserProductCouponBundleInfo struct { 242 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 243 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 244 TotalCount *int64 `json:"total_count,omitempty"` 245 UsedCount *int64 `json:"used_count,omitempty"` 246} 247 248type ProductCouponEntity struct { 249 ProductCouponId *string `json:"product_coupon_id,omitempty"` 250 Scope *ProductCouponScope `json:"scope,omitempty"` 251 Type *ProductCouponType `json:"type,omitempty"` 252 UsageMode *UsageMode `json:"usage_mode,omitempty"` 253 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 254 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 255 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 256 OutProductNo *string `json:"out_product_no,omitempty"` 257 State *ProductCouponState `json:"state,omitempty"` 258 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 259 DeactivateTime *string `json:"deactivate_time,omitempty"` 260 DeactivateReason *string `json:"deactivate_reason,omitempty"` 261 BrandId *string `json:"brand_id,omitempty"` 262} 263 264type StockEntity struct { 265 ProductCouponId *string `json:"product_coupon_id,omitempty"` 266 StockId *string `json:"stock_id,omitempty"` 267 Remark *string `json:"remark,omitempty"` 268 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 269 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 270 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 271 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 272 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 273 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 274 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 275 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 276 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 277 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 278 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 279 State *StockState `json:"state,omitempty"` 280 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 281 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 282 DeactivateReason *string `json:"deactivate_reason,omitempty"` 283 BrandId *string `json:"brand_id,omitempty"` 284} 285 286type CouponTagInfo struct { 287 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 288 MemberTagInfo *MemberTagInfo `json:"member_tag_info,omitempty"` 289} 290 291type UserProductCouponAssociatedOrderInfo struct { 292 TransactionId *string `json:"transaction_id,omitempty"` 293 OutTradeNo *string `json:"out_trade_no,omitempty"` 294 Mchid *string `json:"mchid,omitempty"` 295 SubMchid *string `json:"sub_mchid,omitempty"` 296} 297 298type UserProductCouponAssociatedPayScoreOrderInfo struct { 299 OrderId *string `json:"order_id,omitempty"` 300 OutOrderNo *string `json:"out_order_no,omitempty"` 301 Mchid *string `json:"mchid,omitempty"` 302 SubMchid *string `json:"sub_mchid,omitempty"` 303} 304 305type ProductCouponScope string 306 307func (e ProductCouponScope) Ptr() *ProductCouponScope { 308 return &e 309} 310 311const ( 312 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 313 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 314) 315 316type ProductCouponType string 317 318func (e ProductCouponType) Ptr() *ProductCouponType { 319 return &e 320} 321 322const ( 323 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 324 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 325 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 326) 327 328type UsageMode string 329 330func (e UsageMode) Ptr() *UsageMode { 331 return &e 332} 333 334const ( 335 USAGEMODE_SINGLE UsageMode = "SINGLE" 336 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 337) 338 339type SingleUsageInfo struct { 340 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 341 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 342} 343 344type ProgressiveBundleUsageInfo struct { 345 Count *int64 `json:"count,omitempty"` 346 IntervalDays *int64 `json:"interval_days,omitempty"` 347} 348 349type ProductCouponDisplayInfo struct { 350 Name *string `json:"name,omitempty"` 351 ImageUrl *string `json:"image_url,omitempty"` 352 BackgroundUrl *string `json:"background_url,omitempty"` 353 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 354 OriginalPrice *int64 `json:"original_price,omitempty"` 355 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 356} 357 358type ProductCouponState string 359 360func (e ProductCouponState) Ptr() *ProductCouponState { 361 return &e 362} 363 364const ( 365 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 366 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 367 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 368) 369 370type CouponCodeMode string 371 372func (e CouponCodeMode) Ptr() *CouponCodeMode { 373 return &e 374} 375 376const ( 377 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 378 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 379 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 380) 381 382type CouponCodeCountInfo struct { 383 TotalCount *int64 `json:"total_count,omitempty"` 384 AvailableCount *int64 `json:"available_count,omitempty"` 385} 386 387type StockSendRule struct { 388 MaxCount *int64 `json:"max_count,omitempty"` 389 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 390 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 391} 392 393type SingleUsageRule struct { 394 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 395 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 396 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 397 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 398} 399 400type StockUsageRule struct { 401 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 402 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 403 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 404 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 405} 406 407type StockBundleInfo struct { 408 StockBundleId *string `json:"stock_bundle_id,omitempty"` 409 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 410} 411 412type UsageRuleDisplayInfo struct { 413 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 414 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 415 MiniProgramPath *string `json:"mini_program_path,omitempty"` 416 AppPath *string `json:"app_path,omitempty"` 417 UsageDescription *string `json:"usage_description,omitempty"` 418 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 419} 420 421type CouponDisplayInfo struct { 422 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 423 BackgroundColor *string `json:"background_color,omitempty"` 424 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 425 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 426 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 427} 428 429type NotifyConfig struct { 430 NotifyAppid *string `json:"notify_appid,omitempty"` 431} 432 433type StockStoreScope string 434 435func (e StockStoreScope) Ptr() *StockStoreScope { 436 return &e 437} 438 439const ( 440 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 441 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 442 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 443) 444 445type StockSentCountInfo struct { 446 TotalCount *int64 `json:"total_count,omitempty"` 447 TodayCount *int64 `json:"today_count,omitempty"` 448} 449 450type StockState string 451 452func (e StockState) Ptr() *StockState { 453 return &e 454} 455 456const ( 457 STOCKSTATE_AUDITING StockState = "AUDITING" 458 STOCKSTATE_SENDING StockState = "SENDING" 459 STOCKSTATE_PAUSED StockState = "PAUSED" 460 STOCKSTATE_STOPPED StockState = "STOPPED" 461 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 462) 463 464type UserProductCouponTag string 465 466func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 467 return &e 468} 469 470const ( 471 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 472) 473 474type MemberTagInfo struct { 475 MemberCardId *string `json:"member_card_id,omitempty"` 476} 477 478type NormalCouponUsageRule struct { 479 Threshold *int64 `json:"threshold,omitempty"` 480 DiscountAmount *int64 `json:"discount_amount,omitempty"` 481} 482 483type DiscountCouponUsageRule struct { 484 Threshold *int64 `json:"threshold,omitempty"` 485 PercentOff *int64 `json:"percent_off,omitempty"` 486} 487 488type ComboPackage struct { 489 Name *string `json:"name,omitempty"` 490 PickCount *int64 `json:"pick_count,omitempty"` 491 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 492} 493 494type CouponAvailablePeriod struct { 495 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 496 AvailableEndTime *string `json:"available_end_time,omitempty"` 497 AvailableDays *int64 `json:"available_days,omitempty"` 498 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 499 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 500 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 501} 502 503type ExchangeCouponUsageRule struct { 504 Threshold *int64 `json:"threshold,omitempty"` 505 ExchangePrice *int64 `json:"exchange_price,omitempty"` 506} 507 508type CouponUsageMethod string 509 510func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 511 return &e 512} 513 514const ( 515 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 516 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 517 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 518 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 519) 520 521type CouponAvailableStoreInfo struct { 522 Description *string `json:"description,omitempty"` 523 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 524 MiniProgramPath *string `json:"mini_program_path,omitempty"` 525} 526 527type CouponCodeDisplayMode string 528 529func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 530 return &e 531} 532 533const ( 534 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 535 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 536 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 537) 538 539type EntranceMiniProgram struct { 540 Appid *string `json:"appid,omitempty"` 541 Path *string `json:"path,omitempty"` 542 EntranceWording *string `json:"entrance_wording,omitempty"` 543 GuidanceWording *string `json:"guidance_wording,omitempty"` 544} 545 546type EntranceOfficialAccount struct { 547 Appid *string `json:"appid,omitempty"` 548} 549 550type EntranceFinder struct { 551 FinderId *string `json:"finder_id,omitempty"` 552 FinderVideoId *string `json:"finder_video_id,omitempty"` 553 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 554} 555 556type ComboPackageChoice struct { 557 Name *string `json:"name,omitempty"` 558 Price *int64 `json:"price,omitempty"` 559 Count *int64 `json:"count,omitempty"` 560 ImageUrl *string `json:"image_url,omitempty"` 561 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 562 MiniProgramPath *string `json:"mini_program_path,omitempty"` 563} 564 565type FixedWeekPeriod struct { 566 DayList []WeekEnum `json:"day_list,omitempty"` 567 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 568} 569 570type TimePeriod struct { 571 BeginTime *string `json:"begin_time,omitempty"` 572 EndTime *string `json:"end_time,omitempty"` 573} 574 575type WeekEnum string 576 577func (e WeekEnum) Ptr() *WeekEnum { 578 return &e 579} 580 581const ( 582 WEEKENUM_MONDAY WeekEnum = "MONDAY" 583 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 584 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 585 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 586 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 587 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 588 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 589) 590 591type PeriodOfTheDay struct { 592 BeginTime *int64 `json:"begin_time,omitempty"` 593 EndTime *int64 `json:"end_time,omitempty"` 594} 595
应答参数
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 | 请求超过接口频率限制 | 请稍后使用原参数重试 |


