确认发放用户商品券
更新时间:2025.11.07给用户发券后,微信支付会给服务商发送【商品券回调通知】,此时服务商应调用本接口确认发放成功。
注:商品券有多个发券渠道,可以由微信支付提供的营销渠道发券,服务商也可以调用【向用户发放商品券API】主动发券,不论由何渠道发放,微信支付均会发送该通知给服务商,服务商均需调用本接口确认发放成功。
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/users/{openid}/coupons/{coupon_code}/confirm
请求域名:【主域名】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 路径参数
coupon_code 必填 string(40)
【用户商品券Code】 用户商品券的唯一标识
openid 必填 string
【用户OpenID】 OpenID信息,用户在AppID下的唯一标识,获取方式参考OpenID
body 包体参数
product_coupon_id 必填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成
stock_id 必填 string
【批次ID】 商品券批次的唯一标识,商品券批次创建时由微信支付生成(可使用【创建商品券API】或【添加商品券批次API】创建),请确保该批次属于 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("single_usage_detail") 169 public CouponUsageDetail singleUsageDetail; 170 171 @SerializedName("progressive_bundle_usage_detail") 172 public CouponUsageDetail progressiveBundleUsageDetail; 173 174 @SerializedName("user_product_coupon_bundle_info") 175 public UserProductCouponBundleInfo userProductCouponBundleInfo; 176 177 @SerializedName("product_coupon") 178 public ProductCouponEntity productCoupon; 179 180 @SerializedName("stock") 181 public StockEntity stock; 182 183 @SerializedName("attach") 184 public String attach; 185 186 @SerializedName("channel_custom_info") 187 public String channelCustomInfo; 188 189 @SerializedName("coupon_tag_info") 190 public CouponTagInfo couponTagInfo; 191 192 @SerializedName("brand_id") 193 public String brandId; 194 } 195 196 public enum UserProductCouponState { 197 @SerializedName("CONFIRMING") 198 CONFIRMING, 199 @SerializedName("PENDING") 200 PENDING, 201 @SerializedName("EFFECTIVE") 202 EFFECTIVE, 203 @SerializedName("USED") 204 USED, 205 @SerializedName("EXPIRED") 206 EXPIRED, 207 @SerializedName("DELETED") 208 DELETED, 209 @SerializedName("DEACTIVATED") 210 DEACTIVATED 211 } 212 213 public enum UserProductCouponSendChannel { 214 @SerializedName("BRAND_MANAGE") 215 BRAND_MANAGE, 216 @SerializedName("API") 217 API, 218 @SerializedName("RECEIVE_COMPONENT") 219 RECEIVE_COMPONENT 220 } 221 222 public static class CouponUsageDetail { 223 @SerializedName("use_request_no") 224 public String useRequestNo; 225 226 @SerializedName("use_time") 227 public String useTime; 228 229 @SerializedName("return_request_no") 230 public String returnRequestNo; 231 232 @SerializedName("return_time") 233 public String returnTime; 234 235 @SerializedName("associated_order_info") 236 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 237 238 @SerializedName("associated_pay_score_order_info") 239 public UserProductCouponAssociatedPayScoreOrderInfo associatedPayScoreOrderInfo; 240 241 @SerializedName("saved_amount") 242 public Long savedAmount; 243 } 244 245 public static class UserProductCouponBundleInfo { 246 @SerializedName("user_coupon_bundle_id") 247 public String userCouponBundleId; 248 249 @SerializedName("user_coupon_bundle_index") 250 public Long userCouponBundleIndex; 251 252 @SerializedName("total_count") 253 public Long totalCount; 254 255 @SerializedName("used_count") 256 public Long usedCount; 257 } 258 259 public static class ProductCouponEntity { 260 @SerializedName("product_coupon_id") 261 public String productCouponId; 262 263 @SerializedName("scope") 264 public ProductCouponScope scope; 265 266 @SerializedName("type") 267 public ProductCouponType type; 268 269 @SerializedName("usage_mode") 270 public UsageMode usageMode; 271 272 @SerializedName("single_usage_info") 273 public SingleUsageInfo singleUsageInfo; 274 275 @SerializedName("progressive_bundle_usage_info") 276 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 277 278 @SerializedName("display_info") 279 public ProductCouponDisplayInfo displayInfo; 280 281 @SerializedName("out_product_no") 282 public String outProductNo; 283 284 @SerializedName("state") 285 public ProductCouponState state; 286 287 @SerializedName("deactivate_request_no") 288 public String deactivateRequestNo; 289 290 @SerializedName("deactivate_time") 291 public String deactivateTime; 292 293 @SerializedName("deactivate_reason") 294 public String deactivateReason; 295 296 @SerializedName("brand_id") 297 public String brandId; 298 } 299 300 public static class StockEntity { 301 @SerializedName("product_coupon_id") 302 public String productCouponId; 303 304 @SerializedName("stock_id") 305 public String stockId; 306 307 @SerializedName("remark") 308 public String remark; 309 310 @SerializedName("coupon_code_mode") 311 public CouponCodeMode couponCodeMode; 312 313 @SerializedName("coupon_code_count_info") 314 public CouponCodeCountInfo couponCodeCountInfo; 315 316 @SerializedName("stock_send_rule") 317 public StockSendRule stockSendRule; 318 319 @SerializedName("single_usage_rule") 320 public SingleUsageRule singleUsageRule; 321 322 @SerializedName("progressive_bundle_usage_rule") 323 public StockUsageRule progressiveBundleUsageRule; 324 325 @SerializedName("stock_bundle_info") 326 public StockBundleInfo stockBundleInfo; 327 328 @SerializedName("usage_rule_display_info") 329 public UsageRuleDisplayInfo usageRuleDisplayInfo; 330 331 @SerializedName("coupon_display_info") 332 public CouponDisplayInfo couponDisplayInfo; 333 334 @SerializedName("notify_config") 335 public NotifyConfig notifyConfig; 336 337 @SerializedName("store_scope") 338 public StockStoreScope storeScope; 339 340 @SerializedName("sent_count_info") 341 public StockSentCountInfo sentCountInfo; 342 343 @SerializedName("state") 344 public StockState state; 345 346 @SerializedName("deactivate_request_no") 347 public String deactivateRequestNo; 348 349 @SerializedName("deactivate_time") 350 public String deactivateTime; 351 352 @SerializedName("deactivate_reason") 353 public String deactivateReason; 354 355 @SerializedName("brand_id") 356 public String brandId; 357 } 358 359 public static class CouponTagInfo { 360 @SerializedName("coupon_tag_list") 361 public List<UserProductCouponTag> couponTagList; 362 363 @SerializedName("member_tag_info") 364 public MemberTagInfo memberTagInfo; 365 } 366 367 public static class UserProductCouponAssociatedOrderInfo { 368 @SerializedName("transaction_id") 369 public String transactionId; 370 371 @SerializedName("out_trade_no") 372 public String outTradeNo; 373 374 @SerializedName("mchid") 375 public String mchid; 376 377 @SerializedName("sub_mchid") 378 public String subMchid; 379 } 380 381 public static class UserProductCouponAssociatedPayScoreOrderInfo { 382 @SerializedName("order_id") 383 public String orderId; 384 385 @SerializedName("out_order_no") 386 public String outOrderNo; 387 388 @SerializedName("mchid") 389 public String mchid; 390 391 @SerializedName("sub_mchid") 392 public String subMchid; 393 } 394 395 public enum ProductCouponScope { 396 @SerializedName("ALL") 397 ALL, 398 @SerializedName("SINGLE") 399 SINGLE 400 } 401 402 public enum ProductCouponType { 403 @SerializedName("NORMAL") 404 NORMAL, 405 @SerializedName("DISCOUNT") 406 DISCOUNT, 407 @SerializedName("EXCHANGE") 408 EXCHANGE 409 } 410 411 public enum UsageMode { 412 @SerializedName("SINGLE") 413 SINGLE, 414 @SerializedName("PROGRESSIVE_BUNDLE") 415 PROGRESSIVE_BUNDLE 416 } 417 418 public static class SingleUsageInfo { 419 @SerializedName("normal_coupon") 420 public NormalCouponUsageRule normalCoupon; 421 422 @SerializedName("discount_coupon") 423 public DiscountCouponUsageRule discountCoupon; 424 } 425 426 public static class ProgressiveBundleUsageInfo { 427 @SerializedName("count") 428 public Long count; 429 430 @SerializedName("interval_days") 431 public Long intervalDays; 432 } 433 434 public static class ProductCouponDisplayInfo { 435 @SerializedName("name") 436 public String name; 437 438 @SerializedName("image_url") 439 public String imageUrl; 440 441 @SerializedName("background_url") 442 public String backgroundUrl; 443 444 @SerializedName("detail_image_url_list") 445 public List<String> detailImageUrlList; 446 447 @SerializedName("original_price") 448 public Long originalPrice; 449 450 @SerializedName("combo_package_list") 451 public List<ComboPackage> comboPackageList; 452 } 453 454 public enum ProductCouponState { 455 @SerializedName("AUDITING") 456 AUDITING, 457 @SerializedName("EFFECTIVE") 458 EFFECTIVE, 459 @SerializedName("DEACTIVATED") 460 DEACTIVATED 461 } 462 463 public enum CouponCodeMode { 464 @SerializedName("WECHATPAY") 465 WECHATPAY, 466 @SerializedName("UPLOAD") 467 UPLOAD, 468 @SerializedName("API_ASSIGN") 469 API_ASSIGN 470 } 471 472 public static class CouponCodeCountInfo { 473 @SerializedName("total_count") 474 public Long totalCount; 475 476 @SerializedName("available_count") 477 public Long availableCount; 478 } 479 480 public static class StockSendRule { 481 @SerializedName("max_count") 482 public Long maxCount; 483 484 @SerializedName("max_count_per_day") 485 public Long maxCountPerDay; 486 487 @SerializedName("max_count_per_user") 488 public Long maxCountPerUser; 489 } 490 491 public static class SingleUsageRule { 492 @SerializedName("coupon_available_period") 493 public CouponAvailablePeriod couponAvailablePeriod; 494 495 @SerializedName("normal_coupon") 496 public NormalCouponUsageRule normalCoupon; 497 498 @SerializedName("discount_coupon") 499 public DiscountCouponUsageRule discountCoupon; 500 501 @SerializedName("exchange_coupon") 502 public ExchangeCouponUsageRule exchangeCoupon; 503 } 504 505 public static class StockUsageRule { 506 @SerializedName("coupon_available_period") 507 public CouponAvailablePeriod couponAvailablePeriod; 508 509 @SerializedName("normal_coupon") 510 public NormalCouponUsageRule normalCoupon; 511 512 @SerializedName("discount_coupon") 513 public DiscountCouponUsageRule discountCoupon; 514 515 @SerializedName("exchange_coupon") 516 public ExchangeCouponUsageRule exchangeCoupon; 517 } 518 519 public static class StockBundleInfo { 520 @SerializedName("stock_bundle_id") 521 public String stockBundleId; 522 523 @SerializedName("stock_bundle_index") 524 public Long stockBundleIndex; 525 } 526 527 public static class UsageRuleDisplayInfo { 528 @SerializedName("coupon_usage_method_list") 529 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 530 531 @SerializedName("mini_program_appid") 532 public String miniProgramAppid; 533 534 @SerializedName("mini_program_path") 535 public String miniProgramPath; 536 537 @SerializedName("app_path") 538 public String appPath; 539 540 @SerializedName("usage_description") 541 public String usageDescription; 542 543 @SerializedName("coupon_available_store_info") 544 public CouponAvailableStoreInfo couponAvailableStoreInfo; 545 } 546 547 public static class CouponDisplayInfo { 548 @SerializedName("code_display_mode") 549 public CouponCodeDisplayMode codeDisplayMode; 550 551 @SerializedName("background_color") 552 public String backgroundColor; 553 554 @SerializedName("entrance_mini_program") 555 public EntranceMiniProgram entranceMiniProgram; 556 557 @SerializedName("entrance_official_account") 558 public EntranceOfficialAccount entranceOfficialAccount; 559 560 @SerializedName("entrance_finder") 561 public EntranceFinder entranceFinder; 562 } 563 564 public static class NotifyConfig { 565 @SerializedName("notify_appid") 566 public String notifyAppid; 567 } 568 569 public enum StockStoreScope { 570 @SerializedName("NONE") 571 NONE, 572 @SerializedName("ALL") 573 ALL, 574 @SerializedName("SPECIFIC") 575 SPECIFIC 576 } 577 578 public static class StockSentCountInfo { 579 @SerializedName("total_count") 580 public Long totalCount; 581 582 @SerializedName("today_count") 583 public Long todayCount; 584 } 585 586 public enum StockState { 587 @SerializedName("AUDITING") 588 AUDITING, 589 @SerializedName("SENDING") 590 SENDING, 591 @SerializedName("PAUSED") 592 PAUSED, 593 @SerializedName("STOPPED") 594 STOPPED, 595 @SerializedName("DEACTIVATED") 596 DEACTIVATED 597 } 598 599 public enum UserProductCouponTag { 600 @SerializedName("MEMBER") 601 MEMBER 602 } 603 604 public static class MemberTagInfo { 605 @SerializedName("member_card_id") 606 public String memberCardId; 607 } 608 609 public static class NormalCouponUsageRule { 610 @SerializedName("threshold") 611 public Long threshold; 612 613 @SerializedName("discount_amount") 614 public Long discountAmount; 615 } 616 617 public static class DiscountCouponUsageRule { 618 @SerializedName("threshold") 619 public Long threshold; 620 621 @SerializedName("percent_off") 622 public Long percentOff; 623 } 624 625 public static class ComboPackage { 626 @SerializedName("name") 627 public String name; 628 629 @SerializedName("pick_count") 630 public Long pickCount; 631 632 @SerializedName("choice_list") 633 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 634 } 635 636 public static class CouponAvailablePeriod { 637 @SerializedName("available_begin_time") 638 public String availableBeginTime; 639 640 @SerializedName("available_end_time") 641 public String availableEndTime; 642 643 @SerializedName("available_days") 644 public Long availableDays; 645 646 @SerializedName("wait_days_after_receive") 647 public Long waitDaysAfterReceive; 648 649 @SerializedName("weekly_available_period") 650 public FixedWeekPeriod weeklyAvailablePeriod; 651 652 @SerializedName("irregular_available_period_list") 653 public List<TimePeriod> irregularAvailablePeriodList; 654 } 655 656 public static class ExchangeCouponUsageRule { 657 @SerializedName("threshold") 658 public Long threshold; 659 660 @SerializedName("exchange_price") 661 public Long exchangePrice; 662 } 663 664 public enum CouponUsageMethod { 665 @SerializedName("OFFLINE") 666 OFFLINE, 667 @SerializedName("MINI_PROGRAM") 668 MINI_PROGRAM, 669 @SerializedName("APP") 670 APP, 671 @SerializedName("PAYMENT_CODE") 672 PAYMENT_CODE 673 } 674 675 public static class CouponAvailableStoreInfo { 676 @SerializedName("description") 677 public String description; 678 679 @SerializedName("mini_program_appid") 680 public String miniProgramAppid; 681 682 @SerializedName("mini_program_path") 683 public String miniProgramPath; 684 } 685 686 public enum CouponCodeDisplayMode { 687 @SerializedName("INVISIBLE") 688 INVISIBLE, 689 @SerializedName("BARCODE") 690 BARCODE, 691 @SerializedName("QRCODE") 692 QRCODE 693 } 694 695 public static class EntranceMiniProgram { 696 @SerializedName("appid") 697 public String appid; 698 699 @SerializedName("path") 700 public String path; 701 702 @SerializedName("entrance_wording") 703 public String entranceWording; 704 705 @SerializedName("guidance_wording") 706 public String guidanceWording; 707 } 708 709 public static class EntranceOfficialAccount { 710 @SerializedName("appid") 711 public String appid; 712 } 713 714 public static class EntranceFinder { 715 @SerializedName("finder_id") 716 public String finderId; 717 718 @SerializedName("finder_video_id") 719 public String finderVideoId; 720 721 @SerializedName("finder_video_cover_image_url") 722 public String finderVideoCoverImageUrl; 723 } 724 725 public static class ComboPackageChoice { 726 @SerializedName("name") 727 public String name; 728 729 @SerializedName("price") 730 public Long price; 731 732 @SerializedName("count") 733 public Long count; 734 735 @SerializedName("image_url") 736 public String imageUrl; 737 738 @SerializedName("mini_program_appid") 739 public String miniProgramAppid; 740 741 @SerializedName("mini_program_path") 742 public String miniProgramPath; 743 } 744 745 public static class FixedWeekPeriod { 746 @SerializedName("day_list") 747 public List<WeekEnum> dayList = new ArrayList<WeekEnum>(); 748 749 @SerializedName("day_period_list") 750 public List<PeriodOfTheDay> dayPeriodList; 751 } 752 753 public static class TimePeriod { 754 @SerializedName("begin_time") 755 public String beginTime; 756 757 @SerializedName("end_time") 758 public String endTime; 759 } 760 761 public enum WeekEnum { 762 @SerializedName("MONDAY") 763 MONDAY, 764 @SerializedName("TUESDAY") 765 TUESDAY, 766 @SerializedName("WEDNESDAY") 767 WEDNESDAY, 768 @SerializedName("THURSDAY") 769 THURSDAY, 770 @SerializedName("FRIDAY") 771 FRIDAY, 772 @SerializedName("SATURDAY") 773 SATURDAY, 774 @SerializedName("SUNDAY") 775 SUNDAY 776 } 777 778 public static class PeriodOfTheDay { 779 @SerializedName("begin_time") 780 public Long beginTime; 781 782 @SerializedName("end_time") 783 public Long endTime; 784 } 785 786} 787
需配合微信支付工具库 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 SingleUsageDetail *CouponUsageDetail `json:"single_usage_detail,omitempty"` 153 ProgressiveBundleUsageDetail *CouponUsageDetail `json:"progressive_bundle_usage_detail,omitempty"` 154 UserProductCouponBundleInfo *UserProductCouponBundleInfo `json:"user_product_coupon_bundle_info,omitempty"` 155 ProductCoupon *ProductCouponEntity `json:"product_coupon,omitempty"` 156 Stock *StockEntity `json:"stock,omitempty"` 157 Attach *string `json:"attach,omitempty"` 158 ChannelCustomInfo *string `json:"channel_custom_info,omitempty"` 159 CouponTagInfo *CouponTagInfo `json:"coupon_tag_info,omitempty"` 160 BrandId *string `json:"brand_id,omitempty"` 161} 162 163type UserProductCouponState string 164 165func (e UserProductCouponState) Ptr() *UserProductCouponState { 166 return &e 167} 168 169const ( 170 USERPRODUCTCOUPONSTATE_CONFIRMING UserProductCouponState = "CONFIRMING" 171 USERPRODUCTCOUPONSTATE_PENDING UserProductCouponState = "PENDING" 172 USERPRODUCTCOUPONSTATE_EFFECTIVE UserProductCouponState = "EFFECTIVE" 173 USERPRODUCTCOUPONSTATE_USED UserProductCouponState = "USED" 174 USERPRODUCTCOUPONSTATE_EXPIRED UserProductCouponState = "EXPIRED" 175 USERPRODUCTCOUPONSTATE_DELETED UserProductCouponState = "DELETED" 176 USERPRODUCTCOUPONSTATE_DEACTIVATED UserProductCouponState = "DEACTIVATED" 177) 178 179type UserProductCouponSendChannel string 180 181func (e UserProductCouponSendChannel) Ptr() *UserProductCouponSendChannel { 182 return &e 183} 184 185const ( 186 USERPRODUCTCOUPONSENDCHANNEL_BRAND_MANAGE UserProductCouponSendChannel = "BRAND_MANAGE" 187 USERPRODUCTCOUPONSENDCHANNEL_API UserProductCouponSendChannel = "API" 188 USERPRODUCTCOUPONSENDCHANNEL_RECEIVE_COMPONENT UserProductCouponSendChannel = "RECEIVE_COMPONENT" 189) 190 191type CouponUsageDetail struct { 192 UseRequestNo *string `json:"use_request_no,omitempty"` 193 UseTime *time.Time `json:"use_time,omitempty"` 194 ReturnRequestNo *string `json:"return_request_no,omitempty"` 195 ReturnTime *time.Time `json:"return_time,omitempty"` 196 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 197 AssociatedPayScoreOrderInfo *UserProductCouponAssociatedPayScoreOrderInfo `json:"associated_pay_score_order_info,omitempty"` 198 SavedAmount *int64 `json:"saved_amount,omitempty"` 199} 200 201type UserProductCouponBundleInfo struct { 202 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 203 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 204 TotalCount *int64 `json:"total_count,omitempty"` 205 UsedCount *int64 `json:"used_count,omitempty"` 206} 207 208type ProductCouponEntity struct { 209 ProductCouponId *string `json:"product_coupon_id,omitempty"` 210 Scope *ProductCouponScope `json:"scope,omitempty"` 211 Type *ProductCouponType `json:"type,omitempty"` 212 UsageMode *UsageMode `json:"usage_mode,omitempty"` 213 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 214 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 215 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 216 OutProductNo *string `json:"out_product_no,omitempty"` 217 State *ProductCouponState `json:"state,omitempty"` 218 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 219 DeactivateTime *string `json:"deactivate_time,omitempty"` 220 DeactivateReason *string `json:"deactivate_reason,omitempty"` 221 BrandId *string `json:"brand_id,omitempty"` 222} 223 224type StockEntity struct { 225 ProductCouponId *string `json:"product_coupon_id,omitempty"` 226 StockId *string `json:"stock_id,omitempty"` 227 Remark *string `json:"remark,omitempty"` 228 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 229 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 230 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 231 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 232 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 233 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 234 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 235 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 236 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 237 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 238 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 239 State *StockState `json:"state,omitempty"` 240 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 241 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 242 DeactivateReason *string `json:"deactivate_reason,omitempty"` 243 BrandId *string `json:"brand_id,omitempty"` 244} 245 246type CouponTagInfo struct { 247 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 248 MemberTagInfo *MemberTagInfo `json:"member_tag_info,omitempty"` 249} 250 251type UserProductCouponAssociatedOrderInfo struct { 252 TransactionId *string `json:"transaction_id,omitempty"` 253 OutTradeNo *string `json:"out_trade_no,omitempty"` 254 Mchid *string `json:"mchid,omitempty"` 255 SubMchid *string `json:"sub_mchid,omitempty"` 256} 257 258type UserProductCouponAssociatedPayScoreOrderInfo struct { 259 OrderId *string `json:"order_id,omitempty"` 260 OutOrderNo *string `json:"out_order_no,omitempty"` 261 Mchid *string `json:"mchid,omitempty"` 262 SubMchid *string `json:"sub_mchid,omitempty"` 263} 264 265type ProductCouponScope string 266 267func (e ProductCouponScope) Ptr() *ProductCouponScope { 268 return &e 269} 270 271const ( 272 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 273 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 274) 275 276type ProductCouponType string 277 278func (e ProductCouponType) Ptr() *ProductCouponType { 279 return &e 280} 281 282const ( 283 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 284 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 285 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 286) 287 288type UsageMode string 289 290func (e UsageMode) Ptr() *UsageMode { 291 return &e 292} 293 294const ( 295 USAGEMODE_SINGLE UsageMode = "SINGLE" 296 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 297) 298 299type SingleUsageInfo struct { 300 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 301 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 302} 303 304type ProgressiveBundleUsageInfo struct { 305 Count *int64 `json:"count,omitempty"` 306 IntervalDays *int64 `json:"interval_days,omitempty"` 307} 308 309type ProductCouponDisplayInfo struct { 310 Name *string `json:"name,omitempty"` 311 ImageUrl *string `json:"image_url,omitempty"` 312 BackgroundUrl *string `json:"background_url,omitempty"` 313 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 314 OriginalPrice *int64 `json:"original_price,omitempty"` 315 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 316} 317 318type ProductCouponState string 319 320func (e ProductCouponState) Ptr() *ProductCouponState { 321 return &e 322} 323 324const ( 325 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 326 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 327 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 328) 329 330type CouponCodeMode string 331 332func (e CouponCodeMode) Ptr() *CouponCodeMode { 333 return &e 334} 335 336const ( 337 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 338 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 339 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 340) 341 342type CouponCodeCountInfo struct { 343 TotalCount *int64 `json:"total_count,omitempty"` 344 AvailableCount *int64 `json:"available_count,omitempty"` 345} 346 347type StockSendRule struct { 348 MaxCount *int64 `json:"max_count,omitempty"` 349 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 350 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 351} 352 353type SingleUsageRule struct { 354 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 355 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 356 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 357 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 358} 359 360type StockUsageRule struct { 361 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 362 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 363 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 364 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 365} 366 367type StockBundleInfo struct { 368 StockBundleId *string `json:"stock_bundle_id,omitempty"` 369 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 370} 371 372type UsageRuleDisplayInfo struct { 373 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 374 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 375 MiniProgramPath *string `json:"mini_program_path,omitempty"` 376 AppPath *string `json:"app_path,omitempty"` 377 UsageDescription *string `json:"usage_description,omitempty"` 378 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 379} 380 381type CouponDisplayInfo struct { 382 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 383 BackgroundColor *string `json:"background_color,omitempty"` 384 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 385 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 386 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 387} 388 389type NotifyConfig struct { 390 NotifyAppid *string `json:"notify_appid,omitempty"` 391} 392 393type StockStoreScope string 394 395func (e StockStoreScope) Ptr() *StockStoreScope { 396 return &e 397} 398 399const ( 400 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 401 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 402 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 403) 404 405type StockSentCountInfo struct { 406 TotalCount *int64 `json:"total_count,omitempty"` 407 TodayCount *int64 `json:"today_count,omitempty"` 408} 409 410type StockState string 411 412func (e StockState) Ptr() *StockState { 413 return &e 414} 415 416const ( 417 STOCKSTATE_AUDITING StockState = "AUDITING" 418 STOCKSTATE_SENDING StockState = "SENDING" 419 STOCKSTATE_PAUSED StockState = "PAUSED" 420 STOCKSTATE_STOPPED StockState = "STOPPED" 421 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 422) 423 424type UserProductCouponTag string 425 426func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 427 return &e 428} 429 430const ( 431 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 432) 433 434type MemberTagInfo struct { 435 MemberCardId *string `json:"member_card_id,omitempty"` 436} 437 438type NormalCouponUsageRule struct { 439 Threshold *int64 `json:"threshold,omitempty"` 440 DiscountAmount *int64 `json:"discount_amount,omitempty"` 441} 442 443type DiscountCouponUsageRule struct { 444 Threshold *int64 `json:"threshold,omitempty"` 445 PercentOff *int64 `json:"percent_off,omitempty"` 446} 447 448type ComboPackage struct { 449 Name *string `json:"name,omitempty"` 450 PickCount *int64 `json:"pick_count,omitempty"` 451 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 452} 453 454type CouponAvailablePeriod struct { 455 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 456 AvailableEndTime *string `json:"available_end_time,omitempty"` 457 AvailableDays *int64 `json:"available_days,omitempty"` 458 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 459 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 460 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 461} 462 463type ExchangeCouponUsageRule struct { 464 Threshold *int64 `json:"threshold,omitempty"` 465 ExchangePrice *int64 `json:"exchange_price,omitempty"` 466} 467 468type CouponUsageMethod string 469 470func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 471 return &e 472} 473 474const ( 475 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 476 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 477 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 478 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 479) 480 481type CouponAvailableStoreInfo struct { 482 Description *string `json:"description,omitempty"` 483 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 484 MiniProgramPath *string `json:"mini_program_path,omitempty"` 485} 486 487type CouponCodeDisplayMode string 488 489func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 490 return &e 491} 492 493const ( 494 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 495 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 496 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 497) 498 499type EntranceMiniProgram struct { 500 Appid *string `json:"appid,omitempty"` 501 Path *string `json:"path,omitempty"` 502 EntranceWording *string `json:"entrance_wording,omitempty"` 503 GuidanceWording *string `json:"guidance_wording,omitempty"` 504} 505 506type EntranceOfficialAccount struct { 507 Appid *string `json:"appid,omitempty"` 508} 509 510type EntranceFinder struct { 511 FinderId *string `json:"finder_id,omitempty"` 512 FinderVideoId *string `json:"finder_video_id,omitempty"` 513 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 514} 515 516type ComboPackageChoice struct { 517 Name *string `json:"name,omitempty"` 518 Price *int64 `json:"price,omitempty"` 519 Count *int64 `json:"count,omitempty"` 520 ImageUrl *string `json:"image_url,omitempty"` 521 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 522 MiniProgramPath *string `json:"mini_program_path,omitempty"` 523} 524 525type FixedWeekPeriod struct { 526 DayList []WeekEnum `json:"day_list,omitempty"` 527 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 528} 529 530type TimePeriod struct { 531 BeginTime *string `json:"begin_time,omitempty"` 532 EndTime *string `json:"end_time,omitempty"` 533} 534 535type WeekEnum string 536 537func (e WeekEnum) Ptr() *WeekEnum { 538 return &e 539} 540 541const ( 542 WEEKENUM_MONDAY WeekEnum = "MONDAY" 543 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 544 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 545 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 546 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 547 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 548 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 549) 550 551type PeriodOfTheDay struct { 552 BeginTime *int64 `json:"begin_time,omitempty"` 553 EndTime *int64 `json:"end_time,omitempty"` 554} 555
应答参数
200 OK
coupon_code 必填 string(40)
【用户商品券Code】 用户商品券的唯一标识
coupon_state 必填 string
【用户商品券状态】
可选取值
CONFIRMING: 待确认,用户商品券发放需要品牌方调用【确认发放用户商品券API(单券)】或【确认发放用户商品券API(多次优惠)】后才能生效PENDING: 已发放待生效,用户商品券已发放成功但尚未到达可用开始时间EFFECTIVE: 已生效,用户商品券已成功发放且到达可用开始时间USED: 已核销,用户商品券已核销EXPIRED: 已过期,用户商品券已超过有效期,不再可用DELETED: 已删除,用户主动删除该券DEACTIVATED: 已失效,品牌方主动调用【失效用户商品券API】或【失效用户商品券组API】使用户商品券失效
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
【确认请求单号】 品牌方确认发券请求时传入的的请求流水号。当且仅当 品牌方调用【确认发放用户商品券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)
【失效请求单号】 品牌方失效券请求时传入的的请求流水号。当且仅当 coupon_state 为 DEACTIVATED 时提供,返回品牌方调用【失效用户商品券API】或【失效用户商品券组API】时传入的请求流水号
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 时提供,返回品牌方调用【失效用户商品券API】或【失效用户商品券组API】时传入的失效原因
single_usage_detail 选填 object
【单券使用详情】 当且仅当 usage_mode 为 SINGLE 时提供
| 属性 | |||||||||
use_request_no 选填 string 【券核销请求单号】 券核销的请求流水号,当且仅当用户商品券状态 use_time 选填 string 【券核销时间】 券被核销的时间,当且仅当用户商品券状态 return_request_no 选填 string 【退券请求单号】 品牌退券时传入的请求流水号,当且仅当券发生了退回后提供此字段 return_time 选填 string 【退券时间】 券被退回的时间,当且仅当券发生了退回后提供此字段。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) associated_order_info 选填 object 【券核销的微信支付订单信息】 券核销对应的微信支付订单信息,当且仅当用户商品券状态
associated_pay_score_order_info 选填 object 【券核销的关联微信支付分订单信息】 券核销的关联微信支付分订单信息,当且仅当用户商品券状态
saved_amount 选填 integer 【优惠金额】 使用本券的实际优惠金额,单位为分
|
progressive_bundle_usage_detail 选填 object
【多次优惠使用详情】 当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时提供
| 属性 | |||||||||
use_request_no 选填 string 【券核销请求单号】 券核销的请求流水号,当且仅当用户商品券状态 use_time 选填 string 【券核销时间】 券被核销的时间,当且仅当用户商品券状态 return_request_no 选填 string 【退券请求单号】 品牌退券时传入的请求流水号,当且仅当券发生了退回后提供此字段 return_time 选填 string 【退券时间】 券被退回的时间,当且仅当券发生了退回后提供此字段。遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间) associated_order_info 选填 object 【券核销的微信支付订单信息】 券核销对应的微信支付订单信息,当且仅当用户商品券状态
associated_pay_score_order_info 选填 object 【券核销的关联微信支付分订单信息】 券核销的关联微信支付分订单信息,当且仅当用户商品券状态
saved_amount 选填 integer 【优惠金额】 使用本券的实际优惠金额,单位为分
|
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 | 请求超过接口频率限制 | 请稍后使用原参数重试 |


