退券
更新时间:2025.08.04品牌方可以通过本接口将已经核销用户的商品券退回给用户。
前置条件:
已经给用户发券成功,且用户商品券当前已核销
特别的,针对商品券
usage_mode为PROGRESSIVE_BUNDLE的用户商品券,只有当该券为其所属券组最近一个已核销券时才可以退回。例如:假设券组内已核销第1、2、3张券,此时只能退回第3张券。
频率限制:500/s
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/users/{openid}/coupons/{coupon_code}/return
请求域名:【主域名】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/return \ 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" : "MCHRETURN202003101234", 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 ReturnUserProductCoupon { 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}/return"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ReturnUserProductCoupon client = new ReturnUserProductCoupon( 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 ReturnUserProductCouponRequest request = new ReturnUserProductCouponRequest(); 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 = "MCHRETURN202003101234"; 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(ReturnUserProductCouponRequest 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 ReturnUserProductCoupon(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 ReturnUserProductCouponRequest { 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("associated_order_info") 230 public UserProductCouponAssociatedOrderInfo associatedOrderInfo; 231 232 @SerializedName("return_request_no") 233 public String returnRequestNo; 234 235 @SerializedName("return_time") 236 public String returnTime; 237 } 238 239 public static class UserProductCouponBundleInfo { 240 @SerializedName("user_coupon_bundle_id") 241 public String userCouponBundleId; 242 243 @SerializedName("user_coupon_bundle_index") 244 public Long userCouponBundleIndex; 245 246 @SerializedName("total_count") 247 public Long totalCount; 248 249 @SerializedName("used_count") 250 public Long usedCount; 251 } 252 253 public static class ProductCouponEntity { 254 @SerializedName("product_coupon_id") 255 public String productCouponId; 256 257 @SerializedName("scope") 258 public ProductCouponScope scope; 259 260 @SerializedName("type") 261 public ProductCouponType type; 262 263 @SerializedName("usage_mode") 264 public UsageMode usageMode; 265 266 @SerializedName("single_usage_info") 267 public SingleUsageInfo singleUsageInfo; 268 269 @SerializedName("progressive_bundle_usage_info") 270 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 271 272 @SerializedName("display_info") 273 public ProductCouponDisplayInfo displayInfo; 274 275 @SerializedName("out_product_no") 276 public String outProductNo; 277 278 @SerializedName("state") 279 public ProductCouponState state; 280 281 @SerializedName("deactivate_request_no") 282 public String deactivateRequestNo; 283 284 @SerializedName("deactivate_time") 285 public String deactivateTime; 286 287 @SerializedName("deactivate_reason") 288 public String deactivateReason; 289 290 @SerializedName("brand_id") 291 public String brandId; 292 } 293 294 public static class StockEntity { 295 @SerializedName("product_coupon_id") 296 public String productCouponId; 297 298 @SerializedName("stock_id") 299 public String stockId; 300 301 @SerializedName("remark") 302 public String remark; 303 304 @SerializedName("coupon_code_mode") 305 public CouponCodeMode couponCodeMode; 306 307 @SerializedName("coupon_code_count_info") 308 public CouponCodeCountInfo couponCodeCountInfo; 309 310 @SerializedName("stock_send_rule") 311 public StockSendRule stockSendRule; 312 313 @SerializedName("single_usage_rule") 314 public SingleUsageRule singleUsageRule; 315 316 @SerializedName("progressive_bundle_usage_rule") 317 public StockUsageRule progressiveBundleUsageRule; 318 319 @SerializedName("stock_bundle_info") 320 public StockBundleInfo stockBundleInfo; 321 322 @SerializedName("usage_rule_display_info") 323 public UsageRuleDisplayInfo usageRuleDisplayInfo; 324 325 @SerializedName("coupon_display_info") 326 public CouponDisplayInfo couponDisplayInfo; 327 328 @SerializedName("notify_config") 329 public NotifyConfig notifyConfig; 330 331 @SerializedName("store_scope") 332 public StockStoreScope storeScope; 333 334 @SerializedName("sent_count_info") 335 public StockSentCountInfo sentCountInfo; 336 337 @SerializedName("state") 338 public StockState state; 339 340 @SerializedName("deactivate_request_no") 341 public String deactivateRequestNo; 342 343 @SerializedName("deactivate_time") 344 public String deactivateTime; 345 346 @SerializedName("deactivate_reason") 347 public String deactivateReason; 348 349 @SerializedName("brand_id") 350 public String brandId; 351 } 352 353 public static class CouponTagInfo { 354 @SerializedName("coupon_tag_list") 355 public List<UserProductCouponTag> couponTagList; 356 357 @SerializedName("member_tag_info") 358 public MemberTagInfo memberTagInfo; 359 } 360 361 public static class UserProductCouponAssociatedOrderInfo { 362 @SerializedName("transaction_id") 363 public String transactionId; 364 365 @SerializedName("out_trade_no") 366 public String outTradeNo; 367 368 @SerializedName("mchid") 369 public String mchid; 370 371 @SerializedName("sub_mchid") 372 public String subMchid; 373 } 374 375 public enum ProductCouponScope { 376 @SerializedName("ALL") 377 ALL, 378 @SerializedName("SINGLE") 379 SINGLE 380 } 381 382 public enum ProductCouponType { 383 @SerializedName("NORMAL") 384 NORMAL, 385 @SerializedName("DISCOUNT") 386 DISCOUNT, 387 @SerializedName("EXCHANGE") 388 EXCHANGE 389 } 390 391 public enum UsageMode { 392 @SerializedName("SINGLE") 393 SINGLE, 394 @SerializedName("PROGRESSIVE_BUNDLE") 395 PROGRESSIVE_BUNDLE 396 } 397 398 public static class SingleUsageInfo { 399 @SerializedName("normal_coupon") 400 public NormalCouponUsageRule normalCoupon; 401 402 @SerializedName("discount_coupon") 403 public DiscountCouponUsageRule discountCoupon; 404 } 405 406 public static class ProgressiveBundleUsageInfo { 407 @SerializedName("count") 408 public Long count; 409 410 @SerializedName("interval_days") 411 public Long intervalDays; 412 } 413 414 public static class ProductCouponDisplayInfo { 415 @SerializedName("name") 416 public String name; 417 418 @SerializedName("image_url") 419 public String imageUrl; 420 421 @SerializedName("background_url") 422 public String backgroundUrl; 423 424 @SerializedName("detail_image_url_list") 425 public List<String> detailImageUrlList; 426 427 @SerializedName("original_price") 428 public Long originalPrice; 429 430 @SerializedName("combo_package_list") 431 public List<ComboPackage> comboPackageList; 432 } 433 434 public enum ProductCouponState { 435 @SerializedName("AUDITING") 436 AUDITING, 437 @SerializedName("EFFECTIVE") 438 EFFECTIVE, 439 @SerializedName("DEACTIVATED") 440 DEACTIVATED 441 } 442 443 public enum CouponCodeMode { 444 @SerializedName("WECHATPAY") 445 WECHATPAY, 446 @SerializedName("UPLOAD") 447 UPLOAD, 448 @SerializedName("API_ASSIGN") 449 API_ASSIGN 450 } 451 452 public static class CouponCodeCountInfo { 453 @SerializedName("total_count") 454 public Long totalCount; 455 456 @SerializedName("available_count") 457 public Long availableCount; 458 } 459 460 public static class StockSendRule { 461 @SerializedName("max_count") 462 public Long maxCount; 463 464 @SerializedName("max_count_per_day") 465 public Long maxCountPerDay; 466 467 @SerializedName("max_count_per_user") 468 public Long maxCountPerUser; 469 } 470 471 public static class SingleUsageRule { 472 @SerializedName("coupon_available_period") 473 public CouponAvailablePeriod couponAvailablePeriod; 474 475 @SerializedName("normal_coupon") 476 public NormalCouponUsageRule normalCoupon; 477 478 @SerializedName("discount_coupon") 479 public DiscountCouponUsageRule discountCoupon; 480 481 @SerializedName("exchange_coupon") 482 public ExchangeCouponUsageRule exchangeCoupon; 483 } 484 485 public static class StockUsageRule { 486 @SerializedName("coupon_available_period") 487 public CouponAvailablePeriod couponAvailablePeriod; 488 489 @SerializedName("normal_coupon") 490 public NormalCouponUsageRule normalCoupon; 491 492 @SerializedName("discount_coupon") 493 public DiscountCouponUsageRule discountCoupon; 494 495 @SerializedName("exchange_coupon") 496 public ExchangeCouponUsageRule exchangeCoupon; 497 } 498 499 public static class StockBundleInfo { 500 @SerializedName("stock_bundle_id") 501 public String stockBundleId; 502 503 @SerializedName("stock_bundle_index") 504 public Long stockBundleIndex; 505 } 506 507 public static class UsageRuleDisplayInfo { 508 @SerializedName("coupon_usage_method_list") 509 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 510 511 @SerializedName("mini_program_appid") 512 public String miniProgramAppid; 513 514 @SerializedName("mini_program_path") 515 public String miniProgramPath; 516 517 @SerializedName("app_path") 518 public String appPath; 519 520 @SerializedName("usage_description") 521 public String usageDescription; 522 523 @SerializedName("coupon_available_store_info") 524 public CouponAvailableStoreInfo couponAvailableStoreInfo; 525 } 526 527 public static class CouponDisplayInfo { 528 @SerializedName("code_display_mode") 529 public CouponCodeDisplayMode codeDisplayMode; 530 531 @SerializedName("background_color") 532 public String backgroundColor; 533 534 @SerializedName("entrance_mini_program") 535 public EntranceMiniProgram entranceMiniProgram; 536 537 @SerializedName("entrance_official_account") 538 public EntranceOfficialAccount entranceOfficialAccount; 539 540 @SerializedName("entrance_finder") 541 public EntranceFinder entranceFinder; 542 } 543 544 public static class NotifyConfig { 545 @SerializedName("notify_appid") 546 public String notifyAppid; 547 } 548 549 public enum StockStoreScope { 550 @SerializedName("NONE") 551 NONE, 552 @SerializedName("ALL") 553 ALL, 554 @SerializedName("SPECIFIC") 555 SPECIFIC 556 } 557 558 public static class StockSentCountInfo { 559 @SerializedName("total_count") 560 public Long totalCount; 561 562 @SerializedName("today_count") 563 public Long todayCount; 564 } 565 566 public enum StockState { 567 @SerializedName("AUDITING") 568 AUDITING, 569 @SerializedName("SENDING") 570 SENDING, 571 @SerializedName("PAUSED") 572 PAUSED, 573 @SerializedName("STOPPED") 574 STOPPED, 575 @SerializedName("DEACTIVATED") 576 DEACTIVATED 577 } 578 579 public enum UserProductCouponTag { 580 @SerializedName("MEMBER") 581 MEMBER 582 } 583 584 public static class MemberTagInfo { 585 @SerializedName("member_card_id") 586 public String memberCardId; 587 } 588 589 public static class NormalCouponUsageRule { 590 @SerializedName("threshold") 591 public Long threshold; 592 593 @SerializedName("discount_amount") 594 public Long discountAmount; 595 } 596 597 public static class DiscountCouponUsageRule { 598 @SerializedName("threshold") 599 public Long threshold; 600 601 @SerializedName("percent_off") 602 public Long percentOff; 603 } 604 605 public static class ComboPackage { 606 @SerializedName("name") 607 public String name; 608 609 @SerializedName("pick_count") 610 public Long pickCount; 611 612 @SerializedName("choice_list") 613 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 614 } 615 616 public static class CouponAvailablePeriod { 617 @SerializedName("available_begin_time") 618 public String availableBeginTime; 619 620 @SerializedName("available_end_time") 621 public String availableEndTime; 622 623 @SerializedName("available_days") 624 public Long availableDays; 625 626 @SerializedName("wait_days_after_receive") 627 public Long waitDaysAfterReceive; 628 629 @SerializedName("weekly_available_period") 630 public FixedWeekPeriod weeklyAvailablePeriod; 631 632 @SerializedName("irregular_available_period_list") 633 public List<TimePeriod> irregularAvailablePeriodList; 634 } 635 636 public static class ExchangeCouponUsageRule { 637 @SerializedName("threshold") 638 public Long threshold; 639 640 @SerializedName("exchange_price") 641 public Long exchangePrice; 642 } 643 644 public enum CouponUsageMethod { 645 @SerializedName("OFFLINE") 646 OFFLINE, 647 @SerializedName("MINI_PROGRAM") 648 MINI_PROGRAM, 649 @SerializedName("APP") 650 APP, 651 @SerializedName("PAYMENT_CODE") 652 PAYMENT_CODE 653 } 654 655 public static class CouponAvailableStoreInfo { 656 @SerializedName("description") 657 public String description; 658 659 @SerializedName("mini_program_appid") 660 public String miniProgramAppid; 661 662 @SerializedName("mini_program_path") 663 public String miniProgramPath; 664 } 665 666 public enum CouponCodeDisplayMode { 667 @SerializedName("INVISIBLE") 668 INVISIBLE, 669 @SerializedName("BARCODE") 670 BARCODE, 671 @SerializedName("QRCODE") 672 QRCODE 673 } 674 675 public static class EntranceMiniProgram { 676 @SerializedName("appid") 677 public String appid; 678 679 @SerializedName("path") 680 public String path; 681 682 @SerializedName("entrance_wording") 683 public String entranceWording; 684 685 @SerializedName("guidance_wording") 686 public String guidanceWording; 687 } 688 689 public static class EntranceOfficialAccount { 690 @SerializedName("appid") 691 public String appid; 692 } 693 694 public static class EntranceFinder { 695 @SerializedName("finder_id") 696 public String finderId; 697 698 @SerializedName("finder_video_id") 699 public String finderVideoId; 700 701 @SerializedName("finder_video_cover_image_url") 702 public String finderVideoCoverImageUrl; 703 } 704 705 public static class ComboPackageChoice { 706 @SerializedName("name") 707 public String name; 708 709 @SerializedName("price") 710 public Long price; 711 712 @SerializedName("count") 713 public Long count; 714 715 @SerializedName("image_url") 716 public String imageUrl; 717 718 @SerializedName("mini_program_appid") 719 public String miniProgramAppid; 720 721 @SerializedName("mini_program_path") 722 public String miniProgramPath; 723 } 724 725 public static class FixedWeekPeriod { 726 @SerializedName("day_list") 727 public List<WeekEnum> dayList; 728 729 @SerializedName("day_period_list") 730 public List<PeriodOfTheDay> dayPeriodList; 731 } 732 733 public static class TimePeriod { 734 @SerializedName("begin_time") 735 public String beginTime; 736 737 @SerializedName("end_time") 738 public String endTime; 739 } 740 741 public enum WeekEnum { 742 @SerializedName("MONDAY") 743 MONDAY, 744 @SerializedName("TUESDAY") 745 TUESDAY, 746 @SerializedName("WEDNESDAY") 747 WEDNESDAY, 748 @SerializedName("THURSDAY") 749 THURSDAY, 750 @SerializedName("FRIDAY") 751 FRIDAY, 752 @SerializedName("SATURDAY") 753 SATURDAY, 754 @SerializedName("SUNDAY") 755 SUNDAY 756 } 757 758 public static class PeriodOfTheDay { 759 @SerializedName("begin_time") 760 public Long beginTime; 761 762 @SerializedName("end_time") 763 public Long endTime; 764 } 765 766} 767
需配合微信支付工具库 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 := &ReturnUserProductCouponRequest{ 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("MCHRETURN202003101234"), 35 BrandId: wxpay_utility.String("120344"), 36 } 37 38 response, err := ReturnUserProductCoupon(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 ReturnUserProductCoupon(config *wxpay_utility.MchConfig, request *ReturnUserProductCouponRequest) (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}/return" 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 ReturnUserProductCouponRequest 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 *ReturnUserProductCouponRequest) MarshalJSON() ([]byte, error) { 125 type Alias ReturnUserProductCouponRequest 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 AssociatedOrderInfo *UserProductCouponAssociatedOrderInfo `json:"associated_order_info,omitempty"` 195 ReturnRequestNo *string `json:"return_request_no,omitempty"` 196 ReturnTime *time.Time `json:"return_time,omitempty"` 197} 198 199type UserProductCouponBundleInfo struct { 200 UserCouponBundleId *string `json:"user_coupon_bundle_id,omitempty"` 201 UserCouponBundleIndex *int64 `json:"user_coupon_bundle_index,omitempty"` 202 TotalCount *int64 `json:"total_count,omitempty"` 203 UsedCount *int64 `json:"used_count,omitempty"` 204} 205 206type ProductCouponEntity struct { 207 ProductCouponId *string `json:"product_coupon_id,omitempty"` 208 Scope *ProductCouponScope `json:"scope,omitempty"` 209 Type *ProductCouponType `json:"type,omitempty"` 210 UsageMode *UsageMode `json:"usage_mode,omitempty"` 211 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 212 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 213 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 214 OutProductNo *string `json:"out_product_no,omitempty"` 215 State *ProductCouponState `json:"state,omitempty"` 216 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 217 DeactivateTime *string `json:"deactivate_time,omitempty"` 218 DeactivateReason *string `json:"deactivate_reason,omitempty"` 219 BrandId *string `json:"brand_id,omitempty"` 220} 221 222type StockEntity struct { 223 ProductCouponId *string `json:"product_coupon_id,omitempty"` 224 StockId *string `json:"stock_id,omitempty"` 225 Remark *string `json:"remark,omitempty"` 226 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 227 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 228 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 229 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 230 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 231 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 232 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 233 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 234 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 235 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 236 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 237 State *StockState `json:"state,omitempty"` 238 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 239 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 240 DeactivateReason *string `json:"deactivate_reason,omitempty"` 241 BrandId *string `json:"brand_id,omitempty"` 242} 243 244type CouponTagInfo struct { 245 CouponTagList []UserProductCouponTag `json:"coupon_tag_list,omitempty"` 246 MemberTagInfo *MemberTagInfo `json:"member_tag_info,omitempty"` 247} 248 249type UserProductCouponAssociatedOrderInfo struct { 250 TransactionId *string `json:"transaction_id,omitempty"` 251 OutTradeNo *string `json:"out_trade_no,omitempty"` 252 Mchid *string `json:"mchid,omitempty"` 253 SubMchid *string `json:"sub_mchid,omitempty"` 254} 255 256type ProductCouponScope string 257 258func (e ProductCouponScope) Ptr() *ProductCouponScope { 259 return &e 260} 261 262const ( 263 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 264 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 265) 266 267type ProductCouponType string 268 269func (e ProductCouponType) Ptr() *ProductCouponType { 270 return &e 271} 272 273const ( 274 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 275 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 276 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 277) 278 279type UsageMode string 280 281func (e UsageMode) Ptr() *UsageMode { 282 return &e 283} 284 285const ( 286 USAGEMODE_SINGLE UsageMode = "SINGLE" 287 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 288) 289 290type SingleUsageInfo struct { 291 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 292 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 293} 294 295type ProgressiveBundleUsageInfo struct { 296 Count *int64 `json:"count,omitempty"` 297 IntervalDays *int64 `json:"interval_days,omitempty"` 298} 299 300type ProductCouponDisplayInfo struct { 301 Name *string `json:"name,omitempty"` 302 ImageUrl *string `json:"image_url,omitempty"` 303 BackgroundUrl *string `json:"background_url,omitempty"` 304 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 305 OriginalPrice *int64 `json:"original_price,omitempty"` 306 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 307} 308 309type ProductCouponState string 310 311func (e ProductCouponState) Ptr() *ProductCouponState { 312 return &e 313} 314 315const ( 316 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 317 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 318 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 319) 320 321type CouponCodeMode string 322 323func (e CouponCodeMode) Ptr() *CouponCodeMode { 324 return &e 325} 326 327const ( 328 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 329 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 330 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 331) 332 333type CouponCodeCountInfo struct { 334 TotalCount *int64 `json:"total_count,omitempty"` 335 AvailableCount *int64 `json:"available_count,omitempty"` 336} 337 338type StockSendRule struct { 339 MaxCount *int64 `json:"max_count,omitempty"` 340 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 341 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 342} 343 344type SingleUsageRule struct { 345 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 346 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 347 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 348 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 349} 350 351type StockUsageRule struct { 352 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 353 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 354 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 355 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 356} 357 358type StockBundleInfo struct { 359 StockBundleId *string `json:"stock_bundle_id,omitempty"` 360 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 361} 362 363type UsageRuleDisplayInfo struct { 364 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 365 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 366 MiniProgramPath *string `json:"mini_program_path,omitempty"` 367 AppPath *string `json:"app_path,omitempty"` 368 UsageDescription *string `json:"usage_description,omitempty"` 369 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 370} 371 372type CouponDisplayInfo struct { 373 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 374 BackgroundColor *string `json:"background_color,omitempty"` 375 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 376 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 377 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 378} 379 380type NotifyConfig struct { 381 NotifyAppid *string `json:"notify_appid,omitempty"` 382} 383 384type StockStoreScope string 385 386func (e StockStoreScope) Ptr() *StockStoreScope { 387 return &e 388} 389 390const ( 391 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 392 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 393 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 394) 395 396type StockSentCountInfo struct { 397 TotalCount *int64 `json:"total_count,omitempty"` 398 TodayCount *int64 `json:"today_count,omitempty"` 399} 400 401type StockState string 402 403func (e StockState) Ptr() *StockState { 404 return &e 405} 406 407const ( 408 STOCKSTATE_AUDITING StockState = "AUDITING" 409 STOCKSTATE_SENDING StockState = "SENDING" 410 STOCKSTATE_PAUSED StockState = "PAUSED" 411 STOCKSTATE_STOPPED StockState = "STOPPED" 412 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 413) 414 415type UserProductCouponTag string 416 417func (e UserProductCouponTag) Ptr() *UserProductCouponTag { 418 return &e 419} 420 421const ( 422 USERPRODUCTCOUPONTAG_MEMBER UserProductCouponTag = "MEMBER" 423) 424 425type MemberTagInfo struct { 426 MemberCardId *string `json:"member_card_id,omitempty"` 427} 428 429type NormalCouponUsageRule struct { 430 Threshold *int64 `json:"threshold,omitempty"` 431 DiscountAmount *int64 `json:"discount_amount,omitempty"` 432} 433 434type DiscountCouponUsageRule struct { 435 Threshold *int64 `json:"threshold,omitempty"` 436 PercentOff *int64 `json:"percent_off,omitempty"` 437} 438 439type ComboPackage struct { 440 Name *string `json:"name,omitempty"` 441 PickCount *int64 `json:"pick_count,omitempty"` 442 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 443} 444 445type CouponAvailablePeriod struct { 446 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 447 AvailableEndTime *string `json:"available_end_time,omitempty"` 448 AvailableDays *int64 `json:"available_days,omitempty"` 449 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 450 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 451 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 452} 453 454type ExchangeCouponUsageRule struct { 455 Threshold *int64 `json:"threshold,omitempty"` 456 ExchangePrice *int64 `json:"exchange_price,omitempty"` 457} 458 459type CouponUsageMethod string 460 461func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 462 return &e 463} 464 465const ( 466 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 467 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 468 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 469 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 470) 471 472type CouponAvailableStoreInfo struct { 473 Description *string `json:"description,omitempty"` 474 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 475 MiniProgramPath *string `json:"mini_program_path,omitempty"` 476} 477 478type CouponCodeDisplayMode string 479 480func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 481 return &e 482} 483 484const ( 485 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 486 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 487 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 488) 489 490type EntranceMiniProgram struct { 491 Appid *string `json:"appid,omitempty"` 492 Path *string `json:"path,omitempty"` 493 EntranceWording *string `json:"entrance_wording,omitempty"` 494 GuidanceWording *string `json:"guidance_wording,omitempty"` 495} 496 497type EntranceOfficialAccount struct { 498 Appid *string `json:"appid,omitempty"` 499} 500 501type EntranceFinder struct { 502 FinderId *string `json:"finder_id,omitempty"` 503 FinderVideoId *string `json:"finder_video_id,omitempty"` 504 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 505} 506 507type ComboPackageChoice struct { 508 Name *string `json:"name,omitempty"` 509 Price *int64 `json:"price,omitempty"` 510 Count *int64 `json:"count,omitempty"` 511 ImageUrl *string `json:"image_url,omitempty"` 512 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 513 MiniProgramPath *string `json:"mini_program_path,omitempty"` 514} 515 516type FixedWeekPeriod struct { 517 DayList []WeekEnum `json:"day_list,omitempty"` 518 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 519} 520 521type TimePeriod struct { 522 BeginTime *string `json:"begin_time,omitempty"` 523 EndTime *string `json:"end_time,omitempty"` 524} 525 526type WeekEnum string 527 528func (e WeekEnum) Ptr() *WeekEnum { 529 return &e 530} 531 532const ( 533 WEEKENUM_MONDAY WeekEnum = "MONDAY" 534 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 535 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 536 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 537 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 538 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 539 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 540) 541 542type PeriodOfTheDay struct { 543 BeginTime *int64 `json:"begin_time,omitempty"` 544 EndTime *int64 `json:"end_time,omitempty"` 545} 546
应答参数
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 时提供,返回品牌方调用失效用户商品券接口时传入的失效原因
single_usage_detail 选填 object
【单券使用详情】 当且仅当 usage_mode 为 SINGLE 时提供
| 属性 | |||||
use_request_no 选填 string 【券核销请求单号】 券核销的请求流水号,当且仅当用户商品券状态 use_time 选填 string 【券核销时间】 券被核销的时间,当且仅当用户商品券状态 associated_order_info 选填 object 【券核销的微信支付订单信息】 券核销对应的微信支付订单信息,当且仅当用户商品券状态
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小时,即北京时间) |
progressive_bundle_usage_detail 选填 object
【多次优惠使用详情】 当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时提供
| 属性 | |||||
use_request_no 选填 string 【券核销请求单号】 券核销的请求流水号,当且仅当用户商品券状态 use_time 选填 string 【券核销时间】 券被核销的时间,当且仅当用户商品券状态 associated_order_info 选填 object 【券核销的微信支付订单信息】 券核销对应的微信支付订单信息,当且仅当用户商品券状态
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小时,即北京时间) |
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 "use_request_no" : "MCHUSE202003101234", 13 "use_time" : "2025-08-03T12:00:00+08:00", 14 "associated_order_info" : { 15 "transaction_id" : "4200000000123456789123456789" 16 }, 17 "return_request_no" : "MCHRETURN202003101234", 18 "return_time" : "2025-08-03T12:01:00+08:00" 19 }, 20 "product_coupon" : { 21 "product_coupon_id" : "1000000013", 22 "scope" : "ALL", 23 "type" : "DISCOUNT", 24 "usage_mode" : "SINGLE", 25 "single_usage_info" : { 26 "discount_coupon" : { 27 "threshold" : 10000, 28 "percent_off" : 20 29 } 30 }, 31 "display_info" : { 32 "name" : "全场满100立打8折-新名字", 33 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 34 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 35 "detail_image_url_list" : [ 36 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 37 ] 38 }, 39 "state" : "EFFECTIVE", 40 "out_product_no" : "Product_1234567890", 41 "brand_id" : "120344" 42 }, 43 "stock" : { 44 "product_coupon_id" : "1000000013", 45 "stock_id" : "1000000013001", 46 "remark" : "8月工作日有效批次", 47 "coupon_code_mode" : "UPLOAD", 48 "coupon_code_count_info" : { 49 "total_count" : 0, 50 "available_count" : 0 51 }, 52 "stock_send_rule" : { 53 "max_count" : 10000000, 54 "max_count_per_user" : 1 55 }, 56 "single_usage_rule" : { 57 "coupon_available_period" : { 58 "available_begin_time" : "2025-08-01T00:00:00+08:00", 59 "available_end_time" : "2025-08-31T23:59:59+08:00", 60 "available_days" : 30, 61 "weekly_available_period" : { 62 "day_list" : [ 63 "MONDAY", 64 "TUESDAY", 65 "WEDNESDAY", 66 "THURSDAY", 67 "FRIDAY" 68 ] 69 } 70 } 71 }, 72 "usage_rule_display_info" : { 73 "coupon_usage_method_list" : [ 74 "OFFLINE", 75 "MINI_PROGRAM", 76 "PAYMENT_CODE" 77 ], 78 "mini_program_appid" : "wx1234567890", 79 "mini_program_path" : "/pages/index/product", 80 "usage_description" : "工作日可用", 81 "coupon_available_store_info" : { 82 "description" : "所有门店可用,可使用小程序查看门店列表", 83 "mini_program_appid" : "wx1234567890", 84 "mini_program_path" : "/pages/index/store-list" 85 } 86 }, 87 "coupon_display_info" : { 88 "code_display_mode" : "QRCODE", 89 "background_color" : "Color010", 90 "entrance_mini_program" : { 91 "appid" : "wx1234567890", 92 "path" : "/pages/index/product", 93 "entrance_wording" : "欢迎选购", 94 "guidance_wording" : "获取更多优惠" 95 }, 96 "entrance_official_account" : { 97 "appid" : "wx1234567890" 98 }, 99 "entrance_finder" : { 100 "finder_id" : "gh_12345678", 101 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 102 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 103 } 104 }, 105 "notify_config" : { 106 "notify_appid" : "wx4fd12345678" 107 }, 108 "store_scope" : "NONE", 109 "sent_count_info" : { 110 "total_count" : 0, 111 "today_count" : 0 112 }, 113 "state" : "SENDING", 114 "brand_id" : "120344" 115 }, 116 "attach" : "any attach content", 117 "brand_id" : "120344" 118} 119
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
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 | 请求超过接口频率限制 | 请稍后使用原参数重试 |

