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


