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

