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

