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