创建商品券
更新时间:2025.11.06品牌方可以通过该接口为品牌创建商品券和批次(或批次组)。微信支付创建成功后,会返回此次创建的商品券、批次(或批次组)。品牌方可在【经营平台】上配置【活动】对商品券进行投放。
前置条件:品牌方已【设置商品券事件通知地址】
频率限制:20/s
接口说明
支持商户:【品牌商户】
请求方式:【POST】/brand/marketing/product-coupon/product-coupons
请求域名:【主域名】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
Wechatpay-Serial 必填 string
【微信支付公钥ID】 请传入brand_id对应的微信支付公钥ID,接口将会校验两者的关联关系,参考微信支付公钥产品简介及使用说明获取微信支付公钥ID和相关的介绍。以下两种场景将使用到微信支付公钥: 1、接收到接口的返回内容,需要使用微信支付公钥进行验签; 2、调用含有敏感信息参数(如姓名、身份证号码)的接口时,需要使用微信支付公钥加密敏感信息后再传输参数,加密指引请参考微信支付公钥加密敏感信息指引。
body 包体参数
out_request_no 必填 string(40)
【创建请求单号】 品牌创建商品券的请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_、短横线- 组成,长度在6-40个字符之间
scope 必填 string
【优惠范围】 商品券的优惠范围
可选取值
ALL: 全场券,此时券类型type仅可配置为NORMAL或DISCOUNTSINGLE: 单品券,此时券类型type配置不受限制,即可配置为NORMAL、DISCOUNT或EXCHANGE
type 必填 string
【商品券类型】 商品券的优惠类型
可选取值
NORMAL: 满减券DISCOUNT: 折扣券EXCHANGE: 兑换券,仅在scope为SINGLE时可配置
usage_mode 必填 string
【使用模式】 商品券使用模式
可选取值
SINGLE: 单券,即用户只能使用一次,使用后券失效PROGRESSIVE_BUNDLE: 多次优惠,由一组批次组成,每阶梯次序对应一个批次。用户按顺序使用,每次核销后发放下一张券,直到用完为止
single_usage_info 选填 object
【单券模式信息】 单券模式配置信息,当且仅当 usage_mode 为 SINGLE 时选填(是否填写取决于是否需要填写内部字段),其他模式不应填写。
| 属性 | |||||||||
normal_coupon 选填 object 【满减券使用规则】 本商品券内所有批次均以此规则提供满减优惠,当且仅当
discount_coupon 选填 object 【折扣券使用规则】 本商品券内所有批次均以此规则提供折扣优惠,当且仅当
|
progressive_bundle_usage_info 选填 object
【多次优惠模式信息】 多次优惠模式配置信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时必传,其他模式不应填写。
| 属性 | |
count 必填 integer 【可使用次数】 多次优惠领取后用户可使用次数,最少3次,最多15次 interval_days 选填 integer 【多次优惠使用间隔天数】 多次优惠多次使用之间需要间隔的天数,最高7天。例如:
默认情况下为 |
display_info 必填 object
【展示信息】 商品券展示信息,展示结果可参考商品券示意图(单券模式)与商品券示意图(多次优惠模式)
| 属性 | |||||||||
name 必填 string(15) 【商品券名称】 商品券名称,长度为3-15个UTF-8字符 image_url 必填 string 【商品券图片】 商品图片的链接地址,仅支持通过【图片上传API】获取的图片URL地址。
background_url 必填 string 【商品券背景图】 商品背景图片的URL地址,仅支持通过【图片上传API】获取的图片URL地址。
detail_image_url_list 选填 array[string] 【商品券详情图列表】 商品详情图URL地址列表,用于最多可上传8张图片,仅支持通过【图片上传API】获取的图片URL地址。
original_price 选填 integer 【商品原价】 单位为分,当且仅当 combo_package_list 选填 array[object] 【套餐组合】 当
|
out_product_no 选填 string(40)
【外部商品ID】 品牌侧的商品标识,品牌可自行选择传入,长度不超过40个字符。
注:微信支付不校验此参数的唯一性,即允许多个商品券共享外部商品ID。
stock 选填 object
【批次】 商品券批次信息,当且仅当 usage_mode 不为 PROGRESSIVE_BUNDLE 时必传,其他模式不应填写。PROGRESSIVE_BUNDLE 模式下应使用 stock_bundle 字段
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
remark 选填 string(20) 【备注】 仅配置品牌方可见,用于自定义信息,最多20个UTF-8字符 coupon_code_mode 必填 string 【券Code分配模式】 决定发券时用户商品券Code如何产生 可选取值
stock_send_rule 必填 object 【发放规则】 批次的发放规则
single_usage_rule 选填 object 【单券使用规则】 当且仅当
usage_rule_display_info 必填 object 【券使用规则展示信息】 券使用规则展示信息
coupon_display_info 必填 object 【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口
notify_config 必填 object 【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
store_scope 必填 string 【可用门店范围】 控制该批次可以在品牌下哪些门店使用 可选取值
|
stock_bundle 选填 object
【批次组】 商品券批次组信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时必传,其他模式不应填写。
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
remark 选填 string(20) 【备注】 仅配置品牌方可见,用于自定义信息,最多20个UTF-8字符 coupon_code_mode 必填 string 【券Code分配模式】 决定发券时用户商品券Code如何产生,批次组内每一个批次都会设置为此值 可选取值
stock_send_rule 必填 object 【发放规则】 批次的发放规则
progressive_bundle_usage_rule 选填 object 【多次优惠批次组使用规则】 包含组合内部每一个批次的优惠规则,会根据内部的优惠规则列表依次创建批次放入批次组,当且仅当
usage_rule_display_info 必填 object 【券使用规则展示信息】 券使用规则展示信息,批次组内每一个批次都会设置为此值
coupon_display_info 必填 object 【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口,批次组内每一个批次都会设置为此值
notify_config 必填 object 【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置,批次组内每一个批次都会设置为此值
store_scope 必填 string 【可用门店范围】 控制该批次可以在品牌下哪些门店使用,批次组内每一个批次都会设置为此值 可选取值
|
请求示例
POST
创建满100可用的全场8折券
1curl -X POST \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/product-coupons \ 3 -H "Authorization: WECHATPAY-BRAND-SHA256-RSA2048 brand_id=\"XXXX\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: PUB_KEY_ID_XXXX" \ 6 -H "Content-Type: application/json" \ 7 -d '{ 8 "out_product_no" : "Product_1234567890", 9 "scope" : "ALL", 10 "usage_mode" : "SINGLE", 11 "display_info" : { 12 "name" : "全场满100立打8折", 13 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 14 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 15 "detail_image_url_list" : [ 16 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 17 ] 18 }, 19 "single_usage_info" : { 20 "discount_coupon" : { 21 "threshold" : 10000, 22 "percent_off" : 20 23 } 24 }, 25 "type" : "DISCOUNT", 26 "stock" : { 27 "remark" : "8月工作日有效批次", 28 "coupon_code_mode" : "UPLOAD", 29 "stock_send_rule" : { 30 "max_count" : 10000000, 31 "max_count_per_user" : 1 32 }, 33 "single_usage_rule" : { 34 "coupon_available_period" : { 35 "available_begin_time" : "2025-08-01T00:00:00+08:00", 36 "available_end_time" : "2025-08-31T23:59:59+08:00", 37 "available_days" : 30, 38 "weekly_available_period" : { 39 "day_list" : [ 40 "MONDAY", 41 "TUESDAY", 42 "WEDNESDAY", 43 "THURSDAY", 44 "FRIDAY" 45 ] 46 } 47 } 48 }, 49 "usage_rule_display_info" : { 50 "coupon_usage_method_list" : [ 51 "OFFLINE", 52 "MINI_PROGRAM", 53 "PAYMENT_CODE" 54 ], 55 "mini_program_appid" : "wx1234567890", 56 "mini_program_path" : "/pages/index/product", 57 "usage_description" : "工作日可用", 58 "coupon_available_store_info" : { 59 "description" : "所有门店可用,可使用小程序查看门店列表", 60 "mini_program_appid" : "wx1234567890", 61 "mini_program_path" : "/pages/index/store-list" 62 } 63 }, 64 "coupon_display_info" : { 65 "code_display_mode" : "QRCODE", 66 "background_color" : "Color010", 67 "entrance_mini_program" : { 68 "appid" : "wx1234567890", 69 "path" : "/pages/index/product", 70 "entrance_wording" : "欢迎选购", 71 "guidance_wording" : "获取更多优惠" 72 }, 73 "entrance_official_account" : { 74 "appid" : "wx1234567890" 75 }, 76 "entrance_finder" : { 77 "finder_id" : "gh_12345678", 78 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 79 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 80 } 81 }, 82 "store_scope" : "NONE", 83 "notify_config" : { 84 "notify_appid" : "wx4fd12345678" 85 } 86 }, 87 "out_request_no" : "12345_20250101_A3489" 88 }' 89
创建全场折扣多次优惠券
1curl -X POST \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/product-coupons \ 3 -H "Authorization: WECHATPAY-BRAND-SHA256-RSA2048 brand_id=\"XXXX\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: PUB_KEY_ID_XXXX" \ 6 -H "Content-Type: application/json" \ 7 -d '{ 8 "stock_bundle" : { 9 "remark" : "8月工作日有效批次", 10 "coupon_code_mode" : "UPLOAD", 11 "stock_send_rule" : { 12 "max_count" : 10000000, 13 "max_count_per_user" : 1 14 }, 15 "progressive_bundle_usage_rule" : { 16 "coupon_available_period" : { 17 "available_begin_time" : "2025-08-01T00:00:00+08:00", 18 "available_end_time" : "2025-08-31T23:59:59+08:00", 19 "available_days" : 30, 20 "weekly_available_period" : { 21 "day_list" : [ 22 "MONDAY", 23 "TUESDAY", 24 "WEDNESDAY", 25 "THURSDAY", 26 "FRIDAY" 27 ] 28 } 29 }, 30 "discount_coupon_list" : [ 31 { 32 "threshold" : 10000, 33 "percent_off" : 50 34 }, 35 { 36 "threshold" : 10000, 37 "percent_off" : 20 38 }, 39 { 40 "threshold" : 10000, 41 "percent_off" : 30 42 } 43 ] 44 }, 45 "usage_rule_display_info" : { 46 "coupon_usage_method_list" : [ 47 "OFFLINE", 48 "MINI_PROGRAM", 49 "PAYMENT_CODE" 50 ], 51 "mini_program_appid" : "wx1234567890", 52 "mini_program_path" : "/pages/index/product", 53 "usage_description" : "工作日可用", 54 "coupon_available_store_info" : { 55 "description" : "所有门店可用,可使用小程序查看门店列表", 56 "mini_program_appid" : "wx1234567890", 57 "mini_program_path" : "/pages/index/store-list" 58 } 59 }, 60 "coupon_display_info" : { 61 "code_display_mode" : "QRCODE", 62 "background_color" : "Color010", 63 "entrance_mini_program" : { 64 "appid" : "wx1234567890", 65 "path" : "/pages/index/product", 66 "entrance_wording" : "欢迎选购", 67 "guidance_wording" : "获取更多优惠" 68 }, 69 "entrance_official_account" : { 70 "appid" : "wx1234567890" 71 }, 72 "entrance_finder" : { 73 "finder_id" : "gh_12345678", 74 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 75 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 76 } 77 }, 78 "store_scope" : "NONE", 79 "notify_config" : { 80 "notify_appid" : "wx4fd12345678" 81 } 82 }, 83 "out_product_no" : "Product_1234567890", 84 "scope" : "ALL", 85 "usage_mode" : "PROGRESSIVE_BUNDLE", 86 "display_info" : { 87 "name" : "全场多次折扣券", 88 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 89 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 90 "detail_image_url_list" : [ 91 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 92 ] 93 }, 94 "type" : "DISCOUNT", 95 "out_request_no" : "12345_20250101_A3489", 96 "progressive_bundle_usage_info" : { 97 "count" : 3, 98 "interval_days" : 1 99 } 100 }' 101
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayBrandUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/brand/4015826861 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 CreateProductCoupon { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/brand/marketing/product-coupon/product-coupons"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 CreateProductCoupon client = new CreateProductCoupon( 33 "xxxxxxxx", // 品牌ID,是由微信支付系统生成并分配给每个品牌方的唯一标识符,品牌ID获取方式参考 https://pay.weixin.qq.com/doc/brand/4015415289 34 "1DDE55AD98Exxxxxxxxxx", // 品牌API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015407570 35 "/path/to/apiclient_key.pem", // 品牌API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015453439 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 CreateProductCouponRequest request = new CreateProductCouponRequest(); 41 request.outRequestNo = "12345_20250101_A3489"; 42 request.scope = ProductCouponScope.ALL; 43 request.type = ProductCouponType.DISCOUNT; 44 request.usageMode = UsageMode.SINGLE; 45 request.singleUsageInfo = new SingleUsageInfo(); 46 request.singleUsageInfo.discountCoupon = new DiscountCouponUsageRule(); 47 request.singleUsageInfo.discountCoupon.threshold = 10000L; 48 request.singleUsageInfo.discountCoupon.percentOff = 20L; 49 request.displayInfo = new ProductCouponDisplayInfo(); 50 request.displayInfo.name = "全场满100立打8折"; 51 request.displayInfo.imageUrl = "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"; 52 request.displayInfo.backgroundUrl = "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"; 53 request.displayInfo.detailImageUrlList = new ArrayList<>(); 54 { 55 request.displayInfo.detailImageUrlList.add("https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"); 56 }; 57 request.outProductNo = "Product_1234567890"; 58 request.stock = new StockForCreate(); 59 request.stock.remark = "8月工作日有效批次"; 60 request.stock.couponCodeMode = CouponCodeMode.UPLOAD; 61 request.stock.stockSendRule = new StockSendRule(); 62 request.stock.stockSendRule.maxCount = 10000000L; 63 request.stock.stockSendRule.maxCountPerUser = 1L; 64 request.stock.singleUsageRule = new SingleUsageRule(); 65 request.stock.singleUsageRule.couponAvailablePeriod = new CouponAvailablePeriod(); 66 request.stock.singleUsageRule.couponAvailablePeriod.availableBeginTime = "2025-08-01T00:00:00+08:00"; 67 request.stock.singleUsageRule.couponAvailablePeriod.availableEndTime = "2025-08-31T23:59:59+08:00"; 68 request.stock.singleUsageRule.couponAvailablePeriod.availableDays = 30L; 69 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod = new FixedWeekPeriod(); 70 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList = new ArrayList<>(); 71 { 72 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList.add(WeekEnum.MONDAY); 73 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList.add(WeekEnum.TUESDAY); 74 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList.add(WeekEnum.WEDNESDAY); 75 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList.add(WeekEnum.THURSDAY); 76 request.stock.singleUsageRule.couponAvailablePeriod.weeklyAvailablePeriod.dayList.add(WeekEnum.FRIDAY); 77 }; 78 request.stock.usageRuleDisplayInfo = new UsageRuleDisplayInfo(); 79 request.stock.usageRuleDisplayInfo.couponUsageMethodList = new ArrayList<>(); 80 { 81 request.stock.usageRuleDisplayInfo.couponUsageMethodList.add(CouponUsageMethod.OFFLINE); 82 request.stock.usageRuleDisplayInfo.couponUsageMethodList.add(CouponUsageMethod.MINI_PROGRAM); 83 request.stock.usageRuleDisplayInfo.couponUsageMethodList.add(CouponUsageMethod.PAYMENT_CODE); 84 }; 85 request.stock.usageRuleDisplayInfo.miniProgramAppid = "wx1234567890"; 86 request.stock.usageRuleDisplayInfo.miniProgramPath = "/pages/index/product"; 87 request.stock.usageRuleDisplayInfo.usageDescription = "工作日可用"; 88 request.stock.usageRuleDisplayInfo.couponAvailableStoreInfo = new CouponAvailableStoreInfo(); 89 request.stock.usageRuleDisplayInfo.couponAvailableStoreInfo.description = "所有门店可用,可使用小程序查看门店列表"; 90 request.stock.usageRuleDisplayInfo.couponAvailableStoreInfo.miniProgramAppid = "wx1234567890"; 91 request.stock.usageRuleDisplayInfo.couponAvailableStoreInfo.miniProgramPath = "/pages/index/store-list"; 92 request.stock.couponDisplayInfo = new CouponDisplayInfo(); 93 request.stock.couponDisplayInfo.codeDisplayMode = CouponCodeDisplayMode.QRCODE; 94 request.stock.couponDisplayInfo.backgroundColor = "Color010"; 95 request.stock.couponDisplayInfo.entranceMiniProgram = new EntranceMiniProgram(); 96 request.stock.couponDisplayInfo.entranceMiniProgram.appid = "wx1234567890"; 97 request.stock.couponDisplayInfo.entranceMiniProgram.path = "/pages/index/product"; 98 request.stock.couponDisplayInfo.entranceMiniProgram.entranceWording = "欢迎选购"; 99 request.stock.couponDisplayInfo.entranceMiniProgram.guidanceWording = "获取更多优惠"; 100 request.stock.couponDisplayInfo.entranceOfficialAccount = new EntranceOfficialAccount(); 101 request.stock.couponDisplayInfo.entranceOfficialAccount.appid = "wx1234567890"; 102 request.stock.couponDisplayInfo.entranceFinder = new EntranceFinder(); 103 request.stock.couponDisplayInfo.entranceFinder.finderId = "gh_12345678"; 104 request.stock.couponDisplayInfo.entranceFinder.finderVideoId = "UDFsdf24df34dD456Hdf34"; 105 request.stock.couponDisplayInfo.entranceFinder.finderVideoCoverImageUrl = "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"; 106 request.stock.notifyConfig = new NotifyConfig(); 107 request.stock.notifyConfig.notifyAppid = "wx4fd12345678"; 108 request.stock.storeScope = StockStoreScope.NONE; 109 try { 110 CreateProductCouponResponse response = client.run(request); 111 // TODO: 请求成功,继续业务逻辑 112 System.out.println(response); 113 } catch (WXPayBrandUtility.ApiException e) { 114 // TODO: 请求失败,根据状态码执行不同的逻辑 115 e.printStackTrace(); 116 } 117 } 118 119 public CreateProductCouponResponse run(CreateProductCouponRequest request) { 120 String uri = PATH; 121 String reqBody = WXPayBrandUtility.toJson(request); 122 123 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 124 reqBuilder.addHeader("Accept", "application/json"); 125 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 126 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 127 reqBuilder.addHeader("Content-Type", "application/json"); 128 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 129 reqBuilder.method(METHOD, requestBody); 130 Request httpRequest = reqBuilder.build(); 131 132 // 发送HTTP请求 133 OkHttpClient client = new OkHttpClient.Builder().build(); 134 try (Response httpResponse = client.newCall(httpRequest).execute()) { 135 String respBody = WXPayBrandUtility.extractBody(httpResponse); 136 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 137 // 2XX 成功,验证应答签名 138 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 139 httpResponse.headers(), respBody); 140 141 // 从HTTP应答报文构建返回数据 142 return WXPayBrandUtility.fromJson(respBody, CreateProductCouponResponse.class); 143 } else { 144 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 145 } 146 } catch (IOException e) { 147 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 148 } 149 } 150 151 private final String brand_id; 152 private final String certificateSerialNo; 153 private final PrivateKey privateKey; 154 private final String wechatPayPublicKeyId; 155 private final PublicKey wechatPayPublicKey; 156 157 public CreateProductCoupon(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 158 this.brand_id = brand_id; 159 this.certificateSerialNo = certificateSerialNo; 160 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 161 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 162 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 163 } 164 165 public static class CreateProductCouponRequest { 166 @SerializedName("out_request_no") 167 public String outRequestNo; 168 169 @SerializedName("scope") 170 public ProductCouponScope scope; 171 172 @SerializedName("type") 173 public ProductCouponType type; 174 175 @SerializedName("usage_mode") 176 public UsageMode usageMode; 177 178 @SerializedName("single_usage_info") 179 public SingleUsageInfo singleUsageInfo; 180 181 @SerializedName("progressive_bundle_usage_info") 182 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 183 184 @SerializedName("display_info") 185 public ProductCouponDisplayInfo displayInfo; 186 187 @SerializedName("out_product_no") 188 public String outProductNo; 189 190 @SerializedName("stock") 191 public StockForCreate stock; 192 193 @SerializedName("stock_bundle") 194 public StockBundleForCreate stockBundle; 195 } 196 197 public static class CreateProductCouponResponse { 198 @SerializedName("product_coupon_id") 199 public String productCouponId; 200 201 @SerializedName("scope") 202 public ProductCouponScope scope; 203 204 @SerializedName("type") 205 public ProductCouponType type; 206 207 @SerializedName("usage_mode") 208 public UsageMode usageMode; 209 210 @SerializedName("single_usage_info") 211 public SingleUsageInfo singleUsageInfo; 212 213 @SerializedName("progressive_bundle_usage_info") 214 public ProgressiveBundleUsageInfo progressiveBundleUsageInfo; 215 216 @SerializedName("display_info") 217 public ProductCouponDisplayInfo displayInfo; 218 219 @SerializedName("out_product_no") 220 public String outProductNo; 221 222 @SerializedName("state") 223 public ProductCouponState state; 224 225 @SerializedName("stock") 226 public StockEntity stock; 227 228 @SerializedName("stock_bundle") 229 public StockBundleEntity stockBundle; 230 } 231 232 public enum ProductCouponScope { 233 @SerializedName("ALL") 234 ALL, 235 @SerializedName("SINGLE") 236 SINGLE 237 } 238 239 public enum ProductCouponType { 240 @SerializedName("NORMAL") 241 NORMAL, 242 @SerializedName("DISCOUNT") 243 DISCOUNT, 244 @SerializedName("EXCHANGE") 245 EXCHANGE 246 } 247 248 public enum UsageMode { 249 @SerializedName("SINGLE") 250 SINGLE, 251 @SerializedName("PROGRESSIVE_BUNDLE") 252 PROGRESSIVE_BUNDLE 253 } 254 255 public static class SingleUsageInfo { 256 @SerializedName("normal_coupon") 257 public NormalCouponUsageRule normalCoupon; 258 259 @SerializedName("discount_coupon") 260 public DiscountCouponUsageRule discountCoupon; 261 } 262 263 public static class ProgressiveBundleUsageInfo { 264 @SerializedName("count") 265 public Long count; 266 267 @SerializedName("interval_days") 268 public Long intervalDays; 269 } 270 271 public static class ProductCouponDisplayInfo { 272 @SerializedName("name") 273 public String name; 274 275 @SerializedName("image_url") 276 public String imageUrl; 277 278 @SerializedName("background_url") 279 public String backgroundUrl; 280 281 @SerializedName("detail_image_url_list") 282 public List<String> detailImageUrlList; 283 284 @SerializedName("original_price") 285 public Long originalPrice; 286 287 @SerializedName("combo_package_list") 288 public List<ComboPackage> comboPackageList; 289 } 290 291 public static class StockForCreate { 292 @SerializedName("remark") 293 public String remark; 294 295 @SerializedName("coupon_code_mode") 296 public CouponCodeMode couponCodeMode; 297 298 @SerializedName("stock_send_rule") 299 public StockSendRule stockSendRule; 300 301 @SerializedName("single_usage_rule") 302 public SingleUsageRule singleUsageRule; 303 304 @SerializedName("usage_rule_display_info") 305 public UsageRuleDisplayInfo usageRuleDisplayInfo; 306 307 @SerializedName("coupon_display_info") 308 public CouponDisplayInfo couponDisplayInfo; 309 310 @SerializedName("notify_config") 311 public NotifyConfig notifyConfig; 312 313 @SerializedName("store_scope") 314 public StockStoreScope storeScope; 315 } 316 317 public static class StockBundleForCreate { 318 @SerializedName("remark") 319 public String remark; 320 321 @SerializedName("coupon_code_mode") 322 public CouponCodeMode couponCodeMode; 323 324 @SerializedName("stock_send_rule") 325 public StockSendRule stockSendRule; 326 327 @SerializedName("progressive_bundle_usage_rule") 328 public StockBundleUsageRule progressiveBundleUsageRule; 329 330 @SerializedName("usage_rule_display_info") 331 public UsageRuleDisplayInfo usageRuleDisplayInfo; 332 333 @SerializedName("coupon_display_info") 334 public CouponDisplayInfo couponDisplayInfo; 335 336 @SerializedName("notify_config") 337 public NotifyConfig notifyConfig; 338 339 @SerializedName("store_scope") 340 public StockStoreScope storeScope; 341 } 342 343 public enum ProductCouponState { 344 @SerializedName("AUDITING") 345 AUDITING, 346 @SerializedName("EFFECTIVE") 347 EFFECTIVE, 348 @SerializedName("DEACTIVATED") 349 DEACTIVATED 350 } 351 352 public static class StockEntity { 353 @SerializedName("product_coupon_id") 354 public String productCouponId; 355 356 @SerializedName("stock_id") 357 public String stockId; 358 359 @SerializedName("remark") 360 public String remark; 361 362 @SerializedName("coupon_code_mode") 363 public CouponCodeMode couponCodeMode; 364 365 @SerializedName("coupon_code_count_info") 366 public CouponCodeCountInfo couponCodeCountInfo; 367 368 @SerializedName("stock_send_rule") 369 public StockSendRule stockSendRule; 370 371 @SerializedName("single_usage_rule") 372 public SingleUsageRule singleUsageRule; 373 374 @SerializedName("usage_rule_display_info") 375 public UsageRuleDisplayInfo usageRuleDisplayInfo; 376 377 @SerializedName("coupon_display_info") 378 public CouponDisplayInfo couponDisplayInfo; 379 380 @SerializedName("notify_config") 381 public NotifyConfig notifyConfig; 382 383 @SerializedName("store_scope") 384 public StockStoreScope storeScope; 385 386 @SerializedName("sent_count_info") 387 public StockSentCountInfo sentCountInfo; 388 389 @SerializedName("state") 390 public StockState state; 391 392 @SerializedName("deactivate_request_no") 393 public String deactivateRequestNo; 394 395 @SerializedName("deactivate_time") 396 public String deactivateTime; 397 398 @SerializedName("deactivate_reason") 399 public String deactivateReason; 400 } 401 402 public static class StockBundleEntity { 403 @SerializedName("stock_bundle_id") 404 public String stockBundleId; 405 406 @SerializedName("stock_list") 407 public List<StockEntityInBundle> stockList = new ArrayList<StockEntityInBundle>(); 408 } 409 410 public static class NormalCouponUsageRule { 411 @SerializedName("threshold") 412 public Long threshold; 413 414 @SerializedName("discount_amount") 415 public Long discountAmount; 416 } 417 418 public static class DiscountCouponUsageRule { 419 @SerializedName("threshold") 420 public Long threshold; 421 422 @SerializedName("percent_off") 423 public Long percentOff; 424 } 425 426 public static class ComboPackage { 427 @SerializedName("name") 428 public String name; 429 430 @SerializedName("pick_count") 431 public Long pickCount; 432 433 @SerializedName("choice_list") 434 public List<ComboPackageChoice> choiceList = new ArrayList<ComboPackageChoice>(); 435 } 436 437 public enum CouponCodeMode { 438 @SerializedName("WECHATPAY") 439 WECHATPAY, 440 @SerializedName("UPLOAD") 441 UPLOAD, 442 @SerializedName("API_ASSIGN") 443 API_ASSIGN 444 } 445 446 public static class StockSendRule { 447 @SerializedName("max_count") 448 public Long maxCount; 449 450 @SerializedName("max_count_per_day") 451 public Long maxCountPerDay; 452 453 @SerializedName("max_count_per_user") 454 public Long maxCountPerUser; 455 } 456 457 public static class SingleUsageRule { 458 @SerializedName("coupon_available_period") 459 public CouponAvailablePeriod couponAvailablePeriod; 460 461 @SerializedName("normal_coupon") 462 public NormalCouponUsageRule normalCoupon; 463 464 @SerializedName("discount_coupon") 465 public DiscountCouponUsageRule discountCoupon; 466 467 @SerializedName("exchange_coupon") 468 public ExchangeCouponUsageRule exchangeCoupon; 469 } 470 471 public static class UsageRuleDisplayInfo { 472 @SerializedName("coupon_usage_method_list") 473 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 474 475 @SerializedName("mini_program_appid") 476 public String miniProgramAppid; 477 478 @SerializedName("mini_program_path") 479 public String miniProgramPath; 480 481 @SerializedName("app_path") 482 public String appPath; 483 484 @SerializedName("usage_description") 485 public String usageDescription; 486 487 @SerializedName("coupon_available_store_info") 488 public CouponAvailableStoreInfo couponAvailableStoreInfo; 489 } 490 491 public static class CouponDisplayInfo { 492 @SerializedName("code_display_mode") 493 public CouponCodeDisplayMode codeDisplayMode; 494 495 @SerializedName("background_color") 496 public String backgroundColor; 497 498 @SerializedName("entrance_mini_program") 499 public EntranceMiniProgram entranceMiniProgram; 500 501 @SerializedName("entrance_official_account") 502 public EntranceOfficialAccount entranceOfficialAccount; 503 504 @SerializedName("entrance_finder") 505 public EntranceFinder entranceFinder; 506 } 507 508 public static class NotifyConfig { 509 @SerializedName("notify_appid") 510 public String notifyAppid; 511 } 512 513 public enum StockStoreScope { 514 @SerializedName("NONE") 515 NONE, 516 @SerializedName("ALL") 517 ALL, 518 @SerializedName("SPECIFIC") 519 SPECIFIC 520 } 521 522 public static class StockBundleUsageRule { 523 @SerializedName("coupon_available_period") 524 public CouponAvailablePeriod couponAvailablePeriod; 525 526 @SerializedName("normal_coupon_list") 527 public List<NormalCouponUsageRule> normalCouponList; 528 529 @SerializedName("discount_coupon_list") 530 public List<DiscountCouponUsageRule> discountCouponList; 531 532 @SerializedName("exchange_coupon_list") 533 public List<ExchangeCouponUsageRule> exchangeCouponList; 534 } 535 536 public static class CouponCodeCountInfo { 537 @SerializedName("total_count") 538 public Long totalCount; 539 540 @SerializedName("available_count") 541 public Long availableCount; 542 } 543 544 public static class StockSentCountInfo { 545 @SerializedName("total_count") 546 public Long totalCount; 547 548 @SerializedName("today_count") 549 public Long todayCount; 550 } 551 552 public enum StockState { 553 @SerializedName("AUDITING") 554 AUDITING, 555 @SerializedName("SENDING") 556 SENDING, 557 @SerializedName("PAUSED") 558 PAUSED, 559 @SerializedName("STOPPED") 560 STOPPED, 561 @SerializedName("DEACTIVATED") 562 DEACTIVATED 563 } 564 565 public static class StockEntityInBundle { 566 @SerializedName("product_coupon_id") 567 public String productCouponId; 568 569 @SerializedName("stock_id") 570 public String stockId; 571 572 @SerializedName("remark") 573 public String remark; 574 575 @SerializedName("coupon_code_mode") 576 public CouponCodeMode couponCodeMode; 577 578 @SerializedName("coupon_code_count_info") 579 public CouponCodeCountInfo couponCodeCountInfo; 580 581 @SerializedName("stock_send_rule") 582 public StockSendRule stockSendRule; 583 584 @SerializedName("progressive_bundle_usage_rule") 585 public StockUsageRule progressiveBundleUsageRule; 586 587 @SerializedName("stock_bundle_info") 588 public StockBundleInfo stockBundleInfo; 589 590 @SerializedName("usage_rule_display_info") 591 public UsageRuleDisplayInfo usageRuleDisplayInfo; 592 593 @SerializedName("coupon_display_info") 594 public CouponDisplayInfo couponDisplayInfo; 595 596 @SerializedName("notify_config") 597 public NotifyConfig notifyConfig; 598 599 @SerializedName("store_scope") 600 public StockStoreScope storeScope; 601 602 @SerializedName("sent_count_info") 603 public StockSentCountInfo sentCountInfo; 604 605 @SerializedName("state") 606 public StockState state; 607 608 @SerializedName("deactivate_request_no") 609 public String deactivateRequestNo; 610 611 @SerializedName("deactivate_time") 612 public String deactivateTime; 613 614 @SerializedName("deactivate_reason") 615 public String deactivateReason; 616 } 617 618 public static class ComboPackageChoice { 619 @SerializedName("name") 620 public String name; 621 622 @SerializedName("price") 623 public Long price; 624 625 @SerializedName("count") 626 public Long count; 627 628 @SerializedName("image_url") 629 public String imageUrl; 630 631 @SerializedName("mini_program_appid") 632 public String miniProgramAppid; 633 634 @SerializedName("mini_program_path") 635 public String miniProgramPath; 636 } 637 638 public static class CouponAvailablePeriod { 639 @SerializedName("available_begin_time") 640 public String availableBeginTime; 641 642 @SerializedName("available_end_time") 643 public String availableEndTime; 644 645 @SerializedName("available_days") 646 public Long availableDays; 647 648 @SerializedName("wait_days_after_receive") 649 public Long waitDaysAfterReceive; 650 651 @SerializedName("weekly_available_period") 652 public FixedWeekPeriod weeklyAvailablePeriod; 653 654 @SerializedName("irregular_available_period_list") 655 public List<TimePeriod> irregularAvailablePeriodList; 656 } 657 658 public static class ExchangeCouponUsageRule { 659 @SerializedName("threshold") 660 public Long threshold; 661 662 @SerializedName("exchange_price") 663 public Long exchangePrice; 664 } 665 666 public enum CouponUsageMethod { 667 @SerializedName("OFFLINE") 668 OFFLINE, 669 @SerializedName("MINI_PROGRAM") 670 MINI_PROGRAM, 671 @SerializedName("APP") 672 APP, 673 @SerializedName("PAYMENT_CODE") 674 PAYMENT_CODE 675 } 676 677 public static class CouponAvailableStoreInfo { 678 @SerializedName("description") 679 public String description; 680 681 @SerializedName("mini_program_appid") 682 public String miniProgramAppid; 683 684 @SerializedName("mini_program_path") 685 public String miniProgramPath; 686 } 687 688 public enum CouponCodeDisplayMode { 689 @SerializedName("INVISIBLE") 690 INVISIBLE, 691 @SerializedName("BARCODE") 692 BARCODE, 693 @SerializedName("QRCODE") 694 QRCODE 695 } 696 697 public static class EntranceMiniProgram { 698 @SerializedName("appid") 699 public String appid; 700 701 @SerializedName("path") 702 public String path; 703 704 @SerializedName("entrance_wording") 705 public String entranceWording; 706 707 @SerializedName("guidance_wording") 708 public String guidanceWording; 709 } 710 711 public static class EntranceOfficialAccount { 712 @SerializedName("appid") 713 public String appid; 714 } 715 716 public static class EntranceFinder { 717 @SerializedName("finder_id") 718 public String finderId; 719 720 @SerializedName("finder_video_id") 721 public String finderVideoId; 722 723 @SerializedName("finder_video_cover_image_url") 724 public String finderVideoCoverImageUrl; 725 } 726 727 public static class StockUsageRule { 728 @SerializedName("coupon_available_period") 729 public CouponAvailablePeriod couponAvailablePeriod; 730 731 @SerializedName("normal_coupon") 732 public NormalCouponUsageRule normalCoupon; 733 734 @SerializedName("discount_coupon") 735 public DiscountCouponUsageRule discountCoupon; 736 737 @SerializedName("exchange_coupon") 738 public ExchangeCouponUsageRule exchangeCoupon; 739 } 740 741 public static class StockBundleInfo { 742 @SerializedName("stock_bundle_id") 743 public String stockBundleId; 744 745 @SerializedName("stock_bundle_index") 746 public Long stockBundleIndex; 747 } 748 749 public static class FixedWeekPeriod { 750 @SerializedName("day_list") 751 public List<WeekEnum> dayList; 752 753 @SerializedName("day_period_list") 754 public List<PeriodOfTheDay> dayPeriodList; 755 } 756 757 public static class TimePeriod { 758 @SerializedName("begin_time") 759 public String beginTime; 760 761 @SerializedName("end_time") 762 public String endTime; 763 } 764 765 public enum WeekEnum { 766 @SerializedName("MONDAY") 767 MONDAY, 768 @SerializedName("TUESDAY") 769 TUESDAY, 770 @SerializedName("WEDNESDAY") 771 WEDNESDAY, 772 @SerializedName("THURSDAY") 773 THURSDAY, 774 @SerializedName("FRIDAY") 775 FRIDAY, 776 @SerializedName("SATURDAY") 777 SATURDAY, 778 @SerializedName("SUNDAY") 779 SUNDAY 780 } 781 782 public static class PeriodOfTheDay { 783 @SerializedName("begin_time") 784 public Long beginTime; 785 786 @SerializedName("end_time") 787 public Long endTime; 788 } 789 790} 791
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_brand_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/brand/4015826866 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "time" 11) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 15 config, err := wxpay_brand_utility.CreateBrandConfig( 16 "xxxxxxxx", // 品牌ID,是由微信支付系统生成并分配给每个品牌方的唯一标识符,品牌ID获取方式参考 https://pay.weixin.qq.com/doc/brand/4015415289 17 "1DDE55AD98Exxxxxxxxxx", // 品牌API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015407570 18 "/path/to/apiclient_key.pem", // 品牌API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015453439 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &CreateProductCouponRequest{ 28 OutRequestNo: wxpay_brand_utility.String("12345_20250101_A3489"), 29 Scope: PRODUCTCOUPONSCOPE_ALL.Ptr(), 30 Type: PRODUCTCOUPONTYPE_DISCOUNT.Ptr(), 31 UsageMode: USAGEMODE_SINGLE.Ptr(), 32 SingleUsageInfo: &SingleUsageInfo{ 33 DiscountCoupon: &DiscountCouponUsageRule{ 34 Threshold: wxpay_brand_utility.Int64(10000), 35 PercentOff: wxpay_brand_utility.Int64(20), 36 }, 37 }, 38 DisplayInfo: &ProductCouponDisplayInfo{ 39 Name: wxpay_brand_utility.String("全场满100立打8折"), 40 ImageUrl: wxpay_brand_utility.String("https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"), 41 BackgroundUrl: wxpay_brand_utility.String("https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"), 42 DetailImageUrlList: []string{ 43 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 44 }, 45 }, 46 OutProductNo: wxpay_brand_utility.String("Product_1234567890"), 47 Stock: &StockForCreate{ 48 Remark: wxpay_brand_utility.String("8月工作日有效批次"), 49 CouponCodeMode: COUPONCODEMODE_UPLOAD.Ptr(), 50 StockSendRule: &StockSendRule{ 51 MaxCount: wxpay_brand_utility.Int64(10000000), 52 MaxCountPerUser: wxpay_brand_utility.Int64(1), 53 }, 54 SingleUsageRule: &SingleUsageRule{ 55 CouponAvailablePeriod: &CouponAvailablePeriod{ 56 AvailableBeginTime: wxpay_brand_utility.String("2025-08-01T00:00:00+08:00"), 57 AvailableEndTime: wxpay_brand_utility.String("2025-08-31T23:59:59+08:00"), 58 AvailableDays: wxpay_brand_utility.Int64(30), 59 WeeklyAvailablePeriod: &FixedWeekPeriod{ 60 DayList: []WeekEnum{ 61 WEEKENUM_MONDAY, 62 WEEKENUM_TUESDAY, 63 WEEKENUM_WEDNESDAY, 64 WEEKENUM_THURSDAY, 65 WEEKENUM_FRIDAY, 66 }, 67 }, 68 }, 69 }, 70 UsageRuleDisplayInfo: &UsageRuleDisplayInfo{ 71 CouponUsageMethodList: []CouponUsageMethod{ 72 COUPONUSAGEMETHOD_OFFLINE, 73 COUPONUSAGEMETHOD_MINI_PROGRAM, 74 COUPONUSAGEMETHOD_PAYMENT_CODE, 75 }, 76 MiniProgramAppid: wxpay_brand_utility.String("wx1234567890"), 77 MiniProgramPath: wxpay_brand_utility.String("/pages/index/product"), 78 UsageDescription: wxpay_brand_utility.String("工作日可用"), 79 CouponAvailableStoreInfo: &CouponAvailableStoreInfo{ 80 Description: wxpay_brand_utility.String("所有门店可用,可使用小程序查看门店列表"), 81 MiniProgramAppid: wxpay_brand_utility.String("wx1234567890"), 82 MiniProgramPath: wxpay_brand_utility.String("/pages/index/store-list"), 83 }, 84 }, 85 CouponDisplayInfo: &CouponDisplayInfo{ 86 CodeDisplayMode: COUPONCODEDISPLAYMODE_QRCODE.Ptr(), 87 BackgroundColor: wxpay_brand_utility.String("Color010"), 88 EntranceMiniProgram: &EntranceMiniProgram{ 89 Appid: wxpay_brand_utility.String("wx1234567890"), 90 Path: wxpay_brand_utility.String("/pages/index/product"), 91 EntranceWording: wxpay_brand_utility.String("欢迎选购"), 92 GuidanceWording: wxpay_brand_utility.String("获取更多优惠"), 93 }, 94 EntranceOfficialAccount: &EntranceOfficialAccount{ 95 Appid: wxpay_brand_utility.String("wx1234567890"), 96 }, 97 EntranceFinder: &EntranceFinder{ 98 FinderId: wxpay_brand_utility.String("gh_12345678"), 99 FinderVideoId: wxpay_brand_utility.String("UDFsdf24df34dD456Hdf34"), 100 FinderVideoCoverImageUrl: wxpay_brand_utility.String("https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"), 101 }, 102 }, 103 NotifyConfig: &NotifyConfig{ 104 NotifyAppid: wxpay_brand_utility.String("wx4fd12345678"), 105 }, 106 StoreScope: STOCKSTORESCOPE_NONE.Ptr(), 107 }, 108 } 109 110 response, err := CreateProductCoupon(config, request) 111 if err != nil { 112 fmt.Printf("请求失败: %+v\n", err) 113 // TODO: 请求失败,根据状态码执行不同的处理 114 return 115 } 116 117 // TODO: 请求成功,继续业务逻辑 118 fmt.Printf("请求成功: %+v\n", response) 119} 120 121func CreateProductCoupon(config *wxpay_brand_utility.BrandConfig, request *CreateProductCouponRequest) (response *CreateProductCouponResponse, err error) { 122 const ( 123 host = "https://api.mch.weixin.qq.com" 124 method = "POST" 125 path = "/brand/marketing/product-coupon/product-coupons" 126 ) 127 128 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 129 if err != nil { 130 return nil, err 131 } 132 reqBody, err := json.Marshal(request) 133 if err != nil { 134 return nil, err 135 } 136 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 137 if err != nil { 138 return nil, err 139 } 140 httpRequest.Header.Set("Accept", "application/json") 141 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 142 httpRequest.Header.Set("Content-Type", "application/json") 143 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 144 if err != nil { 145 return nil, err 146 } 147 httpRequest.Header.Set("Authorization", authorization) 148 149 client := &http.Client{} 150 httpResponse, err := client.Do(httpRequest) 151 if err != nil { 152 return nil, err 153 } 154 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 155 if err != nil { 156 return nil, err 157 } 158 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 159 // 2XX 成功,验证应答签名 160 err = wxpay_brand_utility.ValidateResponse( 161 config.WechatPayPublicKeyId(), 162 config.WechatPayPublicKey(), 163 &httpResponse.Header, 164 respBody, 165 ) 166 if err != nil { 167 return nil, err 168 } 169 response := &CreateProductCouponResponse{} 170 if err := json.Unmarshal(respBody, response); err != nil { 171 return nil, err 172 } 173 174 return response, nil 175 } else { 176 return nil, wxpay_brand_utility.NewApiException( 177 httpResponse.StatusCode, 178 httpResponse.Header, 179 respBody, 180 ) 181 } 182} 183 184type CreateProductCouponRequest struct { 185 OutRequestNo *string `json:"out_request_no,omitempty"` 186 Scope *ProductCouponScope `json:"scope,omitempty"` 187 Type *ProductCouponType `json:"type,omitempty"` 188 UsageMode *UsageMode `json:"usage_mode,omitempty"` 189 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 190 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 191 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 192 OutProductNo *string `json:"out_product_no,omitempty"` 193 Stock *StockForCreate `json:"stock,omitempty"` 194 StockBundle *StockBundleForCreate `json:"stock_bundle,omitempty"` 195} 196 197type CreateProductCouponResponse struct { 198 ProductCouponId *string `json:"product_coupon_id,omitempty"` 199 Scope *ProductCouponScope `json:"scope,omitempty"` 200 Type *ProductCouponType `json:"type,omitempty"` 201 UsageMode *UsageMode `json:"usage_mode,omitempty"` 202 SingleUsageInfo *SingleUsageInfo `json:"single_usage_info,omitempty"` 203 ProgressiveBundleUsageInfo *ProgressiveBundleUsageInfo `json:"progressive_bundle_usage_info,omitempty"` 204 DisplayInfo *ProductCouponDisplayInfo `json:"display_info,omitempty"` 205 OutProductNo *string `json:"out_product_no,omitempty"` 206 State *ProductCouponState `json:"state,omitempty"` 207 Stock *StockEntity `json:"stock,omitempty"` 208 StockBundle *StockBundleEntity `json:"stock_bundle,omitempty"` 209} 210 211type ProductCouponScope string 212 213func (e ProductCouponScope) Ptr() *ProductCouponScope { 214 return &e 215} 216 217const ( 218 PRODUCTCOUPONSCOPE_ALL ProductCouponScope = "ALL" 219 PRODUCTCOUPONSCOPE_SINGLE ProductCouponScope = "SINGLE" 220) 221 222type ProductCouponType string 223 224func (e ProductCouponType) Ptr() *ProductCouponType { 225 return &e 226} 227 228const ( 229 PRODUCTCOUPONTYPE_NORMAL ProductCouponType = "NORMAL" 230 PRODUCTCOUPONTYPE_DISCOUNT ProductCouponType = "DISCOUNT" 231 PRODUCTCOUPONTYPE_EXCHANGE ProductCouponType = "EXCHANGE" 232) 233 234type UsageMode string 235 236func (e UsageMode) Ptr() *UsageMode { 237 return &e 238} 239 240const ( 241 USAGEMODE_SINGLE UsageMode = "SINGLE" 242 USAGEMODE_PROGRESSIVE_BUNDLE UsageMode = "PROGRESSIVE_BUNDLE" 243) 244 245type SingleUsageInfo struct { 246 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 247 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 248} 249 250type ProgressiveBundleUsageInfo struct { 251 Count *int64 `json:"count,omitempty"` 252 IntervalDays *int64 `json:"interval_days,omitempty"` 253} 254 255type ProductCouponDisplayInfo struct { 256 Name *string `json:"name,omitempty"` 257 ImageUrl *string `json:"image_url,omitempty"` 258 BackgroundUrl *string `json:"background_url,omitempty"` 259 DetailImageUrlList []string `json:"detail_image_url_list,omitempty"` 260 OriginalPrice *int64 `json:"original_price,omitempty"` 261 ComboPackageList []ComboPackage `json:"combo_package_list,omitempty"` 262} 263 264type StockForCreate struct { 265 Remark *string `json:"remark,omitempty"` 266 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 267 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 268 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 269 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 270 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 271 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 272 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 273} 274 275type StockBundleForCreate struct { 276 Remark *string `json:"remark,omitempty"` 277 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 278 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 279 ProgressiveBundleUsageRule *StockBundleUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 280 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 281 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 282 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 283 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 284} 285 286type ProductCouponState string 287 288func (e ProductCouponState) Ptr() *ProductCouponState { 289 return &e 290} 291 292const ( 293 PRODUCTCOUPONSTATE_AUDITING ProductCouponState = "AUDITING" 294 PRODUCTCOUPONSTATE_EFFECTIVE ProductCouponState = "EFFECTIVE" 295 PRODUCTCOUPONSTATE_DEACTIVATED ProductCouponState = "DEACTIVATED" 296) 297 298type StockEntity struct { 299 ProductCouponId *string `json:"product_coupon_id,omitempty"` 300 StockId *string `json:"stock_id,omitempty"` 301 Remark *string `json:"remark,omitempty"` 302 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 303 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 304 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 305 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 306 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 307 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 308 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 309 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 310 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 311 State *StockState `json:"state,omitempty"` 312 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 313 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 314 DeactivateReason *string `json:"deactivate_reason,omitempty"` 315} 316 317type StockBundleEntity struct { 318 StockBundleId *string `json:"stock_bundle_id,omitempty"` 319 StockList []StockEntityInBundle `json:"stock_list,omitempty"` 320} 321 322type NormalCouponUsageRule struct { 323 Threshold *int64 `json:"threshold,omitempty"` 324 DiscountAmount *int64 `json:"discount_amount,omitempty"` 325} 326 327type DiscountCouponUsageRule struct { 328 Threshold *int64 `json:"threshold,omitempty"` 329 PercentOff *int64 `json:"percent_off,omitempty"` 330} 331 332type ComboPackage struct { 333 Name *string `json:"name,omitempty"` 334 PickCount *int64 `json:"pick_count,omitempty"` 335 ChoiceList []ComboPackageChoice `json:"choice_list,omitempty"` 336} 337 338type CouponCodeMode string 339 340func (e CouponCodeMode) Ptr() *CouponCodeMode { 341 return &e 342} 343 344const ( 345 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 346 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 347 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 348) 349 350type StockSendRule struct { 351 MaxCount *int64 `json:"max_count,omitempty"` 352 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 353 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 354} 355 356type SingleUsageRule struct { 357 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 358 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 359 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 360 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,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 StockBundleUsageRule struct { 397 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 398 NormalCouponList []NormalCouponUsageRule `json:"normal_coupon_list,omitempty"` 399 DiscountCouponList []DiscountCouponUsageRule `json:"discount_coupon_list,omitempty"` 400 ExchangeCouponList []ExchangeCouponUsageRule `json:"exchange_coupon_list,omitempty"` 401} 402 403type CouponCodeCountInfo struct { 404 TotalCount *int64 `json:"total_count,omitempty"` 405 AvailableCount *int64 `json:"available_count,omitempty"` 406} 407 408type StockSentCountInfo struct { 409 TotalCount *int64 `json:"total_count,omitempty"` 410 TodayCount *int64 `json:"today_count,omitempty"` 411} 412 413type StockState string 414 415func (e StockState) Ptr() *StockState { 416 return &e 417} 418 419const ( 420 STOCKSTATE_AUDITING StockState = "AUDITING" 421 STOCKSTATE_SENDING StockState = "SENDING" 422 STOCKSTATE_PAUSED StockState = "PAUSED" 423 STOCKSTATE_STOPPED StockState = "STOPPED" 424 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 425) 426 427type StockEntityInBundle struct { 428 ProductCouponId *string `json:"product_coupon_id,omitempty"` 429 StockId *string `json:"stock_id,omitempty"` 430 Remark *string `json:"remark,omitempty"` 431 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 432 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 433 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 434 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 435 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 436 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 437 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 438 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 439 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 440 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 441 State *StockState `json:"state,omitempty"` 442 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 443 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 444 DeactivateReason *string `json:"deactivate_reason,omitempty"` 445} 446 447type ComboPackageChoice struct { 448 Name *string `json:"name,omitempty"` 449 Price *int64 `json:"price,omitempty"` 450 Count *int64 `json:"count,omitempty"` 451 ImageUrl *string `json:"image_url,omitempty"` 452 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 453 MiniProgramPath *string `json:"mini_program_path,omitempty"` 454} 455 456type CouponAvailablePeriod struct { 457 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 458 AvailableEndTime *string `json:"available_end_time,omitempty"` 459 AvailableDays *int64 `json:"available_days,omitempty"` 460 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 461 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 462 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 463} 464 465type ExchangeCouponUsageRule struct { 466 Threshold *int64 `json:"threshold,omitempty"` 467 ExchangePrice *int64 `json:"exchange_price,omitempty"` 468} 469 470type CouponUsageMethod string 471 472func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 473 return &e 474} 475 476const ( 477 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 478 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 479 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 480 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 481) 482 483type CouponAvailableStoreInfo struct { 484 Description *string `json:"description,omitempty"` 485 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 486 MiniProgramPath *string `json:"mini_program_path,omitempty"` 487} 488 489type CouponCodeDisplayMode string 490 491func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 492 return &e 493} 494 495const ( 496 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 497 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 498 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 499) 500 501type EntranceMiniProgram struct { 502 Appid *string `json:"appid,omitempty"` 503 Path *string `json:"path,omitempty"` 504 EntranceWording *string `json:"entrance_wording,omitempty"` 505 GuidanceWording *string `json:"guidance_wording,omitempty"` 506} 507 508type EntranceOfficialAccount struct { 509 Appid *string `json:"appid,omitempty"` 510} 511 512type EntranceFinder struct { 513 FinderId *string `json:"finder_id,omitempty"` 514 FinderVideoId *string `json:"finder_video_id,omitempty"` 515 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 516} 517 518type StockUsageRule struct { 519 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 520 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 521 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 522 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 523} 524 525type StockBundleInfo struct { 526 StockBundleId *string `json:"stock_bundle_id,omitempty"` 527 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 528} 529 530type FixedWeekPeriod struct { 531 DayList []WeekEnum `json:"day_list,omitempty"` 532 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 533} 534 535type TimePeriod struct { 536 BeginTime *string `json:"begin_time,omitempty"` 537 EndTime *string `json:"end_time,omitempty"` 538} 539 540type WeekEnum string 541 542func (e WeekEnum) Ptr() *WeekEnum { 543 return &e 544} 545 546const ( 547 WEEKENUM_MONDAY WeekEnum = "MONDAY" 548 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 549 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 550 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 551 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 552 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 553 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 554) 555 556type PeriodOfTheDay struct { 557 BeginTime *int64 `json:"begin_time,omitempty"` 558 EndTime *int64 `json:"end_time,omitempty"` 559} 560
应答参数
200 OK
product_coupon_id 必填 string(40)
【商品券ID】 商品券的唯一标识,本接口成功时由微信支付生成
scope 必填 string
【优惠范围】 商品券优惠范围
可选取值
ALL: 全场券,此时券类型type仅可配置为NORMAL或DISCOUNTSINGLE: 单品券,此时券类型type配置不受限制,即可配置为NORMAL、DISCOUNT或EXCHANGE
type 必填 string
【商品券类型】 商品券的优惠类型
可选取值
NORMAL: 满减券DISCOUNT: 折扣券EXCHANGE: 兑换券,仅在scope为SINGLE时可配置
usage_mode 必填 string
【使用模式】 商品券使用模式
可选取值
SINGLE: 单券,即用户只能使用一次,使用后券失效PROGRESSIVE_BUNDLE: 多次优惠,由一组批次组成,每阶梯次序对应一个批次。用户按顺序使用,每次核销后发放下一张券,直到用完为止
single_usage_info 选填 object
【单券模式信息】 单券模式配置信息,仅当 usage_mode 为 SINGLE 时提供,其他模式不提供。
| 属性 | |||||||||
normal_coupon 选填 object 【满减券使用规则】 本商品券内所有批次均以此规则提供满减优惠,当且仅当
discount_coupon 选填 object 【折扣券使用规则】 本商品券内所有批次均以此规则提供折扣优惠,当且仅当
|
progressive_bundle_usage_info 选填 object
【多次优惠模式信息】 多次优惠模式配置信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时提供,其他模式不提供。
| 属性 | |
count 必填 integer 【可使用次数】 多次优惠领取后用户可使用次数,最少3次,最多15次 interval_days 选填 integer 【多次优惠使用间隔天数】 多次优惠多次使用之间需要间隔的天数,最高7天。例如:
默认情况下为 |
display_info 必填 object
【展示信息】 商品券展示信息
| 属性 | |||||||||
name 必填 string(15) 【商品券名称】 商品券名称,长度为3-15个UTF-8字符 image_url 必填 string 【商品券图片】 商品图片的链接地址,仅支持通过【图片上传API】获取的图片URL地址。
background_url 必填 string 【商品券背景图】 商品背景图片的URL地址,仅支持通过【图片上传API】获取的图片URL地址。
detail_image_url_list 选填 array[string] 【商品券详情图列表】 商品详情图URL地址列表,用于最多可上传8张图片,仅支持通过【图片上传API】获取的图片URL地址。
original_price 选填 integer 【商品原价】 单位为分,当且仅当 combo_package_list 选填 array[object] 【套餐组合】 当
|
out_product_no 选填 string
【外部商品ID】 商户创建商品券时主动传入的外部商品ID,原样返回
state 必填 string
【商品券状态】 商品券状态
可选取值
AUDITING: 审批中,审批完成前商品券不可用EFFECTIVE: 生效中,商品券已生效,可以正常使用DEACTIVATED: 已失效,品牌方主动调用失效接口使商品券失效
stock 选填 object
【批次】 商品券批次信息,当且仅当 usage_mode 为 SINGLE 时提供
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 【单券使用规则】 当且仅当
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) 【失效原因】 当且仅当 |
stock_bundle 选填 object
【批次组】 商品券批次组信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时提供,其他模式不提供
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
stock_bundle_id 必填 string(40) 【批次组ID】 商品券批次组的唯一标识,由微信支付生成 stock_list 必填 array[object] 【批次列表】 批次组内批次列表
|
应答示例
200 OK
创建满100可用的全场8折券
1{ 2 "product_coupon_id" : "1000000013", 3 "scope" : "ALL", 4 "type" : "DISCOUNT", 5 "usage_mode" : "SINGLE", 6 "single_usage_info" : { 7 "discount_coupon" : { 8 "threshold" : 10000, 9 "percent_off" : 20 10 } 11 }, 12 "display_info" : { 13 "name" : "全场满100立打8折", 14 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 15 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 16 "detail_image_url_list" : [ 17 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 18 ] 19 }, 20 "state" : "EFFECTIVE", 21 "out_product_no" : "Product_1234567890", 22 "stock" : { 23 "product_coupon_id" : "1000000013", 24 "stock_id" : "1000000013001", 25 "remark" : "8月工作日有效批次", 26 "coupon_code_mode" : "UPLOAD", 27 "coupon_code_count_info" : { 28 "total_count" : 0, 29 "available_count" : 0 30 }, 31 "stock_send_rule" : { 32 "max_count" : 10000000, 33 "max_count_per_user" : 1 34 }, 35 "single_usage_rule" : { 36 "coupon_available_period" : { 37 "available_begin_time" : "2025-08-01T00:00:00+08:00", 38 "available_end_time" : "2025-08-31T23:59:59+08:00", 39 "available_days" : 30, 40 "weekly_available_period" : { 41 "day_list" : [ 42 "MONDAY", 43 "TUESDAY", 44 "WEDNESDAY", 45 "THURSDAY", 46 "FRIDAY" 47 ] 48 } 49 } 50 }, 51 "usage_rule_display_info" : { 52 "coupon_usage_method_list" : [ 53 "OFFLINE", 54 "MINI_PROGRAM", 55 "PAYMENT_CODE" 56 ], 57 "mini_program_appid" : "wx1234567890", 58 "mini_program_path" : "/pages/index/product", 59 "usage_description" : "工作日可用", 60 "coupon_available_store_info" : { 61 "description" : "所有门店可用,可使用小程序查看门店列表", 62 "mini_program_appid" : "wx1234567890", 63 "mini_program_path" : "/pages/index/store-list" 64 } 65 }, 66 "coupon_display_info" : { 67 "code_display_mode" : "QRCODE", 68 "background_color" : "Color010", 69 "entrance_mini_program" : { 70 "appid" : "wx1234567890", 71 "path" : "/pages/index/product", 72 "entrance_wording" : "欢迎选购", 73 "guidance_wording" : "获取更多优惠" 74 }, 75 "entrance_official_account" : { 76 "appid" : "wx1234567890" 77 }, 78 "entrance_finder" : { 79 "finder_id" : "gh_12345678", 80 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 81 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 82 } 83 }, 84 "notify_config" : { 85 "notify_appid" : "wx4fd12345678" 86 }, 87 "store_scope" : "NONE", 88 "sent_count_info" : { 89 "total_count" : 0, 90 "today_count" : 0 91 }, 92 "state" : "SENDING" 93 } 94} 95
创建全场折扣多次优惠券
1{ 2 "product_coupon_id" : "1000000014", 3 "scope" : "ALL", 4 "type" : "DISCOUNT", 5 "usage_mode" : "PROGRESSIVE_BUNDLE", 6 "progressive_bundle_usage_info" : { 7 "count" : 3, 8 "interval_days" : 1 9 }, 10 "display_info" : { 11 "name" : "全场满100立打8折", 12 "image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 13 "background_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx", 14 "detail_image_url_list" : [ 15 "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 16 ] 17 }, 18 "state" : "EFFECTIVE", 19 "out_product_no" : "Product_1234567890", 20 "stock_bundle" : { 21 "stock_bundle_id" : "712315129419284901", 22 "stock_list" : [ 23 { 24 "product_coupon_id" : "1000000014", 25 "stock_id" : "1000000014001", 26 "remark" : "8月工作日有效批次", 27 "coupon_code_mode" : "UPLOAD", 28 "coupon_code_count_info" : { 29 "total_count" : 0, 30 "available_count" : 0 31 }, 32 "stock_send_rule" : { 33 "max_count" : 10000000, 34 "max_count_per_user" : 1 35 }, 36 "progressive_bundle_usage_rule" : { 37 "coupon_available_period" : { 38 "available_begin_time" : "2025-08-01T00:00:00+08:00", 39 "available_end_time" : "2025-08-31T23:59:59+08:00", 40 "available_days" : 30, 41 "weekly_available_period" : { 42 "day_list" : [ 43 "MONDAY", 44 "TUESDAY", 45 "WEDNESDAY", 46 "THURSDAY", 47 "FRIDAY" 48 ] 49 } 50 }, 51 "discount_coupon" : { 52 "threshold" : 10000, 53 "percent_off" : 50 54 } 55 }, 56 "stock_bundle_info" : { 57 "stock_bundle_id" : "712315129419284901", 58 "stock_bundle_index" : 0 59 }, 60 "usage_rule_display_info" : { 61 "coupon_usage_method_list" : [ 62 "OFFLINE", 63 "MINI_PROGRAM", 64 "PAYMENT_CODE" 65 ], 66 "mini_program_appid" : "wx1234567890", 67 "mini_program_path" : "/pages/index/product", 68 "usage_description" : "工作日可用", 69 "coupon_available_store_info" : { 70 "description" : "所有门店可用,可使用小程序查看门店列表", 71 "mini_program_appid" : "wx1234567890", 72 "mini_program_path" : "/pages/index/store-list" 73 } 74 }, 75 "coupon_display_info" : { 76 "code_display_mode" : "QRCODE", 77 "background_color" : "Color010", 78 "entrance_mini_program" : { 79 "appid" : "wx1234567890", 80 "path" : "/pages/index/product", 81 "entrance_wording" : "欢迎选购", 82 "guidance_wording" : "获取更多优惠" 83 }, 84 "entrance_official_account" : { 85 "appid" : "wx1234567890" 86 }, 87 "entrance_finder" : { 88 "finder_id" : "gh_12345678", 89 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 90 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 91 } 92 }, 93 "notify_config" : { 94 "notify_appid" : "wx4fd12345678" 95 }, 96 "store_scope" : "NONE", 97 "sent_count_info" : { 98 "total_count" : 0, 99 "today_count" : 0 100 }, 101 "state" : "SENDING" 102 }, 103 { 104 "product_coupon_id" : "1000000014", 105 "stock_id" : "1000000014002", 106 "remark" : "8月工作日有效批次", 107 "coupon_code_mode" : "UPLOAD", 108 "coupon_code_count_info" : { 109 "total_count" : 0, 110 "available_count" : 0 111 }, 112 "stock_send_rule" : { 113 "max_count" : 10000000, 114 "max_count_per_user" : 1 115 }, 116 "progressive_bundle_usage_rule" : { 117 "coupon_available_period" : { 118 "available_begin_time" : "2025-08-01T00:00:00+08:00", 119 "available_end_time" : "2025-08-31T23:59:59+08:00", 120 "available_days" : 30, 121 "weekly_available_period" : { 122 "day_list" : [ 123 "MONDAY", 124 "TUESDAY", 125 "WEDNESDAY", 126 "THURSDAY", 127 "FRIDAY" 128 ] 129 } 130 }, 131 "discount_coupon" : { 132 "threshold" : 10000, 133 "percent_off" : 20 134 } 135 }, 136 "stock_bundle_info" : { 137 "stock_bundle_id" : "712315129419284901", 138 "stock_bundle_index" : 1 139 }, 140 "usage_rule_display_info" : { 141 "coupon_usage_method_list" : [ 142 "OFFLINE", 143 "MINI_PROGRAM", 144 "PAYMENT_CODE" 145 ], 146 "mini_program_appid" : "wx1234567890", 147 "mini_program_path" : "/pages/index/product", 148 "usage_description" : "工作日可用", 149 "coupon_available_store_info" : { 150 "description" : "所有门店可用,可使用小程序查看门店列表", 151 "mini_program_appid" : "wx1234567890", 152 "mini_program_path" : "/pages/index/store-list" 153 } 154 }, 155 "coupon_display_info" : { 156 "code_display_mode" : "QRCODE", 157 "background_color" : "Color010", 158 "entrance_mini_program" : { 159 "appid" : "wx1234567890", 160 "path" : "/pages/index/product", 161 "entrance_wording" : "欢迎选购", 162 "guidance_wording" : "获取更多优惠" 163 }, 164 "entrance_official_account" : { 165 "appid" : "wx1234567890" 166 }, 167 "entrance_finder" : { 168 "finder_id" : "gh_12345678", 169 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 170 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 171 } 172 }, 173 "notify_config" : { 174 "notify_appid" : "wx4fd12345678" 175 }, 176 "store_scope" : "NONE", 177 "sent_count_info" : { 178 "total_count" : 0, 179 "today_count" : 0 180 }, 181 "state" : "SENDING" 182 }, 183 { 184 "product_coupon_id" : "1000000014", 185 "stock_id" : "1000000014003", 186 "remark" : "8月工作日有效批次", 187 "coupon_code_mode" : "UPLOAD", 188 "coupon_code_count_info" : { 189 "total_count" : 0, 190 "available_count" : 0 191 }, 192 "stock_send_rule" : { 193 "max_count" : 10000000, 194 "max_count_per_user" : 1 195 }, 196 "progressive_bundle_usage_rule" : { 197 "coupon_available_period" : { 198 "available_begin_time" : "2025-08-01T00:00:00+08:00", 199 "available_end_time" : "2025-08-31T23:59:59+08:00", 200 "available_days" : 30, 201 "weekly_available_period" : { 202 "day_list" : [ 203 "MONDAY", 204 "TUESDAY", 205 "WEDNESDAY", 206 "THURSDAY", 207 "FRIDAY" 208 ] 209 } 210 }, 211 "discount_coupon" : { 212 "threshold" : 10000, 213 "percent_off" : 30 214 } 215 }, 216 "stock_bundle_info" : { 217 "stock_bundle_id" : "712315129419284901", 218 "stock_bundle_index" : 2 219 }, 220 "usage_rule_display_info" : { 221 "coupon_usage_method_list" : [ 222 "OFFLINE", 223 "MINI_PROGRAM", 224 "PAYMENT_CODE" 225 ], 226 "mini_program_appid" : "wx1234567890", 227 "mini_program_path" : "/pages/index/product", 228 "usage_description" : "工作日可用", 229 "coupon_available_store_info" : { 230 "description" : "所有门店可用,可使用小程序查看门店列表", 231 "mini_program_appid" : "wx1234567890", 232 "mini_program_path" : "/pages/index/store-list" 233 } 234 }, 235 "coupon_display_info" : { 236 "code_display_mode" : "QRCODE", 237 "background_color" : "Color010", 238 "entrance_mini_program" : { 239 "appid" : "wx1234567890", 240 "path" : "/pages/index/product", 241 "entrance_wording" : "欢迎选购", 242 "guidance_wording" : "获取更多优惠" 243 }, 244 "entrance_official_account" : { 245 "appid" : "wx1234567890" 246 }, 247 "entrance_finder" : { 248 "finder_id" : "gh_12345678", 249 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 250 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 251 } 252 }, 253 "notify_config" : { 254 "notify_appid" : "wx4fd12345678" 255 }, 256 "store_scope" : "NONE", 257 "sent_count_info" : { 258 "total_count" : 0, 259 "today_count" : 0 260 }, 261 "state" : "SENDING" 262 } 263 ] 264 } 265} 266
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 商品券使用模式(usage_mode)非法,不可以使此模式 | 请使用其他 usage_mode |
400 | INVALID_REQUEST | usage_mode 为 SINGLE 时,批次未填写 single_usage_rule | 请填写 single_usage_rule |
400 | INVALID_REQUEST | usage_mode 为 SEQUENTIAL 时,批次未填写 sequential_usage_rule | 请填写 sequential_usage_rule |
400 | INVALID_REQUEST | 单券使用模式的商品券批次,应该在「单券使用规则」中包含对应类型的优惠规则。对于文档中标记不应填写的优惠规则应删除。 | 请在「单券使用规则」中包含对应类型的优惠规则,并删除文档中标记不应填写的优惠规则。 |
400 | INVALID_REQUEST | 多次优惠使用模式的商品券批次,应该在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 | 在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 |
400 | INVALID_REQUEST | 单品满减券或单品折扣券不应在商品券中设置「满减券使用规则」或「折扣券使用规则」,而是应该在商品券批次中设置 | 请删除商品券中的「满减券使用规则」或「折扣券使用规则」,并在商品券批次中设置对应的优惠规则 |
403 | NO_AUTH | 品牌没有此接口权限 | 品牌没有此接口权限 |
400 | INVALID_REQUEST | 全场券的券类型只能设置为 「满减券」和「折扣券」,不可以设置为「换购券」 | 请更换券类型为「满减券」或「折扣券」;或者更换券使用范围为「单品券』 |
400 | INVALID_REQUEST | 商品券支持APP核销时,必须提供「APP跳转路径」 | 请提供「APP跳转路径」参数 |
400 | PARAM_ERROR | 分页大小超出限制,请根据接口文档调整到允许的范围 | 请调整分页大小到规定范围 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序AppID」 | 请提供「小程序AppID」 |
400 | INVALID_REQUEST | 单品券必须提供商品原价,请补充 | 请补充商品原价 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序跳转路径」 | 请提供提供「小程序跳转路径」 |
400 | INVALID_REQUEST | 单品券必须提供商品券套餐组合信息,请补充 | 请提供商品券套餐组合信息 |
400 | PARAM_ERROR | 时间字符串格式错误,请使用 RFC3339 标准格式 | 请使用 RFC3339 标准格式 |
400 | INVALID_REQUEST | 单券模式下,全场折扣券应在商品券中提供折扣券使用规则信息 | 请在商品券中提供「折扣券使用规则信息」 |
400 | INVALID_REQUEST | 单券模式下,全场满减券应在商品券中提供满减券使用规则信息 | 请在商品券中提供「满减券使用规则信息」 |
400 | INVALID_REQUEST | 每周固定可用时间(weekly_available_period)中提供当天可用时间段时(day_period_list),每周可用星期数(day_list)必填 | 请补充 每周可用星期数(day_list) |
400 | INVALID_REQUEST | 单券模式下,全场券需要提供「单券模式信息(single_usage_info)」 | 请提供单券模式信息(single_usage_info) |
400 | INVALID_REQUEST | 多次优惠模式下必须提供「多次优惠模式信息(sequential_usage_info)」 | 请填写 多次优惠模式信息(sequential_usage_info) |
400 | INVALID_REQUEST | 传入的OpenID不合法 | 请使用参数 AppID 对应的的OpenID |


