向用户发放商品券批次组
更新时间:2025.11.20服务商可以通过本接口向用户发放指定商品券批次组,能否发放受限于商品券组内批次的发放限额:
商品券批次总预算
商品券批次每日预算(如果有)
商品券批次每人限领(如果有)
前置条件: 已创建商品券批次组,批次组内商品券批次处于 SENDING 状态
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/users/{openid}/coupon-bundles
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
接口限频:500/秒(商户号维度)
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Content-Type 必填 string
请设置为application/json
path 路径参数
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(128)
【发券请求单号】 品牌给用户发券的请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_、短横线- 组成,长度在6-128个字符之间
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("return_request_no") 253 public String returnRequestNo; 254 255 @SerializedName("return_time") 256 public String returnTime; 257 258 @SerializedName("associated_order_info") 259 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 260 261 @SerializedName("associated_pay_score_order_info") 262 public UserProductCouponAssociatedPayScoreOrderInfo associatedPayScoreOrderInfo; 263 264 @SerializedName("saved_amount") 265 public Long savedAmount; 266 } 267 268 public static class UserProductCouponBundleInfo { 269 @SerializedName("user_coupon_bundle_id") 270 public String userCouponBundleId; 271 272 @SerializedName("user_coupon_bundle_index") 273 public Long userCouponBundleIndex; 274 275 @SerializedName("total_count") 276 public Long totalCount; 277 278 @SerializedName("used_count") 279 public Long usedCount; 280 } 281 282 public static class ProductCouponEntity { 283 @SerializedName("product_coupon_id") 284 public String productCouponId; 285 286 @SerializedName("scope") 287 public ProductCouponScope scope; 288 289 @SerializedName("type") 290 public ProductCouponType type; 291 292 @SerializedName("usage_mode") 293 public UsageMode usageMode; 294 295 @SerializedName("single_usage_info") 296 public SingleUsageInfo singleUsageInfo; 297 298 @SerializedName("progressive_bundle_usage_info") 299 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 300 301 @SerializedName("display_info") 302 public ProductCouponDisplayInfo displayInfo; 303 304 @SerializedName("out_product_no") 305 public String outProductNo; 306 307 @SerializedName("state") 308 public ProductCouponState state; 309 310 @SerializedName("deactivate_request_no") 311 public String deactivateRequestNo; 312 313 @SerializedName("deactivate_time") 314 public String deactivateTime; 315 316 @SerializedName("deactivate_reason") 317 public String deactivateReason; 318 319 @SerializedName("brand_id") 320 public String brandId; 321 } 322 323 public static class StockEntity { 324 @SerializedName("product_coupon_id") 325 public String productCouponId; 326 327 @SerializedName("stock_id") 328 public String stockId; 329 330 @SerializedName("remark") 331 public String remark; 332 333 @SerializedName("coupon_code_mode") 334 public CouponCodeMode couponCodeMode; 335 336 @SerializedName("coupon_code_count_info") 337 public CouponCodeCountInfo couponCodeCountInfo; 338 339 @SerializedName("stock_send_rule") 340 public StockSendRule stockSendRule; 341 342 @SerializedName("progressive_bundle_usage_rule") 343 public StockUsageRule progressiveBundleUsageRule; 344 345 @SerializedName("stock_bundle_info") 346 public StockBundleInfo stockBundleInfo; 347 348 @SerializedName("usage_rule_display_info") 349 public UsageRuleDisplayInfo usageRuleDisplayInfo; 350 351 @SerializedName("coupon_display_info") 352 public CouponDisplayInfo couponDisplayInfo; 353 354 @SerializedName("notify_config") 355 public NotifyConfig notifyConfig; 356 357 @SerializedName("store_scope") 358 public StockStoreScope storeScope; 359 360 @SerializedName("sent_count_info") 361 public StockSentCountInfo sentCountInfo; 362 363 @SerializedName("state") 364 public StockState state; 365 366 @SerializedName("deactivate_request_no") 367 public String deactivateRequestNo; 368 369 @SerializedName("deactivate_time") 370 public String deactivateTime; 371 372 @SerializedName("deactivate_reason") 373 public String deactivateReason; 374 375 @SerializedName("brand_id") 376 public String brandId; 377 } 378 379 public static class UserProductCouponAssociatedOrderInfo { 380 @SerializedName("transaction_id") 381 public String transactionId; 382 383 @SerializedName("out_trade_no") 384 public String outTradeNo; 385 386 @SerializedName("mchid") 387 public String mchid; 388 389 @SerializedName("sub_mchid") 390 public String subMchid; 391 } 392 393 public static class UserProductCouponAssociatedPayScoreOrderInfo { 394 @SerializedName("order_id") 395 public String orderId; 396 397 @SerializedName("out_order_no") 398 public String outOrderNo; 399 400 @SerializedName("mchid") 401 public String mchid; 402 403 @SerializedName("sub_mchid") 404 public String subMchid; 405 } 406 407 public enum ProductCouponScope { 408 @SerializedName("ALL") 409 ALL, 410 @SerializedName("SINGLE") 411 SINGLE 412 } 413 414 public enum ProductCouponType { 415 @SerializedName("NORMAL") 416 NORMAL, 417 @SerializedName("DISCOUNT") 418 DISCOUNT, 419 @SerializedName("EXCHANGE") 420 EXCHANGE 421 } 422 423 public enum UsageMode { 424 @SerializedName("SINGLE") 425 SINGLE, 426 @SerializedName("PROGRESSIVE_BUNDLE") 427 PROGRESSIVE_BUNDLE 428 } 429 430 public static class SingleUsageInfo { 431 @SerializedName("normal_coupon") 432 public NormalCouponUsageRule normalCoupon; 433 434 @SerializedName("discount_coupon") 435 public DiscountCouponUsageRule discountCoupon; 436 } 437 438 public static class ProgressiveBundleUsageInfo { 439 @SerializedName("count") 440 public Long count; 441 442 @SerializedName("interval_days") 443 public Long intervalDays; 444 } 445 446 public static class ProductCouponDisplayInfo { 447 @SerializedName("name") 448 public String name; 449 450 @SerializedName("image_url") 451 public String imageUrl; 452 453 @SerializedName("background_url") 454 public String backgroundUrl; 455 456 @SerializedName("detail_image_url_list") 457 public List<String> detailImageUrlList; 458 459 @SerializedName("original_price") 460 public Long originalPrice; 461 462 @SerializedName("combo_package_list") 463 public List<ComboPackage> comboPackageList; 464 } 465 466 public enum ProductCouponState { 467 @SerializedName("AUDITING") 468 AUDITING, 469 @SerializedName("EFFECTIVE") 470 EFFECTIVE, 471 @SerializedName("DEACTIVATED") 472 DEACTIVATED 473 } 474 475 public enum CouponCodeMode { 476 @SerializedName("WECHATPAY") 477 WECHATPAY, 478 @SerializedName("UPLOAD") 479 UPLOAD 480 } 481 482 public static class CouponCodeCountInfo { 483 @SerializedName("total_count") 484 public Long totalCount; 485 486 @SerializedName("available_count") 487 public Long availableCount; 488 } 489 490 public static class StockSendRule { 491 @SerializedName("max_count") 492 public Long maxCount; 493 494 @SerializedName("max_count_per_day") 495 public Long maxCountPerDay; 496 497 @SerializedName("max_count_per_user") 498 public Long maxCountPerUser; 499 } 500 501 public static class StockUsageRule { 502 @SerializedName("coupon_available_period") 503 public CouponAvailablePeriod couponAvailablePeriod; 504 505 @SerializedName("normal_coupon") 506 public NormalCouponUsageRule normalCoupon; 507 508 @SerializedName("discount_coupon") 509 public DiscountCouponUsageRule discountCoupon; 510 511 @SerializedName("exchange_coupon") 512 public ExchangeCouponUsageRule exchangeCoupon; 513 } 514 515 public static class StockBundleInfo { 516 @SerializedName("stock_bundle_id") 517 public String stockBundleId; 518 519 @SerializedName("stock_bundle_index") 520 public Long stockBundleIndex; 521 } 522 523 public static class UsageRuleDisplayInfo { 524 @SerializedName("coupon_usage_method_list") 525 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 526 527 @SerializedName("mini_program_appid") 528 public String miniProgramAppid; 529 530 @SerializedName("mini_program_path") 531 public String miniProgramPath; 532 533 @SerializedName("app_path") 534 public String appPath; 535 536 @SerializedName("usage_description") 537 public String usageDescription; 538 539 @SerializedName("coupon_available_store_info") 540 public CouponAvailableStoreInfo couponAvailableStoreInfo; 541 } 542 543 public static class CouponDisplayInfo { 544 @SerializedName("code_display_mode") 545 public CouponCodeDisplayMode codeDisplayMode; 546 547 @SerializedName("background_color") 548 public String backgroundColor; 549 550 @SerializedName("entrance_mini_program") 551 public EntranceMiniProgram entranceMiniProgram; 552 553 @SerializedName("entrance_official_account") 554 public EntranceOfficialAccount entranceOfficialAccount; 555 556 @SerializedName("entrance_finder") 557 public EntranceFinder entranceFinder; 558 } 559 560 public static class NotifyConfig { 561 @SerializedName("notify_appid") 562 public String notifyAppid; 563 } 564 565 public enum StockStoreScope { 566 @SerializedName("NONE") 567 NONE, 568 @SerializedName("ALL") 569 ALL, 570 @SerializedName("SPECIFIC") 571 SPECIFIC 572 } 573 574 public static class StockSentCountInfo { 575 @SerializedName("total_count") 576 public Long totalCount; 577 578 @SerializedName("today_count") 579 public Long todayCount; 580 } 581 582 public enum StockState { 583 @SerializedName("AUDITING") 584 AUDITING, 585 @SerializedName("SENDING") 586 SENDING, 587 @SerializedName("PAUSED") 588 PAUSED, 589 @SerializedName("STOPPED") 590 STOPPED, 591 @SerializedName("DEACTIVATED") 592 DEACTIVATED 593 } 594 595 public static class NormalCouponUsageRule { 596 @SerializedName("threshold") 597 public Long threshold; 598 599 @SerializedName("discount_amount") 600 public Long discountAmount; 601 } 602 603 public static class DiscountCouponUsageRule { 604 @SerializedName("threshold") 605 public Long threshold; 606 607 @SerializedName("percent_off") 608 public Long percentOff; 609 } 610 611 public static class ComboPackage { 612 @SerializedName("name") 613 public String name; 614 615 @SerializedName("pick_count") 616 public Long pickCount; 617 618 @SerializedName("choice_list") 619 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 620 } 621 622 public static class CouponAvailablePeriod { 623 @SerializedName("available_begin_time") 624 public String availableBeginTime; 625 626 @SerializedName("available_end_time") 627 public String availableEndTime; 628 629 @SerializedName("available_days") 630 public Long availableDays; 631 632 @SerializedName("wait_days_after_receive") 633 public Long waitDaysAfterReceive; 634 635 @SerializedName("weekly_available_period") 636 public FixedWeekPeriod weeklyAvailablePeriod; 637 638 @SerializedName("irregular_available_period_list") 639 public List<TimePeriod> irregularAvailablePeriodList; 640 } 641 642 public static class ExchangeCouponUsageRule { 643 @SerializedName("threshold") 644 public Long threshold; 645 646 @SerializedName("exchange_price") 647 public Long exchangePrice; 648 } 649 650 public enum CouponUsageMethod { 651 @SerializedName("OFFLINE") 652 OFFLINE, 653 @SerializedName("MINI_PROGRAM") 654 MINI_PROGRAM, 655 @SerializedName("APP") 656 APP, 657 @SerializedName("PAYMENT_CODE") 658 PAYMENT_CODE 659 } 660 661 public static class CouponAvailableStoreInfo { 662 @SerializedName("description") 663 public String description; 664 665 @SerializedName("mini_program_appid") 666 public String miniProgramAppid; 667 668 @SerializedName("mini_program_path") 669 public String miniProgramPath; 670 } 671 672 public enum CouponCodeDisplayMode { 673 @SerializedName("INVISIBLE") 674 INVISIBLE, 675 @SerializedName("BARCODE") 676 BARCODE, 677 @SerializedName("QRCODE") 678 QRCODE 679 } 680 681 public static class EntranceMiniProgram { 682 @SerializedName("appid") 683 public String appid; 684 685 @SerializedName("path") 686 public String path; 687 688 @SerializedName("entrance_wording") 689 public String entranceWording; 690 691 @SerializedName("guidance_wording") 692 public String guidanceWording; 693 } 694 695 public static class EntranceOfficialAccount { 696 @SerializedName("appid") 697 public String appid; 698 } 699 700 public static class EntranceFinder { 701 @SerializedName("finder_id") 702 public String finderId; 703 704 @SerializedName("finder_video_id") 705 public String finderVideoId; 706 707 @SerializedName("finder_video_cover_image_url") 708 public String finderVideoCoverImageUrl; 709 } 710 711 public static class ComboPackageChoice { 712 @SerializedName("name") 713 public String name; 714 715 @SerializedName("price") 716 public Long price; 717 718 @SerializedName("count") 719 public Long count; 720 721 @SerializedName("image_url") 722 public String imageUrl; 723 724 @SerializedName("mini_program_appid") 725 public String miniProgramAppid; 726 727 @SerializedName("mini_program_path") 728 public String miniProgramPath; 729 } 730 731 public static class FixedWeekPeriod { 732 @SerializedName("day_list") 733 public List<WeekEnum> dayList = new ArrayList<WeekEnum>(); 734 735 @SerializedName("day_period_list") 736 public List<PeriodOfTheDay> dayPeriodList; 737 } 738 739 public static class TimePeriod { 740 @SerializedName("begin_time") 741 public String beginTime; 742 743 @SerializedName("end_time") 744 public String endTime; 745 } 746 747 public enum WeekEnum { 748 @SerializedName("MONDAY") 749 MONDAY, 750 @SerializedName("TUESDAY") 751 TUESDAY, 752 @SerializedName("WEDNESDAY") 753 WEDNESDAY, 754 @SerializedName("THURSDAY") 755 THURSDAY, 756 @SerializedName("FRIDAY") 757 FRIDAY, 758 @SerializedName("SATURDAY") 759 SATURDAY, 760 @SerializedName("SUNDAY") 761 SUNDAY 762 } 763 764 public static class PeriodOfTheDay { 765 @SerializedName("begin_time") 766 public Long beginTime; 767 768 @SerializedName("end_time") 769 public Long endTime; 770 } 771 772} 773
需配合微信支付工具库 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 ReturnRequestNo *string `json:"return_request_no,omitempty"` 215 ReturnTime *time.Time `json:"return_time,omitempty"` 216 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 217 AssociatedPayScoreOrderInfo *UserProductCouponAssociatedPayScoreOrderInfo `json:"associated_pay_score_order_info,omitempty"` 218 SavedAmount *int64 `json:"saved_amount,omitempty"` 219} 220 221type UserProductCouponBundleInfo struct { 222 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 223 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 224 TotalCount *int64 `json:"total_count,omitempty"` 225 UsedCount *int64 `json:"used_count,omitempty"` 226} 227 228type ProductCouponEntity struct { 229 ProductCouponId *string `json:"product_coupon_id,omitempty"` 230 Scope *ProductCouponScope `json:"scope,omitempty"` 231 Type *ProductCouponType `json:"type,omitempty"` 232 UsageMode *UsageMode `json:"usage_mode,omitempty"` 233 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 234 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 235 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 236 OutProductNo *string `json:"out_product_no,omitempty"` 237 State *ProductCouponState `json:"state,omitempty"` 238 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 239 DeactivateTime *string `json:"deactivate_time,omitempty"` 240 DeactivateReason *string `json:"deactivate_reason,omitempty"` 241 BrandId *string `json:"brand_id,omitempty"` 242} 243 244type StockEntity struct { 245 ProductCouponId *string `json:"product_coupon_id,omitempty"` 246 StockId *string `json:"stock_id,omitempty"` 247 Remark *string `json:"remark,omitempty"` 248 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 249 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 250 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 251 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 252 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 253 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 254 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 255 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 256 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 257 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 258 State *StockState `json:"state,omitempty"` 259 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 260 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 261 DeactivateReason *string `json:"deactivate_reason,omitempty"` 262 BrandId *string `json:"brand_id,omitempty"` 263} 264 265type UserProductCouponAssociatedOrderInfo struct { 266 TransactionId *string `json:"transaction_id,omitempty"` 267 OutTradeNo *string `json:"out_trade_no,omitempty"` 268 Mchid *string `json:"mchid,omitempty"` 269 SubMchid *string `json:"sub_mchid,omitempty"` 270} 271 272type UserProductCouponAssociatedPayScoreOrderInfo struct { 273 OrderId *string `json:"order_id,omitempty"` 274 OutOrderNo *string `json:"out_order_no,omitempty"` 275 Mchid *string `json:"mchid,omitempty"` 276 SubMchid *string `json:"sub_mchid,omitempty"` 277} 278 279type ProductCouponScope string 280 281func (e ProductCouponScope) Ptr() *ProductCouponScope { 282 return &e 283} 284 285const ( 286 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 287 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 288) 289 290type ProductCouponType string 291 292func (e ProductCouponType) Ptr() *ProductCouponType { 293 return &e 294} 295 296const ( 297 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 298 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 299 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 300) 301 302type UsageMode string 303 304func (e UsageMode) Ptr() *UsageMode { 305 return &e 306} 307 308const ( 309 USAGEMODE_SINGLE UsageMode = "SINGLE" 310 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 311) 312 313type SingleUsageInfo struct { 314 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 315 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 316} 317 318type ProgressiveBundleUsageInfo struct { 319 Count *int64 `json:"count,omitempty"` 320 IntervalDays *int64 `json:"interval_days,omitempty"` 321} 322 323type ProductCouponDisplayInfo struct { 324 Name *string `json:"name,omitempty"` 325 ImageUrl *string `json:"image_url,omitempty"` 326 BackgroundUrl *string `json:"background_url,omitempty"` 327 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 328 OriginalPrice *int64 `json:"original_price,omitempty"` 329 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 330} 331 332type ProductCouponState string 333 334func (e ProductCouponState) Ptr() *ProductCouponState { 335 return &e 336} 337 338const ( 339 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 340 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 341 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 342) 343 344type CouponCodeMode string 345 346func (e CouponCodeMode) Ptr() *CouponCodeMode { 347 return &e 348} 349 350const ( 351 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 352 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 353) 354 355type CouponCodeCountInfo struct { 356 TotalCount *int64 `json:"total_count,omitempty"` 357 AvailableCount *int64 `json:"available_count,omitempty"` 358} 359 360type StockSendRule struct { 361 MaxCount *int64 `json:"max_count,omitempty"` 362 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 363 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 364} 365 366type StockUsageRule struct { 367 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 368 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 369 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 370 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 371} 372 373type StockBundleInfo struct { 374 StockBundleId *string `json:"stock_bundle_id,omitempty"` 375 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 376} 377 378type UsageRuleDisplayInfo struct { 379 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 380 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 381 MiniProgramPath *string `json:"mini_program_path,omitempty"` 382 AppPath *string `json:"app_path,omitempty"` 383 UsageDescription *string `json:"usage_description,omitempty"` 384 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 385} 386 387type CouponDisplayInfo struct { 388 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 389 BackgroundColor *string `json:"background_color,omitempty"` 390 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 391 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 392 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 393} 394 395type NotifyConfig struct { 396 NotifyAppid *string `json:"notify_appid,omitempty"` 397} 398 399type StockStoreScope string 400 401func (e StockStoreScope) Ptr() *StockStoreScope { 402 return &e 403} 404 405const ( 406 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 407 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 408 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 409) 410 411type StockSentCountInfo struct { 412 TotalCount *int64 `json:"total_count,omitempty"` 413 TodayCount *int64 `json:"today_count,omitempty"` 414} 415 416type StockState string 417 418func (e StockState) Ptr() *StockState { 419 return &e 420} 421 422const ( 423 STOCKSTATE_AUDITING StockState = "AUDITING" 424 STOCKSTATE_SENDING StockState = "SENDING" 425 STOCKSTATE_PAUSED StockState = "PAUSED" 426 STOCKSTATE_STOPPED StockState = "STOPPED" 427 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 428) 429 430type NormalCouponUsageRule struct { 431 Threshold *int64 `json:"threshold,omitempty"` 432 DiscountAmount *int64 `json:"discount_amount,omitempty"` 433} 434 435type DiscountCouponUsageRule struct { 436 Threshold *int64 `json:"threshold,omitempty"` 437 PercentOff *int64 `json:"percent_off,omitempty"` 438} 439 440type ComboPackage struct { 441 Name *string `json:"name,omitempty"` 442 PickCount *int64 `json:"pick_count,omitempty"` 443 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 444} 445 446type CouponAvailablePeriod struct { 447 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 448 AvailableEndTime *string `json:"available_end_time,omitempty"` 449 AvailableDays *int64 `json:"available_days,omitempty"` 450 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 451 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 452 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 453} 454 455type ExchangeCouponUsageRule struct { 456 Threshold *int64 `json:"threshold,omitempty"` 457 ExchangePrice *int64 `json:"exchange_price,omitempty"` 458} 459 460type CouponUsageMethod string 461 462func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 463 return &e 464} 465 466const ( 467 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 468 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 469 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 470 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 471) 472 473type CouponAvailableStoreInfo struct { 474 Description *string `json:"description,omitempty"` 475 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 476 MiniProgramPath *string `json:"mini_program_path,omitempty"` 477} 478 479type CouponCodeDisplayMode string 480 481func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 482 return &e 483} 484 485const ( 486 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 487 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 488 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 489) 490 491type EntranceMiniProgram struct { 492 Appid *string `json:"appid,omitempty"` 493 Path *string `json:"path,omitempty"` 494 EntranceWording *string `json:"entrance_wording,omitempty"` 495 GuidanceWording *string `json:"guidance_wording,omitempty"` 496} 497 498type EntranceOfficialAccount struct { 499 Appid *string `json:"appid,omitempty"` 500} 501 502type EntranceFinder struct { 503 FinderId *string `json:"finder_id,omitempty"` 504 FinderVideoId *string `json:"finder_video_id,omitempty"` 505 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 506} 507 508type ComboPackageChoice struct { 509 Name *string `json:"name,omitempty"` 510 Price *int64 `json:"price,omitempty"` 511 Count *int64 `json:"count,omitempty"` 512 ImageUrl *string `json:"image_url,omitempty"` 513 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 514 MiniProgramPath *string `json:"mini_program_path,omitempty"` 515} 516 517type FixedWeekPeriod struct { 518 DayList []WeekEnum `json:"day_list,omitempty"` 519 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 520} 521 522type TimePeriod struct { 523 BeginTime *string `json:"begin_time,omitempty"` 524 EndTime *string `json:"end_time,omitempty"` 525} 526 527type WeekEnum string 528 529func (e WeekEnum) Ptr() *WeekEnum { 530 return &e 531} 532 533const ( 534 WEEKENUM_MONDAY WeekEnum = "MONDAY" 535 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 536 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 537 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 538 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 539 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 540 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 541) 542 543type PeriodOfTheDay struct { 544 BeginTime *int64 `json:"begin_time,omitempty"` 545 EndTime *int64 `json:"end_time,omitempty"` 546} 547
应答参数
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 【用户商品券标签信息】 用户商品券标签信息
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 | 请求超过接口频率限制 | 请稍后使用原参数重试 |


