失效用户商品券
更新时间:2025.09.02服务商可以通过本接口将用户的商品券失效
前置条件:已经给用户发券成功,且商品券的 usage_mode 不为 PROGRESSIVE_BUNDLE
频率限制:500/s
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/users/{openid}/coupons/{coupon_code}/deactivate
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
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("user_product_coupon_bundle_info") 176 public UserProductCouponBundleInfo userProductCouponBundleInfo; 177 178 @SerializedName("product_coupon") 179 public ProductCouponEntity productCoupon; 180 181 @SerializedName("stock") 182 public StockEntity stock; 183 184 @SerializedName("attach") 185 public String attach; 186 187 @SerializedName("channel_custom_info") 188 public String channelCustomInfo; 189 190 @SerializedName("coupon_tag_info") 191 public CouponTagInfo couponTagInfo; 192 193 @SerializedName("brand_id") 194 public String brandId; 195 } 196 197 public enum UserProductCouponState { 198 @SerializedName("CONFIRMING") 199 CONFIRMING, 200 @SerializedName("PENDING") 201 PENDING, 202 @SerializedName("EFFECTIVE") 203 EFFECTIVE, 204 @SerializedName("USED") 205 USED, 206 @SerializedName("EXPIRED") 207 EXPIRED, 208 @SerializedName("DELETED") 209 DELETED, 210 @SerializedName("DEACTIVATED") 211 DEACTIVATED 212 } 213 214 public enum UserProductCouponSendChannel { 215 @SerializedName("BRAND_MANAGE") 216 BRAND_MANAGE, 217 @SerializedName("API") 218 API, 219 @SerializedName("RECEIVE_COMPONENT") 220 RECEIVE_COMPONENT 221 } 222 223 public static class CouponUsageDetail { 224 @SerializedName("use_request_no") 225 public String useRequestNo; 226 227 @SerializedName("use_time") 228 public String useTime; 229 230 @SerializedName("associated_order_info") 231 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 232 233 @SerializedName("return_request_no") 234 public String returnRequestNo; 235 236 @SerializedName("return_time") 237 public String returnTime; 238 } 239 240 public static class UserProductCouponBundleInfo { 241 @SerializedName("user_coupon_bundle_id") 242 public String userCouponBundleId; 243 244 @SerializedName("user_coupon_bundle_index") 245 public Long userCouponBundleIndex; 246 247 @SerializedName("total_count") 248 public Long totalCount; 249 250 @SerializedName("used_count") 251 public Long usedCount; 252 } 253 254 public static class ProductCouponEntity { 255 @SerializedName("product_coupon_id") 256 public String productCouponId; 257 258 @SerializedName("scope") 259 public ProductCouponScope scope; 260 261 @SerializedName("type") 262 public ProductCouponType type; 263 264 @SerializedName("usage_mode") 265 public UsageMode usageMode; 266 267 @SerializedName("single_usage_info") 268 public SingleUsageInfo singleUsageInfo; 269 270 @SerializedName("progressive_bundle_usage_info") 271 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 272 273 @SerializedName("display_info") 274 public ProductCouponDisplayInfo displayInfo; 275 276 @SerializedName("out_product_no") 277 public String outProductNo; 278 279 @SerializedName("state") 280 public ProductCouponState state; 281 282 @SerializedName("deactivate_request_no") 283 public String deactivateRequestNo; 284 285 @SerializedName("deactivate_time") 286 public String deactivateTime; 287 288 @SerializedName("deactivate_reason") 289 public String deactivateReason; 290 291 @SerializedName("brand_id") 292 public String brandId; 293 } 294 295 public static class StockEntity { 296 @SerializedName("product_coupon_id") 297 public String productCouponId; 298 299 @SerializedName("stock_id") 300 public String stockId; 301 302 @SerializedName("remark") 303 public String remark; 304 305 @SerializedName("coupon_code_mode") 306 public CouponCodeMode couponCodeMode; 307 308 @SerializedName("coupon_code_count_info") 309 public CouponCodeCountInfo couponCodeCountInfo; 310 311 @SerializedName("stock_send_rule") 312 public StockSendRule stockSendRule; 313 314 @SerializedName("single_usage_rule") 315 public SingleUsageRule singleUsageRule; 316 317 @SerializedName("usage_rule_display_info") 318 public UsageRuleDisplayInfo usageRuleDisplayInfo; 319 320 @SerializedName("coupon_display_info") 321 public CouponDisplayInfo couponDisplayInfo; 322 323 @SerializedName("notify_config") 324 public NotifyConfig notifyConfig; 325 326 @SerializedName("store_scope") 327 public StockStoreScope storeScope; 328 329 @SerializedName("sent_count_info") 330 public StockSentCountInfo sentCountInfo; 331 332 @SerializedName("state") 333 public StockState state; 334 335 @SerializedName("deactivate_request_no") 336 public String deactivateRequestNo; 337 338 @SerializedName("deactivate_time") 339 public String deactivateTime; 340 341 @SerializedName("deactivate_reason") 342 public String deactivateReason; 343 344 @SerializedName("brand_id") 345 public String brandId; 346 } 347 348 public static class CouponTagInfo { 349 @SerializedName("coupon_tag_list") 350 public List<UserProductCouponTag> couponTagList; 351 352 @SerializedName("member_tag_info") 353 public MemberTagInfo memberTagInfo; 354 } 355 356 public static class UserProductCouponAssociatedOrderInfo { 357 @SerializedName("transaction_id") 358 public String transactionId; 359 360 @SerializedName("out_trade_no") 361 public String outTradeNo; 362 363 @SerializedName("mchid") 364 public String mchid; 365 366 @SerializedName("sub_mchid") 367 public String subMchid; 368 } 369 370 public enum ProductCouponScope { 371 @SerializedName("ALL") 372 ALL, 373 @SerializedName("SINGLE") 374 SINGLE 375 } 376 377 public enum ProductCouponType { 378 @SerializedName("NORMAL") 379 NORMAL, 380 @SerializedName("DISCOUNT") 381 DISCOUNT, 382 @SerializedName("EXCHANGE") 383 EXCHANGE 384 } 385 386 public enum UsageMode { 387 @SerializedName("SINGLE") 388 SINGLE, 389 @SerializedName("PROGRESSIVE_BUNDLE") 390 PROGRESSIVE_BUNDLE 391 } 392 393 public static class SingleUsageInfo { 394 @SerializedName("normal_coupon") 395 public NormalCouponUsageRule normalCoupon; 396 397 @SerializedName("discount_coupon") 398 public DiscountCouponUsageRule discountCoupon; 399 } 400 401 public static class ProgressiveBundleUsageInfo { 402 @SerializedName("count") 403 public Long count; 404 405 @SerializedName("interval_days") 406 public Long intervalDays; 407 } 408 409 public static class ProductCouponDisplayInfo { 410 @SerializedName("name") 411 public String name; 412 413 @SerializedName("image_url") 414 public String imageUrl; 415 416 @SerializedName("background_url") 417 public String backgroundUrl; 418 419 @SerializedName("detail_image_url_list") 420 public List<String> detailImageUrlList; 421 422 @SerializedName("original_price") 423 public Long originalPrice; 424 425 @SerializedName("combo_package_list") 426 public List<ComboPackage> comboPackageList; 427 } 428 429 public enum ProductCouponState { 430 @SerializedName("AUDITING") 431 AUDITING, 432 @SerializedName("EFFECTIVE") 433 EFFECTIVE, 434 @SerializedName("DEACTIVATED") 435 DEACTIVATED 436 } 437 438 public enum CouponCodeMode { 439 @SerializedName("WECHATPAY") 440 WECHATPAY, 441 @SerializedName("UPLOAD") 442 UPLOAD, 443 @SerializedName("API_ASSIGN") 444 API_ASSIGN 445 } 446 447 public static class CouponCodeCountInfo { 448 @SerializedName("total_count") 449 public Long totalCount; 450 451 @SerializedName("available_count") 452 public Long availableCount; 453 } 454 455 public static class StockSendRule { 456 @SerializedName("max_count") 457 public Long maxCount; 458 459 @SerializedName("max_count_per_day") 460 public Long maxCountPerDay; 461 462 @SerializedName("max_count_per_user") 463 public Long maxCountPerUser; 464 } 465 466 public static class SingleUsageRule { 467 @SerializedName("coupon_available_period") 468 public CouponAvailablePeriod couponAvailablePeriod; 469 470 @SerializedName("normal_coupon") 471 public NormalCouponUsageRule normalCoupon; 472 473 @SerializedName("discount_coupon") 474 public DiscountCouponUsageRule discountCoupon; 475 476 @SerializedName("exchange_coupon") 477 public ExchangeCouponUsageRule exchangeCoupon; 478 } 479 480 public static class UsageRuleDisplayInfo { 481 @SerializedName("coupon_usage_method_list") 482 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 483 484 @SerializedName("mini_program_appid") 485 public String miniProgramAppid; 486 487 @SerializedName("mini_program_path") 488 public String miniProgramPath; 489 490 @SerializedName("app_path") 491 public String appPath; 492 493 @SerializedName("usage_description") 494 public String usageDescription; 495 496 @SerializedName("coupon_available_store_info") 497 public CouponAvailableStoreInfo couponAvailableStoreInfo; 498 } 499 500 public static class CouponDisplayInfo { 501 @SerializedName("code_display_mode") 502 public CouponCodeDisplayMode codeDisplayMode; 503 504 @SerializedName("background_color") 505 public String backgroundColor; 506 507 @SerializedName("entrance_mini_program") 508 public EntranceMiniProgram entranceMiniProgram; 509 510 @SerializedName("entrance_official_account") 511 public EntranceOfficialAccount entranceOfficialAccount; 512 513 @SerializedName("entrance_finder") 514 public EntranceFinder entranceFinder; 515 } 516 517 public static class NotifyConfig { 518 @SerializedName("notify_appid") 519 public String notifyAppid; 520 } 521 522 public enum StockStoreScope { 523 @SerializedName("NONE") 524 NONE, 525 @SerializedName("ALL") 526 ALL, 527 @SerializedName("SPECIFIC") 528 SPECIFIC 529 } 530 531 public static class StockSentCountInfo { 532 @SerializedName("total_count") 533 public Long totalCount; 534 535 @SerializedName("today_count") 536 public Long todayCount; 537 } 538 539 public enum StockState { 540 @SerializedName("AUDITING") 541 AUDITING, 542 @SerializedName("SENDING") 543 SENDING, 544 @SerializedName("PAUSED") 545 PAUSED, 546 @SerializedName("STOPPED") 547 STOPPED, 548 @SerializedName("DEACTIVATED") 549 DEACTIVATED 550 } 551 552 public enum UserProductCouponTag { 553 @SerializedName("MEMBER") 554 MEMBER 555 } 556 557 public static class MemberTagInfo { 558 @SerializedName("member_card_id") 559 public String memberCardId; 560 } 561 562 public static class NormalCouponUsageRule { 563 @SerializedName("threshold") 564 public Long threshold; 565 566 @SerializedName("discount_amount") 567 public Long discountAmount; 568 } 569 570 public static class DiscountCouponUsageRule { 571 @SerializedName("threshold") 572 public Long threshold; 573 574 @SerializedName("percent_off") 575 public Long percentOff; 576 } 577 578 public static class ComboPackage { 579 @SerializedName("name") 580 public String name; 581 582 @SerializedName("pick_count") 583 public Long pickCount; 584 585 @SerializedName("choice_list") 586 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 587 } 588 589 public static class CouponAvailablePeriod { 590 @SerializedName("available_begin_time") 591 public String availableBeginTime; 592 593 @SerializedName("available_end_time") 594 public String availableEndTime; 595 596 @SerializedName("available_days") 597 public Long availableDays; 598 599 @SerializedName("wait_days_after_receive") 600 public Long waitDaysAfterReceive; 601 602 @SerializedName("weekly_available_period") 603 public FixedWeekPeriod weeklyAvailablePeriod; 604 605 @SerializedName("irregular_available_period_list") 606 public List<TimePeriod> irregularAvailablePeriodList; 607 } 608 609 public static class ExchangeCouponUsageRule { 610 @SerializedName("threshold") 611 public Long threshold; 612 613 @SerializedName("exchange_price") 614 public Long exchangePrice; 615 } 616 617 public enum CouponUsageMethod { 618 @SerializedName("OFFLINE") 619 OFFLINE, 620 @SerializedName("MINI_PROGRAM") 621 MINI_PROGRAM, 622 @SerializedName("APP") 623 APP, 624 @SerializedName("PAYMENT_CODE") 625 PAYMENT_CODE 626 } 627 628 public static class CouponAvailableStoreInfo { 629 @SerializedName("description") 630 public String description; 631 632 @SerializedName("mini_program_appid") 633 public String miniProgramAppid; 634 635 @SerializedName("mini_program_path") 636 public String miniProgramPath; 637 } 638 639 public enum CouponCodeDisplayMode { 640 @SerializedName("INVISIBLE") 641 INVISIBLE, 642 @SerializedName("BARCODE") 643 BARCODE, 644 @SerializedName("QRCODE") 645 QRCODE 646 } 647 648 public static class EntranceMiniProgram { 649 @SerializedName("appid") 650 public String appid; 651 652 @SerializedName("path") 653 public String path; 654 655 @SerializedName("entrance_wording") 656 public String entranceWording; 657 658 @SerializedName("guidance_wording") 659 public String guidanceWording; 660 } 661 662 public static class EntranceOfficialAccount { 663 @SerializedName("appid") 664 public String appid; 665 } 666 667 public static class EntranceFinder { 668 @SerializedName("finder_id") 669 public String finderId; 670 671 @SerializedName("finder_video_id") 672 public String finderVideoId; 673 674 @SerializedName("finder_video_cover_image_url") 675 public String finderVideoCoverImageUrl; 676 } 677 678 public static class ComboPackageChoice { 679 @SerializedName("name") 680 public String name; 681 682 @SerializedName("price") 683 public Long price; 684 685 @SerializedName("count") 686 public Long count; 687 688 @SerializedName("image_url") 689 public String imageUrl; 690 691 @SerializedName("mini_program_appid") 692 public String miniProgramAppid; 693 694 @SerializedName("mini_program_path") 695 public String miniProgramPath; 696 } 697 698 public static class FixedWeekPeriod { 699 @SerializedName("day_list") 700 public List<WeekEnum> dayList; 701 702 @SerializedName("day_period_list") 703 public List<PeriodOfTheDay> dayPeriodList; 704 } 705 706 public static class TimePeriod { 707 @SerializedName("begin_time") 708 public String beginTime; 709 710 @SerializedName("end_time") 711 public String endTime; 712 } 713 714 public enum WeekEnum { 715 @SerializedName("MONDAY") 716 MONDAY, 717 @SerializedName("TUESDAY") 718 TUESDAY, 719 @SerializedName("WEDNESDAY") 720 WEDNESDAY, 721 @SerializedName("THURSDAY") 722 THURSDAY, 723 @SerializedName("FRIDAY") 724 FRIDAY, 725 @SerializedName("SATURDAY") 726 SATURDAY, 727 @SerializedName("SUNDAY") 728 SUNDAY 729 } 730 731 public static class PeriodOfTheDay { 732 @SerializedName("begin_time") 733 public Long beginTime; 734 735 @SerializedName("end_time") 736 public Long endTime; 737 } 738 739} 740
需配合微信支付工具库 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 UserProductCouponBundleInfo *UserProductCouponBundleInfo `json:"user_product_coupon_bundle_info,omitempty"` 156 ProductCoupon *ProductCouponEntity `json:"product_coupon,omitempty"` 157 Stock *StockEntity `json:"stock,omitempty"` 158 Attach *string `json:"attach,omitempty"` 159 ChannelCustomInfo *string `json:"channel_custom_info,omitempty"` 160 CouponTagInfo *CouponTagInfo `json:"coupon_tag_info,omitempty"` 161 BrandId *string `json:"brand_id,omitempty"` 162} 163 164type UserProductCouponState string 165 166func (e UserProductCouponState) Ptr() *UserProductCouponState { 167 return &e 168} 169 170const ( 171 USERPRODUCTCOUPONSTATE_CONFIRMING UserProductCouponState = "CONFIRMING" 172 USERPRODUCTCOUPONSTATE_PENDING UserProductCouponState = "PENDING" 173 USERPRODUCTCOUPONSTATE_EFFECTIVE UserProductCouponState = "EFFECTIVE" 174 USERPRODUCTCOUPONSTATE_USED UserProductCouponState = "USED" 175 USERPRODUCTCOUPONSTATE_EXPIRED UserProductCouponState = "EXPIRED" 176 USERPRODUCTCOUPONSTATE_DELETED UserProductCouponState = "DELETED" 177 USERPRODUCTCOUPONSTATE_DEACTIVATED UserProductCouponState = "DEACTIVATED" 178) 179 180type UserProductCouponSendChannel string 181 182func (e UserProductCouponSendChannel) Ptr() *UserProductCouponSendChannel { 183 return &e 184} 185 186const ( 187 USERPRODUCTCOUPONSENDCHANNEL_BRAND_MANAGE UserProductCouponSendChannel = "BRAND_MANAGE" 188 USERPRODUCTCOUPONSENDCHANNEL_API UserProductCouponSendChannel = "API" 189 USERPRODUCTCOUPONSENDCHANNEL_RECEIVE_COMPONENT UserProductCouponSendChannel = "RECEIVE_COMPONENT" 190) 191 192type CouponUsageDetail struct { 193 UseRequestNo *string `json:"use_request_no,omitempty"` 194 UseTime *time.Time `json:"use_time,omitempty"` 195 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 196 ReturnRequestNo *string `json:"return_request_no,omitempty"` 197 ReturnTime *time.Time `json:"return_time,omitempty"` 198} 199 200type UserProductCouponBundleInfo struct { 201 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 202 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 203 TotalCount *int64 `json:"total_count,omitempty"` 204 UsedCount *int64 `json:"used_count,omitempty"` 205} 206 207type ProductCouponEntity struct { 208 ProductCouponId *string `json:"product_coupon_id,omitempty"` 209 Scope *ProductCouponScope `json:"scope,omitempty"` 210 Type *ProductCouponType `json:"type,omitempty"` 211 UsageMode *UsageMode `json:"usage_mode,omitempty"` 212 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 213 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 214 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 215 OutProductNo *string `json:"out_product_no,omitempty"` 216 State *ProductCouponState `json:"state,omitempty"` 217 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 218 DeactivateTime *string `json:"deactivate_time,omitempty"` 219 DeactivateReason *string `json:"deactivate_reason,omitempty"` 220 BrandId *string `json:"brand_id,omitempty"` 221} 222 223type StockEntity struct { 224 ProductCouponId *string `json:"product_coupon_id,omitempty"` 225 StockId *string `json:"stock_id,omitempty"` 226 Remark *string `json:"remark,omitempty"` 227 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 228 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 229 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 230 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 231 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 232 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 233 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 234 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 235 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 236 State *StockState `json:"state,omitempty"` 237 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 238 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 239 DeactivateReason *string `json:"deactivate_reason,omitempty"` 240 BrandId *string `json:"brand_id,omitempty"` 241} 242 243type CouponTagInfo struct { 244 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 245 MemberTagInfo *MemberTagInfo `json:"member_tag_info,omitempty"` 246} 247 248type UserProductCouponAssociatedOrderInfo struct { 249 TransactionId *string `json:"transaction_id,omitempty"` 250 OutTradeNo *string `json:"out_trade_no,omitempty"` 251 Mchid *string `json:"mchid,omitempty"` 252 SubMchid *string `json:"sub_mchid,omitempty"` 253} 254 255type ProductCouponScope string 256 257func (e ProductCouponScope) Ptr() *ProductCouponScope { 258 return &e 259} 260 261const ( 262 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 263 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 264) 265 266type ProductCouponType string 267 268func (e ProductCouponType) Ptr() *ProductCouponType { 269 return &e 270} 271 272const ( 273 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 274 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 275 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 276) 277 278type UsageMode string 279 280func (e UsageMode) Ptr() *UsageMode { 281 return &e 282} 283 284const ( 285 USAGEMODE_SINGLE UsageMode = "SINGLE" 286 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 287) 288 289type SingleUsageInfo struct { 290 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 291 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 292} 293 294type ProgressiveBundleUsageInfo struct { 295 Count *int64 `json:"count,omitempty"` 296 IntervalDays *int64 `json:"interval_days,omitempty"` 297} 298 299type ProductCouponDisplayInfo struct { 300 Name *string `json:"name,omitempty"` 301 ImageUrl *string `json:"image_url,omitempty"` 302 BackgroundUrl *string `json:"background_url,omitempty"` 303 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 304 OriginalPrice *int64 `json:"original_price,omitempty"` 305 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 306} 307 308type ProductCouponState string 309 310func (e ProductCouponState) Ptr() *ProductCouponState { 311 return &e 312} 313 314const ( 315 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 316 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 317 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 318) 319 320type CouponCodeMode string 321 322func (e CouponCodeMode) Ptr() *CouponCodeMode { 323 return &e 324} 325 326const ( 327 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 328 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 329 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 330) 331 332type CouponCodeCountInfo struct { 333 TotalCount *int64 `json:"total_count,omitempty"` 334 AvailableCount *int64 `json:"available_count,omitempty"` 335} 336 337type StockSendRule struct { 338 MaxCount *int64 `json:"max_count,omitempty"` 339 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 340 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 341} 342 343type SingleUsageRule struct { 344 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 345 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 346 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 347 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 348} 349 350type UsageRuleDisplayInfo struct { 351 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 352 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 353 MiniProgramPath *string `json:"mini_program_path,omitempty"` 354 AppPath *string `json:"app_path,omitempty"` 355 UsageDescription *string `json:"usage_description,omitempty"` 356 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 357} 358 359type CouponDisplayInfo struct { 360 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 361 BackgroundColor *string `json:"background_color,omitempty"` 362 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 363 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 364 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 365} 366 367type NotifyConfig struct { 368 NotifyAppid *string `json:"notify_appid,omitempty"` 369} 370 371type StockStoreScope string 372 373func (e StockStoreScope) Ptr() *StockStoreScope { 374 return &e 375} 376 377const ( 378 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 379 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 380 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 381) 382 383type StockSentCountInfo struct { 384 TotalCount *int64 `json:"total_count,omitempty"` 385 TodayCount *int64 `json:"today_count,omitempty"` 386} 387 388type StockState string 389 390func (e StockState) Ptr() *StockState { 391 return &e 392} 393 394const ( 395 STOCKSTATE_AUDITING StockState = "AUDITING" 396 STOCKSTATE_SENDING StockState = "SENDING" 397 STOCKSTATE_PAUSED StockState = "PAUSED" 398 STOCKSTATE_STOPPED StockState = "STOPPED" 399 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 400) 401 402type UserProductCouponTag string 403 404func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 405 return &e 406} 407 408const ( 409 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 410) 411 412type MemberTagInfo struct { 413 MemberCardId *string `json:"member_card_id,omitempty"` 414} 415 416type NormalCouponUsageRule struct { 417 Threshold *int64 `json:"threshold,omitempty"` 418 DiscountAmount *int64 `json:"discount_amount,omitempty"` 419} 420 421type DiscountCouponUsageRule struct { 422 Threshold *int64 `json:"threshold,omitempty"` 423 PercentOff *int64 `json:"percent_off,omitempty"` 424} 425 426type ComboPackage struct { 427 Name *string `json:"name,omitempty"` 428 PickCount *int64 `json:"pick_count,omitempty"` 429 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 430} 431 432type CouponAvailablePeriod struct { 433 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 434 AvailableEndTime *string `json:"available_end_time,omitempty"` 435 AvailableDays *int64 `json:"available_days,omitempty"` 436 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 437 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 438 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 439} 440 441type ExchangeCouponUsageRule struct { 442 Threshold *int64 `json:"threshold,omitempty"` 443 ExchangePrice *int64 `json:"exchange_price,omitempty"` 444} 445 446type CouponUsageMethod string 447 448func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 449 return &e 450} 451 452const ( 453 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 454 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 455 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 456 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 457) 458 459type CouponAvailableStoreInfo struct { 460 Description *string `json:"description,omitempty"` 461 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 462 MiniProgramPath *string `json:"mini_program_path,omitempty"` 463} 464 465type CouponCodeDisplayMode string 466 467func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 468 return &e 469} 470 471const ( 472 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 473 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 474 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 475) 476 477type EntranceMiniProgram struct { 478 Appid *string `json:"appid,omitempty"` 479 Path *string `json:"path,omitempty"` 480 EntranceWording *string `json:"entrance_wording,omitempty"` 481 GuidanceWording *string `json:"guidance_wording,omitempty"` 482} 483 484type EntranceOfficialAccount struct { 485 Appid *string `json:"appid,omitempty"` 486} 487 488type EntranceFinder struct { 489 FinderId *string `json:"finder_id,omitempty"` 490 FinderVideoId *string `json:"finder_video_id,omitempty"` 491 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 492} 493 494type ComboPackageChoice struct { 495 Name *string `json:"name,omitempty"` 496 Price *int64 `json:"price,omitempty"` 497 Count *int64 `json:"count,omitempty"` 498 ImageUrl *string `json:"image_url,omitempty"` 499 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 500 MiniProgramPath *string `json:"mini_program_path,omitempty"` 501} 502 503type FixedWeekPeriod struct { 504 DayList []WeekEnum `json:"day_list,omitempty"` 505 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 506} 507 508type TimePeriod struct { 509 BeginTime *string `json:"begin_time,omitempty"` 510 EndTime *string `json:"end_time,omitempty"` 511} 512 513type WeekEnum string 514 515func (e WeekEnum) Ptr() *WeekEnum { 516 return &e 517} 518 519const ( 520 WEEKENUM_MONDAY WeekEnum = "MONDAY" 521 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 522 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 523 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 524 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 525 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 526 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 527) 528 529type PeriodOfTheDay struct { 530 BeginTime *int64 `json:"begin_time,omitempty"` 531 EndTime *int64 `json:"end_time,omitempty"` 532} 533
应答参数
200 OK
coupon_code 必填 string(40)
【用户商品券Code】 用户商品券的唯一标识
coupon_state 必填 string
【用户商品券状态】
可选取值
CONFIRMING: 待确认,用户商品券发放需要品牌方调用【确认发放用户商品券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 【券核销时间】 券被核销的时间,当且仅当用户商品券状态 associated_order_info 选填 object 【券核销的微信支付订单信息】 券核销对应的微信支付订单信息,当且仅当用户商品券状态
return_request_no 选填 string 【退券请求单号】 品牌退券时传入的请求流水号,当且仅当券发生了退回后提供此字段 return_time 选填 string 【退券时间】 券被退回的时间,当且仅当券发生了退回后提供此字段。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) |
user_product_coupon_bundle_info 选填 object
【用户券组信息】 当前用户券所属用户券组的信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时提供
| 属性 | |
user_coupon_bundle_id 必填 string 【用户券组ID】 本券所属的用户券组ID,【向用户发放商品券批次组】时由微信支付生成 user_coupon_bundle_index 必填 integer 【用户券组内索引】 本券在所属用户券组内的序号,从 0 开始编号 total_count 必填 integer 【总可使用次数】 所属用户券组总计可用次数 used_count 必填 integer 【已使用次数】 所属用户券组已使用次数 |
product_coupon 必填 object
【商品券信息】 该用户商品券对应的商品券详情
| 属性 | |||||||||||||||||||||||||||||
product_coupon_id 必填 string(40) 【商品券ID】 商品券的唯一标识,由微信支付生成 scope 必填 string 【优惠范围】 商品券优惠范围 可选取值
type 必填 string 【商品券类型】 商品券的优惠类型 可选取值
usage_mode 必填 string 【使用模式】 商品券使用模式 可选取值
single_usage_info 选填 object 【单券模式信息】 单券模式配置信息,仅当
progressive_bundle_usage_info 选填 object 【多次优惠模式信息】 多次优惠模式配置信息,当且仅当
display_info 必填 object 【展示信息】 商品券展示信息
out_product_no 选填 string 【外部商品ID】 商户创建商品券时主动传入的外部商品ID,原样返回 state 必填 string 【商品券状态】 商品券状态 可选取值
deactivate_request_no 选填 string(128) 【失效请求单号】 当且仅当 deactivate_time 选填 string 【失效时间】 当且仅当 deactivate_reason 选填 string(150) 【失效原因】 当且仅当 brand_id 必填 string 【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系 |
stock 必填 object
【批次信息】 该用户商品券发券时使用的批次详情
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
product_coupon_id 必填 string(40) 【商品券ID】 商品券的唯一标识,由微信支付生成 stock_id 必填 string(40) 【批次ID】 商品券批次的唯一标识,由微信支付生成 remark 选填 string(20) 【备注】 仅配置品牌可见,用于自定义信息 coupon_code_mode 必填 string 【券Code分配模式】 决定发券时用户商品券Code如何产生 可选取值
coupon_code_count_info 选填 object 【品牌方预上传的券Code数量信息】 当且仅当
stock_send_rule 必填 object 【发放规则】 发放规则
single_usage_rule 选填 object 【单券使用规则】 当且仅当
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 | 请求超过接口频率限制 | 请稍后使用原参数重试 |


