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


