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


