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

