向用户发放商品券批次组
更新时间:2025.11.27品牌方可以通过本接口向用户发放指定商品券批次组,能否发放受限于商品券组内批次的发放限额:
商品券批次总预算
商品券批次每日预算(如果有)
商品券批次每人限领(如果有)
前置条件: 已创建商品券批次组,批次组内商品券批次处于 SENDING 状态
频率限制:500/s
接口说明
支持商户:【品牌商户】
请求方式:【POST】/brand/marketing/product-coupon/users/{openid}/coupon-bundles
请求域名:【主域名】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 路径参数
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,然后在品牌经营平台中绑定,详见品牌经营平台指引。
send_request_no 必填 string(128)
【发券请求单号】 品牌给用户发券的请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_、短横线- 组成,长度在6-128个字符之间
attach 选填 string(150)
【自定义附加信息】 发券时品牌方可以使用该字段附带自定义附加信息,长度限制150个UTF-8字符。微信支付不会解析该信息,仅在查询用户商品券和回调中原样返回。
注: 发券渠道多样,只有品牌方通过此接口发放的券才会在查询和回调中携带此字段,其他渠道发放的券 attach 为空。
coupon_tag_info 选填 object
【用户商品券标签信息】 用户商品券标签信息
| 属性 | |||||
coupon_tag_list 选填 array[string] 【用户商品券标签列表】 用户商品券标签列表 可选取值
member_tag_info 选填 object 【会员标签信息】 当用户商品券标签列表中有
|
请求示例
POST
发送多次优惠批次组
1curl -X POST \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/users/oh-394z-6CGkNoJrsDLTTUKiAnp4/coupon-bundles \ 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 "stock_bundle_id" : "712315129419284901", 9 "product_coupon_id" : "1000000014", 10 "appid" : "wx233544546545989", 11 "send_request_no" : "MCHCONFIRM202003101234" 12 }' 13
需配合微信支付工具库 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 SendUserProductCouponBundle { 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"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 SendUserProductCouponBundle client = new SendUserProductCouponBundle( 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 SendUserProductCouponBundleRequest request = new SendUserProductCouponBundleRequest(); 41 request.productCouponId = "1000000014"; 42 request.stockBundleId = "712315129419284901"; 43 request.appid = "wx233544546545989"; 44 request.openid = "oh-394z-6CGkNoJrsDLTTUKiAnp4"; 45 request.sendRequestNo = "MCHCONFIRM202003101234"; 46 try { 47 SendUserProductCouponBundleResponse response = client.run(request); 48 // TODO: 请求成功,继续业务逻辑 49 System.out.println(response); 50 } catch (WXPayBrandUtility.ApiException e) { 51 // TODO: 请求失败,根据状态码执行不同的逻辑 52 e.printStackTrace(); 53 } 54 } 55 56 public SendUserProductCouponBundleResponse run(SendUserProductCouponBundleRequest request) { 57 String uri = PATH; 58 uri = uri.replace("{openid}", WXPayBrandUtility.urlEncode(request.openid)); 59 String reqBody = WXPayBrandUtility.toJson(request); 60 61 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 62 reqBuilder.addHeader("Accept", "application/json"); 63 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 64 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 65 reqBuilder.addHeader("Content-Type", "application/json"); 66 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 67 reqBuilder.method(METHOD, requestBody); 68 Request httpRequest = reqBuilder.build(); 69 70 // 发送HTTP请求 71 OkHttpClient client = new OkHttpClient.Builder().build(); 72 try (Response httpResponse = client.newCall(httpRequest).execute()) { 73 String respBody = WXPayBrandUtility.extractBody(httpResponse); 74 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 75 // 2XX 成功,验证应答签名 76 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 77 httpResponse.headers(), respBody); 78 79 // 从HTTP应答报文构建返回数据 80 return WXPayBrandUtility.fromJson(respBody, SendUserProductCouponBundleResponse.class); 81 } else { 82 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 83 } 84 } catch (IOException e) { 85 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 86 } 87 } 88 89 private final String brand_id; 90 private final String certificateSerialNo; 91 private final PrivateKey privateKey; 92 private final String wechatPayPublicKeyId; 93 private final PublicKey wechatPayPublicKey; 94 95 public SendUserProductCouponBundle(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 96 this.brand_id = brand_id; 97 this.certificateSerialNo = certificateSerialNo; 98 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 99 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 100 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 101 } 102 103 public static class SendUserProductCouponBundleRequest { 104 @SerializedName("product_coupon_id") 105 public String productCouponId; 106 107 @SerializedName("stock_bundle_id") 108 public String stockBundleId; 109 110 @SerializedName("appid") 111 public String appid; 112 113 @SerializedName("openid") 114 @Expose(serialize = false) 115 public String openid; 116 117 @SerializedName("send_request_no") 118 public String sendRequestNo; 119 120 @SerializedName("attach") 121 public String attach; 122 123 @SerializedName("coupon_tag_info") 124 public CouponTagInfo couponTagInfo; 125 } 126 127 public static class SendUserProductCouponBundleResponse { 128 @SerializedName("user_coupon_bundle_id") 129 public String userCouponBundleId; 130 131 @SerializedName("user_product_coupon_list") 132 public List<UserProductCouponEntity> userProductCouponList = new ArrayList<UserProductCouponEntity>(); 133 } 134 135 public static class CouponTagInfo { 136 @SerializedName("coupon_tag_list") 137 public List<UserProductCouponTag> couponTagList; 138 139 @SerializedName("member_tag_info") 140 public MemberTagInfo memberTagInfo; 141 } 142 143 public static class UserProductCouponEntity { 144 @SerializedName("coupon_code") 145 public String couponCode; 146 147 @SerializedName("coupon_state") 148 public UserProductCouponState couponState; 149 150 @SerializedName("valid_begin_time") 151 public String validBeginTime; 152 153 @SerializedName("valid_end_time") 154 public String validEndTime; 155 156 @SerializedName("receive_time") 157 public String receiveTime; 158 159 @SerializedName("send_request_no") 160 public String sendRequestNo; 161 162 @SerializedName("send_channel") 163 public UserProductCouponSendChannel sendChannel; 164 165 @SerializedName("confirm_request_no") 166 public String confirmRequestNo; 167 168 @SerializedName("confirm_time") 169 public String confirmTime; 170 171 @SerializedName("deactivate_request_no") 172 public String deactivateRequestNo; 173 174 @SerializedName("deactivate_time") 175 public String deactivateTime; 176 177 @SerializedName("deactivate_reason") 178 public String deactivateReason; 179 180 @SerializedName("progressive_bundle_usage_detail") 181 public CouponUsageDetail progressiveBundleUsageDetail; 182 183 @SerializedName("user_product_coupon_bundle_info") 184 public UserProductCouponBundleInfo userProductCouponBundleInfo; 185 186 @SerializedName("product_coupon") 187 public ProductCouponEntity productCoupon; 188 189 @SerializedName("stock") 190 public StockEntity stock; 191 192 @SerializedName("attach") 193 public String attach; 194 195 @SerializedName("channel_custom_info") 196 public String channelCustomInfo; 197 198 @SerializedName("coupon_tag_info") 199 public CouponTagInfo couponTagInfo; 200 } 201 202 public enum UserProductCouponTag { 203 @SerializedName("MEMBER") 204 MEMBER 205 } 206 207 public static class MemberTagInfo { 208 @SerializedName("member_card_id") 209 public String memberCardId; 210 } 211 212 public enum UserProductCouponState { 213 @SerializedName("CONFIRMING") 214 CONFIRMING, 215 @SerializedName("PENDING") 216 PENDING, 217 @SerializedName("EFFECTIVE") 218 EFFECTIVE, 219 @SerializedName("USED") 220 USED, 221 @SerializedName("EXPIRED") 222 EXPIRED, 223 @SerializedName("DELETED") 224 DELETED, 225 @SerializedName("DEACTIVATED") 226 DEACTIVATED 227 } 228 229 public enum UserProductCouponSendChannel { 230 @SerializedName("BRAND_MANAGE") 231 BRAND_MANAGE, 232 @SerializedName("API") 233 API, 234 @SerializedName("RECEIVE_COMPONENT") 235 RECEIVE_COMPONENT 236 } 237 238 public static class CouponUsageDetail { 239 @SerializedName("use_request_no") 240 public String useRequestNo; 241 242 @SerializedName("use_time") 243 public String useTime; 244 245 @SerializedName("associated_order_info") 246 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 247 248 @SerializedName("return_request_no") 249 public String returnRequestNo; 250 251 @SerializedName("return_time") 252 public String returnTime; 253 } 254 255 public static class UserProductCouponBundleInfo { 256 @SerializedName("user_coupon_bundle_id") 257 public String userCouponBundleId; 258 259 @SerializedName("user_coupon_bundle_index") 260 public Long userCouponBundleIndex; 261 262 @SerializedName("total_count") 263 public Long totalCount; 264 265 @SerializedName("used_count") 266 public Long usedCount; 267 } 268 269 public static class ProductCouponEntity { 270 @SerializedName("product_coupon_id") 271 public String productCouponId; 272 273 @SerializedName("scope") 274 public ProductCouponScope scope; 275 276 @SerializedName("type") 277 public ProductCouponType type; 278 279 @SerializedName("usage_mode") 280 public UsageMode usageMode; 281 282 @SerializedName("single_usage_info") 283 public SingleUsageInfo singleUsageInfo; 284 285 @SerializedName("progressive_bundle_usage_info") 286 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 287 288 @SerializedName("display_info") 289 public ProductCouponDisplayInfo displayInfo; 290 291 @SerializedName("out_product_no") 292 public String outProductNo; 293 294 @SerializedName("state") 295 public ProductCouponState state; 296 297 @SerializedName("deactivate_request_no") 298 public String deactivateRequestNo; 299 300 @SerializedName("deactivate_time") 301 public String deactivateTime; 302 303 @SerializedName("deactivate_reason") 304 public String deactivateReason; 305 } 306 307 public static class StockEntity { 308 @SerializedName("product_coupon_id") 309 public String productCouponId; 310 311 @SerializedName("stock_id") 312 public String stockId; 313 314 @SerializedName("remark") 315 public String remark; 316 317 @SerializedName("coupon_code_mode") 318 public CouponCodeMode couponCodeMode; 319 320 @SerializedName("coupon_code_count_info") 321 public CouponCodeCountInfo couponCodeCountInfo; 322 323 @SerializedName("stock_send_rule") 324 public StockSendRule stockSendRule; 325 326 @SerializedName("progressive_bundle_usage_rule") 327 public StockUsageRule progressiveBundleUsageRule; 328 329 @SerializedName("stock_bundle_info") 330 public StockBundleInfo stockBundleInfo; 331 332 @SerializedName("usage_rule_display_info") 333 public UsageRuleDisplayInfo usageRuleDisplayInfo; 334 335 @SerializedName("coupon_display_info") 336 public CouponDisplayInfo couponDisplayInfo; 337 338 @SerializedName("notify_config") 339 public NotifyConfig notifyConfig; 340 341 @SerializedName("store_scope") 342 public StockStoreScope storeScope; 343 344 @SerializedName("sent_count_info") 345 public StockSentCountInfo sentCountInfo; 346 347 @SerializedName("state") 348 public StockState state; 349 350 @SerializedName("deactivate_request_no") 351 public String deactivateRequestNo; 352 353 @SerializedName("deactivate_time") 354 public String deactivateTime; 355 356 @SerializedName("deactivate_reason") 357 public String deactivateReason; 358 } 359 360 public static class UserProductCouponAssociatedOrderInfo { 361 @SerializedName("transaction_id") 362 public String transactionId; 363 364 @SerializedName("out_trade_no") 365 public String outTradeNo; 366 367 @SerializedName("mchid") 368 public String mchid; 369 370 @SerializedName("sub_mchid") 371 public String subMchid; 372 } 373 374 public enum ProductCouponScope { 375 @SerializedName("ALL") 376 ALL, 377 @SerializedName("SINGLE") 378 SINGLE 379 } 380 381 public enum ProductCouponType { 382 @SerializedName("NORMAL") 383 NORMAL, 384 @SerializedName("DISCOUNT") 385 DISCOUNT, 386 @SerializedName("EXCHANGE") 387 EXCHANGE 388 } 389 390 public enum UsageMode { 391 @SerializedName("SINGLE") 392 SINGLE, 393 @SerializedName("PROGRESSIVE_BUNDLE") 394 PROGRESSIVE_BUNDLE 395 } 396 397 public static class SingleUsageInfo { 398 @SerializedName("normal_coupon") 399 public NormalCouponUsageRule normalCoupon; 400 401 @SerializedName("discount_coupon") 402 public DiscountCouponUsageRule discountCoupon; 403 } 404 405 public static class ProgressiveBundleUsageInfo { 406 @SerializedName("count") 407 public Long count; 408 409 @SerializedName("interval_days") 410 public Long intervalDays; 411 } 412 413 public static class ProductCouponDisplayInfo { 414 @SerializedName("name") 415 public String name; 416 417 @SerializedName("image_url") 418 public String imageUrl; 419 420 @SerializedName("background_url") 421 public String backgroundUrl; 422 423 @SerializedName("detail_image_url_list") 424 public List<String> detailImageUrlList; 425 426 @SerializedName("original_price") 427 public Long originalPrice; 428 429 @SerializedName("combo_package_list") 430 public List<ComboPackage> comboPackageList; 431 } 432 433 public enum ProductCouponState { 434 @SerializedName("AUDITING") 435 AUDITING, 436 @SerializedName("EFFECTIVE") 437 EFFECTIVE, 438 @SerializedName("DEACTIVATED") 439 DEACTIVATED 440 } 441 442 public enum CouponCodeMode { 443 @SerializedName("WECHATPAY") 444 WECHATPAY, 445 @SerializedName("UPLOAD") 446 UPLOAD 447 } 448 449 public static class CouponCodeCountInfo { 450 @SerializedName("total_count") 451 public Long totalCount; 452 453 @SerializedName("available_count") 454 public Long availableCount; 455 } 456 457 public static class StockSendRule { 458 @SerializedName("max_count") 459 public Long maxCount; 460 461 @SerializedName("max_count_per_day") 462 public Long maxCountPerDay; 463 464 @SerializedName("max_count_per_user") 465 public Long maxCountPerUser; 466 } 467 468 public static class StockUsageRule { 469 @SerializedName("coupon_available_period") 470 public CouponAvailablePeriod couponAvailablePeriod; 471 472 @SerializedName("normal_coupon") 473 public NormalCouponUsageRule normalCoupon; 474 475 @SerializedName("discount_coupon") 476 public DiscountCouponUsageRule discountCoupon; 477 478 @SerializedName("exchange_coupon") 479 public ExchangeCouponUsageRule exchangeCoupon; 480 } 481 482 public static class StockBundleInfo { 483 @SerializedName("stock_bundle_id") 484 public String stockBundleId; 485 486 @SerializedName("stock_bundle_index") 487 public Long stockBundleIndex; 488 } 489 490 public static class UsageRuleDisplayInfo { 491 @SerializedName("coupon_usage_method_list") 492 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 493 494 @SerializedName("mini_program_appid") 495 public String miniProgramAppid; 496 497 @SerializedName("mini_program_path") 498 public String miniProgramPath; 499 500 @SerializedName("app_path") 501 public String appPath; 502 503 @SerializedName("usage_description") 504 public String usageDescription; 505 506 @SerializedName("coupon_available_store_info") 507 public CouponAvailableStoreInfo couponAvailableStoreInfo; 508 } 509 510 public static class CouponDisplayInfo { 511 @SerializedName("code_display_mode") 512 public CouponCodeDisplayMode codeDisplayMode; 513 514 @SerializedName("background_color") 515 public String backgroundColor; 516 517 @SerializedName("entrance_mini_program") 518 public EntranceMiniProgram entranceMiniProgram; 519 520 @SerializedName("entrance_official_account") 521 public EntranceOfficialAccount entranceOfficialAccount; 522 523 @SerializedName("entrance_finder") 524 public EntranceFinder entranceFinder; 525 } 526 527 public static class NotifyConfig { 528 @SerializedName("notify_appid") 529 public String notifyAppid; 530 } 531 532 public enum StockStoreScope { 533 @SerializedName("NONE") 534 NONE, 535 @SerializedName("ALL") 536 ALL, 537 @SerializedName("SPECIFIC") 538 SPECIFIC 539 } 540 541 public static class StockSentCountInfo { 542 @SerializedName("total_count") 543 public Long totalCount; 544 545 @SerializedName("today_count") 546 public Long todayCount; 547 } 548 549 public enum StockState { 550 @SerializedName("AUDITING") 551 AUDITING, 552 @SerializedName("SENDING") 553 SENDING, 554 @SerializedName("PAUSED") 555 PAUSED, 556 @SerializedName("STOPPED") 557 STOPPED, 558 @SerializedName("DEACTIVATED") 559 DEACTIVATED 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_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 := &SendUserProductCouponBundleRequest{ 29 ProductCouponId: wxpay_brand_utility.String("1000000014"), 30 StockBundleId: wxpay_brand_utility.String("712315129419284901"), 31 Appid: wxpay_brand_utility.String("wx233544546545989"), 32 Openid: wxpay_brand_utility.String("oh-394z-6CGkNoJrsDLTTUKiAnp4"), 33 SendRequestNo: wxpay_brand_utility.String("MCHCONFIRM202003101234"), 34 } 35 36 response, err := SendUserProductCouponBundle(config, request) 37 if err != nil { 38 fmt.Printf("请求失败: %+v\n", err) 39 // TODO: 请求失败,根据状态码执行不同的处理 40 return 41 } 42 43 // TODO: 请求成功,继续业务逻辑 44 fmt.Printf("请求成功: %+v\n", response) 45} 46 47func SendUserProductCouponBundle(config *wxpay_brand_utility.BrandConfig, request *SendUserProductCouponBundleRequest) (response *SendUserProductCouponBundleResponse, err error) { 48 const ( 49 host = "https://api.mch.weixin.qq.com" 50 method = "POST" 51 path = "/brand/marketing/product-coupon/users/{openid}/coupon-bundles" 52 ) 53 54 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 55 if err != nil { 56 return nil, err 57 } 58 reqUrl.Path = strings.Replace(reqUrl.Path, "{openid}", url.PathEscape(*request.Openid), -1) 59 reqBody, err := json.Marshal(request) 60 if err != nil { 61 return nil, err 62 } 63 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 64 if err != nil { 65 return nil, err 66 } 67 httpRequest.Header.Set("Accept", "application/json") 68 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 69 httpRequest.Header.Set("Content-Type", "application/json") 70 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 71 if err != nil { 72 return nil, err 73 } 74 httpRequest.Header.Set("Authorization", authorization) 75 76 client := &http.Client{} 77 httpResponse, err := client.Do(httpRequest) 78 if err != nil { 79 return nil, err 80 } 81 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 82 if err != nil { 83 return nil, err 84 } 85 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 86 // 2XX 成功,验证应答签名 87 err = wxpay_brand_utility.ValidateResponse( 88 config.WechatPayPublicKeyId(), 89 config.WechatPayPublicKey(), 90 &httpResponse.Header, 91 respBody, 92 ) 93 if err != nil { 94 return nil, err 95 } 96 response := &SendUserProductCouponBundleResponse{} 97 if err := json.Unmarshal(respBody, response); err != nil { 98 return nil, err 99 } 100 101 return response, nil 102 } else { 103 return nil, wxpay_brand_utility.NewApiException( 104 httpResponse.StatusCode, 105 httpResponse.Header, 106 respBody, 107 ) 108 } 109} 110 111type SendUserProductCouponBundleRequest struct { 112 ProductCouponId *string `json:"product_coupon_id,omitempty"` 113 StockBundleId *string `json:"stock_bundle_id,omitempty"` 114 Appid *string `json:"appid,omitempty"` 115 Openid *string `json:"openid,omitempty"` 116 SendRequestNo *string `json:"send_request_no,omitempty"` 117 Attach *string `json:"attach,omitempty"` 118 CouponTagInfo *CouponTagInfo `json:"coupon_tag_info,omitempty"` 119} 120 121func (o *SendUserProductCouponBundleRequest) MarshalJSON() ([]byte, error) { 122 type Alias SendUserProductCouponBundleRequest 123 a := &struct { 124 Openid *string `json:"openid,omitempty"` 125 *Alias 126 }{ 127 // 序列化时移除非 Body 字段 128 Openid: nil, 129 Alias: (*Alias)(o), 130 } 131 return json.Marshal(a) 132} 133 134type SendUserProductCouponBundleResponse struct { 135 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 136 UserProductCouponList []UserProductCouponEntity `json:"user_product_coupon_list,omitempty"` 137} 138 139type CouponTagInfo struct { 140 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 141 MemberTagInfo *MemberTagInfo `json:"member_tag_info,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 UserProductCouponTag string 167 168func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 169 return &e 170} 171 172const ( 173 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 174) 175 176type MemberTagInfo struct { 177 MemberCardId *string `json:"member_card_id,omitempty"` 178} 179 180type UserProductCouponState string 181 182func (e UserProductCouponState) Ptr() *UserProductCouponState { 183 return &e 184} 185 186const ( 187 USERPRODUCTCOUPONSTATE_CONFIRMING UserProductCouponState = "CONFIRMING" 188 USERPRODUCTCOUPONSTATE_PENDING UserProductCouponState = "PENDING" 189 USERPRODUCTCOUPONSTATE_EFFECTIVE UserProductCouponState = "EFFECTIVE" 190 USERPRODUCTCOUPONSTATE_USED UserProductCouponState = "USED" 191 USERPRODUCTCOUPONSTATE_EXPIRED UserProductCouponState = "EXPIRED" 192 USERPRODUCTCOUPONSTATE_DELETED UserProductCouponState = "DELETED" 193 USERPRODUCTCOUPONSTATE_DEACTIVATED UserProductCouponState = "DEACTIVATED" 194) 195 196type UserProductCouponSendChannel string 197 198func (e UserProductCouponSendChannel) Ptr() *UserProductCouponSendChannel { 199 return &e 200} 201 202const ( 203 USERPRODUCTCOUPONSENDCHANNEL_BRAND_MANAGE UserProductCouponSendChannel = "BRAND_MANAGE" 204 USERPRODUCTCOUPONSENDCHANNEL_API UserProductCouponSendChannel = "API" 205 USERPRODUCTCOUPONSENDCHANNEL_RECEIVE_COMPONENT UserProductCouponSendChannel = "RECEIVE_COMPONENT" 206) 207 208type CouponUsageDetail struct { 209 UseRequestNo *string `json:"use_request_no,omitempty"` 210 UseTime *time.Time `json:"use_time,omitempty"` 211 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 212 ReturnRequestNo *string `json:"return_request_no,omitempty"` 213 ReturnTime *time.Time `json:"return_time,omitempty"` 214} 215 216type UserProductCouponBundleInfo struct { 217 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 218 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 219 TotalCount *int64 `json:"total_count,omitempty"` 220 UsedCount *int64 `json:"used_count,omitempty"` 221} 222 223type ProductCouponEntity struct { 224 ProductCouponId *string `json:"product_coupon_id,omitempty"` 225 Scope *ProductCouponScope `json:"scope,omitempty"` 226 Type *ProductCouponType `json:"type,omitempty"` 227 UsageMode *UsageMode `json:"usage_mode,omitempty"` 228 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 229 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 230 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 231 OutProductNo *string `json:"out_product_no,omitempty"` 232 State *ProductCouponState `json:"state,omitempty"` 233 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 234 DeactivateTime *string `json:"deactivate_time,omitempty"` 235 DeactivateReason *string `json:"deactivate_reason,omitempty"` 236} 237 238type StockEntity struct { 239 ProductCouponId *string `json:"product_coupon_id,omitempty"` 240 StockId *string `json:"stock_id,omitempty"` 241 Remark *string `json:"remark,omitempty"` 242 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 243 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 244 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 245 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 246 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 247 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 248 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 249 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 250 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 251 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 252 State *StockState `json:"state,omitempty"` 253 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 254 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 255 DeactivateReason *string `json:"deactivate_reason,omitempty"` 256} 257 258type UserProductCouponAssociatedOrderInfo struct { 259 TransactionId *string `json:"transaction_id,omitempty"` 260 OutTradeNo *string `json:"out_trade_no,omitempty"` 261 Mchid *string `json:"mchid,omitempty"` 262 SubMchid *string `json:"sub_mchid,omitempty"` 263} 264 265type ProductCouponScope string 266 267func (e ProductCouponScope) Ptr() *ProductCouponScope { 268 return &e 269} 270 271const ( 272 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 273 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 274) 275 276type ProductCouponType string 277 278func (e ProductCouponType) Ptr() *ProductCouponType { 279 return &e 280} 281 282const ( 283 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 284 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 285 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 286) 287 288type UsageMode string 289 290func (e UsageMode) Ptr() *UsageMode { 291 return &e 292} 293 294const ( 295 USAGEMODE_SINGLE UsageMode = "SINGLE" 296 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 297) 298 299type SingleUsageInfo struct { 300 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 301 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 302} 303 304type ProgressiveBundleUsageInfo struct { 305 Count *int64 `json:"count,omitempty"` 306 IntervalDays *int64 `json:"interval_days,omitempty"` 307} 308 309type ProductCouponDisplayInfo struct { 310 Name *string `json:"name,omitempty"` 311 ImageUrl *string `json:"image_url,omitempty"` 312 BackgroundUrl *string `json:"background_url,omitempty"` 313 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 314 OriginalPrice *int64 `json:"original_price,omitempty"` 315 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 316} 317 318type ProductCouponState string 319 320func (e ProductCouponState) Ptr() *ProductCouponState { 321 return &e 322} 323 324const ( 325 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 326 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 327 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 328) 329 330type CouponCodeMode string 331 332func (e CouponCodeMode) Ptr() *CouponCodeMode { 333 return &e 334} 335 336const ( 337 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 338 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 339) 340 341type CouponCodeCountInfo struct { 342 TotalCount *int64 `json:"total_count,omitempty"` 343 AvailableCount *int64 `json:"available_count,omitempty"` 344} 345 346type StockSendRule struct { 347 MaxCount *int64 `json:"max_count,omitempty"` 348 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 349 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 350} 351 352type StockUsageRule struct { 353 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 354 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 355 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 356 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 357} 358 359type StockBundleInfo struct { 360 StockBundleId *string `json:"stock_bundle_id,omitempty"` 361 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 362} 363 364type UsageRuleDisplayInfo struct { 365 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 366 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 367 MiniProgramPath *string `json:"mini_program_path,omitempty"` 368 AppPath *string `json:"app_path,omitempty"` 369 UsageDescription *string `json:"usage_description,omitempty"` 370 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 371} 372 373type CouponDisplayInfo struct { 374 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 375 BackgroundColor *string `json:"background_color,omitempty"` 376 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 377 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 378 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 379} 380 381type NotifyConfig struct { 382 NotifyAppid *string `json:"notify_appid,omitempty"` 383} 384 385type StockStoreScope string 386 387func (e StockStoreScope) Ptr() *StockStoreScope { 388 return &e 389} 390 391const ( 392 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 393 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 394 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 395) 396 397type StockSentCountInfo struct { 398 TotalCount *int64 `json:"total_count,omitempty"` 399 TodayCount *int64 `json:"today_count,omitempty"` 400} 401 402type StockState string 403 404func (e StockState) Ptr() *StockState { 405 return &e 406} 407 408const ( 409 STOCKSTATE_AUDITING StockState = "AUDITING" 410 STOCKSTATE_SENDING StockState = "SENDING" 411 STOCKSTATE_PAUSED StockState = "PAUSED" 412 STOCKSTATE_STOPPED StockState = "STOPPED" 413 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 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
user_coupon_bundle_id 必填 string(40)
【用户券组ID】 用户商品券批次组的唯一标识,由微信支付生成
user_product_coupon_list 必填 array[object]
【用户商品券列表】 用户商品券组内的用户商品券列表,券组内券的顺序保证与批次组内批次的顺序一致
注意:按照 PROGRESSIVE_BUNDLE 模式的规则,初次发放时用户只会收到首张(此时列表中只会有一个元素),后续批次会在根据用户的核销依次发放。
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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" : "7123912547109241212489", 3 "user_product_coupon_list" : [ 4 { 5 "coupon_code" : "10000003", 6 "coupon_state" : "CONFIRMING", 7 "valid_begin_time" : "2025-08-02T00:00:00+08:00", 8 "valid_end_time" : "2025-08-31T23:59:59+08:00", 9 "receive_time" : "2025-08-02T00:00:00+08:00", 10 "send_request_no" : "MCHCONFIRM202003101234", 11 "send_channel" : "API", 12 "progressive_bundle_usage_detail" : { }, 13 "user_product_coupon_bundle_info" : { 14 "user_coupon_bundle_id" : "7123912547109241212489", 15 "user_coupon_bundle_index" : 0, 16 "total_count" : 10, 17 "used_count" : 0 18 }, 19 "product_coupon" : { 20 "product_coupon_id" : "1000000014", 21 "scope" : "ALL", 22 "type" : "DISCOUNT", 23 "usage_mode" : "PROGRESSIVE_BUNDLE", 24 "progressive_bundle_usage_info" : { 25 "count" : 3, 26 "interval_days" : 1 27 }, 28 "display_info" : { 29 "name" : "全场满100立打8折", 30 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 31 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 32 "detail_image_url_list" : [ 33 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 34 ] 35 }, 36 "state" : "EFFECTIVE", 37 "out_product_no" : "Product_1234567890" 38 }, 39 "stock" : { 40 "product_coupon_id" : "1000000014", 41 "stock_id" : "1000000014001", 42 "remark" : "8月工作日有效批次", 43 "coupon_code_mode" : "UPLOAD", 44 "coupon_code_count_info" : { 45 "total_count" : 0, 46 "available_count" : 0 47 }, 48 "stock_send_rule" : { 49 "max_count" : 10000000, 50 "max_count_per_user" : 1 51 }, 52 "progressive_bundle_usage_rule" : { 53 "coupon_available_period" : { 54 "available_begin_time" : "2025-08-01T00:00:00+08:00", 55 "available_end_time" : "2025-08-31T23:59:59+08:00", 56 "available_days" : 30, 57 "weekly_available_period" : { 58 "day_list" : [ 59 "MONDAY", 60 "TUESDAY", 61 "WEDNESDAY", 62 "THURSDAY", 63 "FRIDAY" 64 ] 65 } 66 }, 67 "discount_coupon" : { 68 "threshold" : 10000, 69 "percent_off" : 50 70 } 71 }, 72 "stock_bundle_info" : { 73 "stock_bundle_id" : "712315129419284901", 74 "stock_bundle_index" : 0 75 }, 76 "usage_rule_display_info" : { 77 "coupon_usage_method_list" : [ 78 "OFFLINE", 79 "MINI_PROGRAM", 80 "PAYMENT_CODE" 81 ], 82 "mini_program_appid" : "wx1234567890", 83 "mini_program_path" : "/pages/index/product", 84 "usage_description" : "工作日可用", 85 "coupon_available_store_info" : { 86 "description" : "所有门店可用,可使用小程序查看门店列表", 87 "mini_program_appid" : "wx1234567890", 88 "mini_program_path" : "/pages/index/store-list" 89 } 90 }, 91 "coupon_display_info" : { 92 "code_display_mode" : "QRCODE", 93 "background_color" : "Color010", 94 "entrance_mini_program" : { 95 "appid" : "wx1234567890", 96 "path" : "/pages/index/product", 97 "entrance_wording" : "欢迎选购", 98 "guidance_wording" : "获取更多优惠" 99 }, 100 "entrance_official_account" : { 101 "appid" : "wx1234567890" 102 }, 103 "entrance_finder" : { 104 "finder_id" : "gh_12345678", 105 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 106 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 107 } 108 }, 109 "notify_config" : { 110 "notify_appid" : "wx4fd12345678" 111 }, 112 "store_scope" : "NONE", 113 "sent_count_info" : { 114 "total_count" : 0, 115 "today_count" : 0 116 }, 117 "state" : "SENDING" 118 } 119 } 120 ] 121} 122
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示


