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


