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


