创建商品券
更新时间:2025.12.31品牌方可以通过该接口为品牌创建商品券和批次组。微信支付创建成功后,会返回此次创建的商品券、批次组。品牌方可在【经营平台】上配置【活动】对商品券进行投放。
前置条件:品牌方已【设置商品券事件通知地址】
接口说明
支持商户:【品牌商户】
请求方式:【POST】/brand/marketing/product-coupon/product-coupons
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
接口限频:20/秒(品牌ID维度)
请求参数
折叠全部参数
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或EXCHANGECATEGORY: 品类券。适用于商户对某一品类商品提供优惠的场景;系统侧不维护商品/品类清单,具体可用商品范围由商户在display_info描述、图片等字段中向用户告知,并在核销时由商户自行判定。此时券类型type仅可配置为NORMAL或DISCOUNT
type 必填 string
【商品券类型】 商品券的优惠类型
可选取值
NORMAL: 满减券DISCOUNT: 折扣券EXCHANGE: 兑换券,仅在scope为SINGLE时可配置
usage_mode 必填 string
【使用模式】 商品券使用模式
PROGRESSIVE_BUNDLE: 多次优惠,由一组批次组成,每阶梯次序对应一个批次。用户按顺序使用,每次核销后发放下一张券,直到用完为止
progressive_bundle_usage_info 必填 object
【多次优惠模式信息】 多次优惠模式配置信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时必传,其他模式不应填写。
count 必填 integer
【可使用次数】 多次优惠领取后用户可使用次数,最少3次,最多15次
interval_days 选填 integer
【多次优惠使用间隔天数】 多次优惠多次使用之间需要间隔的天数,最高7天。例如:
间隔
0天表示不限制,使用后当天仍然可以继续使用下一次优惠间隔
1天表示使用后当天不再可用,下一次优惠需要等到次日 00:00:00 才能使用间隔
2天表示使用后当天和次日不再可用,下一次优惠需要等到第三天 00:00:00 才能使用依此类推……
默认情况下为 0 天,即不限制,使用后当天仍然可以继续使用下一次优惠
display_info 必填 object
【展示信息】 商品券展示信息,展示结果可参考商品券示意图(多次优惠模式)
name 必填 string(25)
【商品券名称】 商品券名称,长度为3-25个UTF-8字符
image_url 选填 string
【商品券图片】 商品图片的链接地址,仅支持通过【图片上传API】获取的图片URL地址。
不填时,平台将根据商品券信息同步生成图片,并在应答中返回:
scope为ALL或CATEGORY时,以品牌元素与优惠信息拼接生成scope为SINGLE时,根据单品信息生成
图片生成失败时本次创建失败,可稍后重试或自行上传图片。
自行上传图片时:
请参考商品券图片设计规范进行设计
要求图片宽高比1:1,建议尺寸1080*1080
大小不超过2M
建议图片格式:透明PNG格式
需要注意保留透明边距(上下左右各120px)
background_url 必填 string
【商品券背景图】 商品背景图片的URL地址,仅支持通过【图片上传API】获取的图片URL地址。
要求图片宽高比65:77,建议尺寸1170*1326
大小不超过2M
建议图片格式:JPG/PNG格式
需要注意保留「商品名称」与「商品图」的安全区域
detail_image_url_list 选填 array[string]
【商品券详情图列表】 商品详情图URL地址列表,用于最多可上传8张图片,仅支持通过【图片上传API】获取的图片URL地址。
要求图片宽高比65:77,建议尺寸1170*1326
大小不超过2M
建议图片格式:JPG/PNG格式
original_price 选填 integer
【商品原价】 单位为分,用于对外展示,默认为 0,最大为 10000000。不填写时默认为 0
combo_package_list 选填 array[object]
【适用商品组合】 当 scope 为 SINGLE 必填,用于对外展示,其他优惠范围选填。最多配置 50 个组合
name 必填 string(25)
【适用商品名】 长度不超过25个UTF-8字符
pick_count 必填 integer
【可选单品数量】 用户可以从 choice_list 中选择的选项数量,例如 10 选 3,则这里填 3
choice_list 必填 array[object]
【单品列表】 套餐内包含的选项列表,记录每个单品的信息,最多99个单品,且不能少于设置的pick_count数量
name 必填 string(25)
【单品名称】 长度不超过25个UTF-8字符
price 必填 integer
【单品价格】 单位为分,必须大于0。
count 必填 integer
【单品数量】 最多99个
image_url 选填 string
【单品图片】 单品图片URL地址,仅支持通过【图片上传API】获取的图片URL地址,接入领券组件和核销组件的品牌方建议填写。
要求图片宽高比1:1,建议尺寸1080*1080
大小不超过2M
建议图片格式:透明PNG格式
需要注意保留透明边距(上下左右各120px)
mini_program_appid 选填 string
【单品跳转小程序AppID】 品牌方可展示单品的小程序AppID,小程序需与品牌方存在绑定关系,接入领券组件和核销组件的品牌方建议填写。需和 mini_program_path 一同填写。
mini_program_path 选填 string
【单品跳转小程序路径】 单品展示信息在小程序内的跳转路径,接入领券组件和核销组件的品牌方建议填写。需和 mini_program_appid 一同填写。
out_product_no 选填 string(40)
【外部商品ID】 品牌侧的商品标识,品牌可自行选择传入,长度不超过40个字符。
注:微信支付不校验此参数的唯一性,即允许多个商品券共享外部商品ID。
stock_bundle 必填 object
【批次组】 商品券批次组信息,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时必传,其他模式不应填写。
remark 选填 string(20)
【备注】 仅配置品牌方可见,用于自定义信息,最多20个UTF-8字符
coupon_code_mode 必填 string
【券Code分配模式】 决定发券时用户商品券Code如何产生,批次组内每一个批次都会设置为此值
可选取值
WECHATPAY: 微信支付随机生成,发券时由微信支付系统自动随机生成券码,品牌方无需干预,微信支付随机生成的券Code长度限制为40个字符以内UPLOAD: 品牌方预上传Code,品牌方需先使用【预上传券Code API(多次优惠)】上传自定义Code,微信支付系统发券时从中随机选取,当预存Code不足时可能影响发券,品牌应及时补充
stock_send_rule 必填 object
【批次组发放规则】 批次组内的批次会继承此规则
max_count 必填 integer
【批次组发放次数总上限】 批次组在生命周期内总发放次数,最多 100,000,000 次。批次组内的所有批次会继承此上限。
max_count_per_day 选填 integer
【批次组每日发放次数上限】 批次组在每天内发放次数上限,每日刷新,最多 100,000,000 次。默认不限制每日发放上限。
注:为保证用户领取/使用多次优惠的体验,批次组内的首个批次会继承此上限,但其余批次会保持为不限制。
max_count_per_user 必填 integer
【每个用户领取批次组次数上限】 每个用户最多可领取本批次组的次数,最多 100 次。批次组内的所有批次会继承此上限。
progressive_bundle_usage_rule 必填 object
【多次优惠批次组使用规则】 包含组合内部每一个批次的优惠规则,会根据内部的优惠规则列表依次创建批次放入批次组,当且仅当 usage_mode 为 PROGRESSIVE_BUNDLE 时必填。
多次优惠的批次组下各轮次,需要保证每一轮次 “优惠力度”大于等于前一轮次。但是首轮除外,即首轮的“优惠力度”可以小于/大于/等于其他任意轮次。
具体定义:
当满减券时:各轮次中“减免金额”数值,每轮次需大于等于前一轮次,首轮除外
当折扣券时:各轮次中“减免百分比”数值,每轮次需大于等于前一轮次,首轮除外
当兑换券时:各轮次中“兑换价”数值,每轮次需小于等于前一轮次,首轮除外
举例:考虑一组折扣券5次优惠
8折、7折、6折、5折、4折:允许
8折、8折、8折、8折、8折:允许
6折、7折、6折、5折、4折:允许
6折、7折、7折、7折、7折:允许
6折、7折、8折、7折、7折:不允许,因为第三轮的“优惠力度”小于第二轮
8折、7折、6折、7折、4折:不允许,因为第四轮的“优惠力度”小于第三轮
coupon_available_period 必填 object
【券可核销时间】 确定用户领券后在什么时间段内可以核销
available_begin_time 必填 string
【批次开始时间】 遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
距离当前创建批次的时间不能超过90天,批次有效期最长不超过366天,摇优惠场景建议设置批次时间大于等于5天
available_end_time 必填 string
【批次结束时间】 遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
批次有效期最长不超过366天
available_days 选填 integer
【券生效后N天内可用】 日期区间内,券生效后 N 天内有效,最多365天。例如:
生效当天内有效填 1
生效后2天内有效填 2
依此类推……
用户在有效期开始前领取商品券,则从有效期第1天开始计算天数,用户在有效期内领取商品券,则从领取当天开始计算天数,无论用户何时领取商品券,商品券在活动有效期结束后均不可用。
可配合 wait_days_after_receive 一同填写,也可单独填写。
注:不可与 irregular_available_period_list 同时配置
wait_days_after_receive 选填 integer
【领券后需等待N天才生效】 日期区间内,用户领券后需等待 N 天才开始生效,最多30天。例如:
领券后当天开始生效则无需填写
领券后第二天开始生效则填写 1
用户在有效期开始前领取商品券,则从有效期第1天开始计算天数,用户在有效期内领取商品券,则从领取当天开始计算天数。无论用户何时领取商品券,商品券在活动有效期结束后均不可用。
需配合 available_days 一同填写,不可单独填写。
注:不可与 irregular_available_period_list 同时配置
weekly_available_period 选填 object
【每周固定可用时间】 日期区间内,每周固定时间可以使用。可与 available_days 和 wait_days_after_receive 一同配置,一同配置时条件需同时满足券才可用(时间范围取交集)。
注:不可与 irregular_available_period_list 同时配置
day_list 必填 array[string]
【每周可用星期数】 每周特定星期X可用,在日期区间内每周循环有效。例如 配置 ["MONDAY", "FRIDAY"] 表示每周一和周五可用。
可选取值
MONDAY: 周一可用TUESDAY: 周二可用WEDNESDAY: 周三可用THURSDAY: 周四可用FRIDAY: 周五可用SATURDAY: 周六可用SUNDAY: 周日可用
day_period_list 选填 array[object]
【当天可用时间段】 生效当天特定时间段内有效,可以配置多个时间段。最多可以配置 3 个时间段。不配置则全天可用。
begin_time 必填 integer
【当天可用开始时间】 当天可用时间距离当天 00:00:00 的秒数,如 60 表示当天 00:01:00 开始可用。取值范围 [0,86399] 且必须小于 end_time
end_time 必填 integer
【当天可用结束时间】 当天结束可用时间距离当天 00:00:00 的秒数,如 86399 表示当天 23:59:59 结束可用。取值范围 [0,86399] 且必须大于 begin_time
irregular_available_period_list 选填 array[object]
【指定可用时间段】 可以配置多个无规律时间段,不同区间内请勿重叠,最多可配置2个区间。
注:不可与 available_days、wait_days_after_receive、weekly_available_period 同时配置
begin_time 必填 string
【开始时间】 区间开始时间,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
end_time 必填 string
【结束时间】 区间结束时间,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
available_seconds 选填 integer
【领取后N秒内有效】 日期区间内,用户领券后立即生效,自领取时刻起 N 秒内可用,不与自然日对齐。取值范围为 3600~86400,且仅支持 3600 的整数倍。
注:不可与 available_days、wait_days_after_receive、weekly_available_period、irregular_available_period_list 同时配置
normal_coupon_list 选填 array[object]
【满减券使用规则】 当且仅当 type 为 NORMAL 时必填,其他类型不应填写
threshold 必填 integer
【门槛金额】 使用门槛金额,单位为分,达到该门槛后可享受满减优惠。门槛可以为0,0元和0.01元都为无门槛。例如:
满 100 元可用填
10000满 0.01 元可用填
1
discount_amount 必填 integer
【固定减免金额】 固定减免金额,单位为分,必须大于0。
discount_coupon_list 选填 array[object]
【折扣券使用规则】 当且仅当 type 为 DISCOUNT 时必填,其他类型不应填写`
threshold 必填 integer
【门槛金额】 使用门槛金额,单位为分,达到该门槛后可享受折扣优惠。门槛可以为0,0元和0.01元都为无门槛。例如:
满 100 元可用填
10000满 0.01 元可用填
1
percent_off 必填 integer
【固定减免百分比】 表示减免金额为总金额的百分比,必须大于0。例如:填入 30 表示减免 30%,即打 7 折
exchange_coupon_list 选填 array[object]
【兑换券使用规则】 当且仅当 type 为 EXCHANGE 时必填,其他类型不应填写
threshold 必填 integer
【门槛金额】 使用门槛金额,单位为分,达到该门槛后可进行兑换。门槛可以为0,0元和0.01元都为无门槛兑换。例如:
满 100 元可用填
10000满 0.01 元可用填
1
exchange_price 必填 integer
【固定兑换价格】 单位为分,必须大于或等于0。
usage_rule_display_info 必填 object
【券使用规则展示信息】 券使用规则展示信息,批次组内每一个批次都会设置为此值
coupon_usage_method_list 必填 array[string]
【券使用方式列表】 可以配置多种使用方式
可选取值
OFFLINE: 线下滴码核销,点击券“立即使用”跳转展示券二维码详情(投放计划暂不支持此核销方式)MINI_PROGRAM: 线上小程序核销,点击券“立即使用”跳转至配置的商家小程序(需要添加小程序AppID和Path)APP: APP核销,在商家APP内核销PAYMENT_CODE: 微信支付付款码核销,用户点击券“立即使用”将跳转至微信支付钱包付款码,品牌方扫描付款码后可通过付款码获取到用户openid,通过openid查询并核销用户券,核销后再发起下单,适合线下支付场景
mini_program_appid 选填 string
【小程序AppID】 品牌方小程序AppID,可在微信公众平台查看,该小程序与品牌存在绑定关系。
在 coupon_usage_method_list 中包含 MINI_PROGRAM 时必填,需和 mini_program_path 一同填写。
mini_program_path 选填 string
【小程序跳转路径】 品牌方小程序内部跳转路径。
在 coupon_usage_method_list 中包含 MINI_PROGRAM 时必填,需和 mini_program_appid 一同填写。
app_path 选填 string
【APP的H5跳转路径】 品牌方APP的H5跳转路径。在 app_jump_type 为 H5 时必填。
usage_description 必填 string(1000)
【券使用说明】 用于说明详细的券规则,长度不超过1000个UTF-8字符
coupon_available_store_info 选填 object
【券可用门店信息】 用于描述全部可用门店信息,可配置小程序跳转地址进行展示
description 必填 string(1000)
【券可用门店描述】 告知用户本券可在哪些门店使用,长度不超过1000个UTF-8字符
mini_program_appid 选填 string
【小程序AppID】 品牌方小程序AppID,用于展示可用门店列表的详细信息,可在微信公众平台查看,该小程序与品牌存在绑定关系。需和 mini_program_path 一同填写。
mini_program_path 选填 string
【小程序跳转路径】 品牌方小程序内部展示可用门店列表的详细信息的页面跳转路径,需和 mini_program_appid 一同填写。
app_jump_type 选填 string
【APP跳转类型】 APP跳转类型,在 coupon_usage_method_list 中包含 APP 时必填。
可选取值
H5: 跳转H5,点击券立即使用跳转至配置的H5页面PASSCODE_LINK: 口令链接,点击券立即使用展示口令链接供用户复制使用USAGE_GUIDE: 展示使用指引,引导前往APP核销
passcode_link 选填 string
【口令链接】 口令链接。在 app_jump_type 为 PASSCODE_LINK 时必填。
coupon_display_info 必填 object
【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口,批次组内每一个批次都会设置为此值
code_display_mode 必填 string
【用户商品券Code展示模式】 决定用户商品券Code在卡包中的展示形态
可选取值
INVISIBLE: 不展示CodeBARCODE: 条形码QRCODE: 二维码
background_color 选填 string
【背景颜色】 券的背景颜色,可设置10种颜色,色值请参考下方说明。颜色取值为颜色图中的颜色名称,不填默认为 Color020 。

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

entrance_mini_program 选填 object
【小程序入口】 展示跳转小程序的入口
appid 必填 string
【小程序AppID】 品牌方小程序的AppID,可在微信公众平台查看,该小程序与品牌存在绑定关系
path 必填 string
【小程序跳转路径】 品牌方小程序内部跳转路径
entrance_wording 必填 string(5)
【入口文案】 小程序入口文案,长度不超过5个UTF-8字符
guidance_wording 必填 string(6)
【引导文案】 小程序入口引导文案,长度不超过6个UTF-8字符
entrance_official_account 选填 object
【公众号入口】 展示跳转公众号的入口
appid 必填 string
【公众号AppID】 微信公众号唯一标识,可在微信公众平台查看,该公众号应与品牌方存在绑定关系
notify_config 必填 object
【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
notify_appid 必填 string
【事件通知AppID】 品牌的AppID,支持小程序、服务号、公众号、APP类型的AppID,可在微信公众平台查看,用于券事件通知时计算用户的OpenID,需要与品牌存在绑定关系
store_scope 必填 string
【可用门店范围】 控制该批次可以在品牌下哪些门店使用
可选取值
NONE: 无关联门店,该批次对外不展示可用门店信息ALL: 所有门店可用,该批次在品牌下的所有门店可用,品牌无需为该批次关联门店列表SPECIFIC: 特定门店可用,品牌需调用关联门店接口关联门店,关联后该批次在关联的门店可用
sent_count_info 必填 object
【已发放次数】 本批次已发放次数
total_count 必填 integer
【已发放总次数】 批次在生命周期内已发放次数
today_count 必填 integer
【当天已发放次数】 批次在当天已发放次数
state 必填 string
【批次状态】 商品券批次状态
可选取值
AUDITING: 审批中SENDING: 发放中PAUSED: 已暂停STOPPED: 已停止,当前已到达结束时间DEACTIVATED: 已失效,品牌方主动调用失效接口使批次失效
deactivate_request_no 选填 string(128)
【失效请求单号】 state 为 DEACTIVATED 时提供,返回品牌方调用【失效商品券批次API】时传入的请求流水号
deactivate_time 选填 string
【失效时间】 state 为 DEACTIVATED 时提供,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
deactivate_reason 选填 string(150)
【失效原因】 state 为 DEACTIVATED 时提供,返回品牌方调用【失效商品券批次API】时传入的失效原因
available_product_no_list 选填 array[string]
【可用商品编码列表】 商户创建商品券时主动传入的可用商品编码,原样返回
business_mode 必填 string
【业务模式】 商品券的业务模式,原样返回创建请求中的取值;创建请求未填写时返回 FREE
可选取值
FREE: 普通券,用户可直接领取,此时批次与批次组均不配置trade_info。
应答示例
200 OK
创建全场折扣多次优惠券
1{ 2 "product_coupon_id" : "1000000014", 3 "scope" : "ALL", 4 "type" : "DISCOUNT", 5 "usage_mode" : "PROGRESSIVE_BUNDLE", 6 "business_mode" : "FREE", 7 "progressive_bundle_usage_info" : { 8 "count" : 3, 9 "interval_days" : 1 10 }, 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 "state" : "EFFECTIVE", 20 "out_product_no" : "Product_1234567890", 21 "stock_bundle" : { 22 "stock_bundle_id" : "712315129419284901", 23 "stock_list" : [ 24 { 25 "product_coupon_id" : "1000000014", 26 "stock_id" : "1000000014001", 27 "remark" : "8月工作日有效批次", 28 "coupon_code_mode" : "UPLOAD", 29 "coupon_code_count_info" : { 30 "total_count" : 0, 31 "available_count" : 0 32 }, 33 "stock_send_rule" : { 34 "max_count" : 10000000, 35 "max_count_per_user" : 1 36 }, 37 "progressive_bundle_usage_rule" : { 38 "coupon_available_period" : { 39 "available_begin_time" : "2025-08-01T00:00:00+08:00", 40 "available_end_time" : "2025-08-31T23:59:59+08:00", 41 "available_days" : 30, 42 "weekly_available_period" : { 43 "day_list" : [ 44 "MONDAY", 45 "TUESDAY", 46 "WEDNESDAY", 47 "THURSDAY", 48 "FRIDAY" 49 ] 50 } 51 }, 52 "discount_coupon" : { 53 "threshold" : 10000, 54 "percent_off" : 50 55 } 56 }, 57 "stock_bundle_info" : { 58 "stock_bundle_id" : "712315129419284901", 59 "stock_bundle_index" : 0 60 }, 61 "usage_rule_display_info" : { 62 "coupon_usage_method_list" : [ 63 "OFFLINE", 64 "MINI_PROGRAM", 65 "PAYMENT_CODE" 66 ], 67 "mini_program_appid" : "wx1234567890", 68 "mini_program_path" : "/pages/index/product", 69 "usage_description" : "工作日可用", 70 "coupon_available_store_info" : { 71 "description" : "所有门店可用,可使用小程序查看门店列表", 72 "mini_program_appid" : "wx1234567890", 73 "mini_program_path" : "/pages/index/store-list" 74 } 75 }, 76 "coupon_display_info" : { 77 "code_display_mode" : "QRCODE", 78 "background_color" : "Color010", 79 "entrance_mini_program" : { 80 "appid" : "wx1234567890", 81 "path" : "/pages/index/product", 82 "entrance_wording" : "欢迎选购", 83 "guidance_wording" : "获取更多优惠" 84 }, 85 "entrance_official_account" : { 86 "appid" : "wx1234567890" 87 } 88 }, 89 "notify_config" : { 90 "notify_appid" : "wx4fd12345678" 91 }, 92 "store_scope" : "NONE", 93 "sent_count_info" : { 94 "total_count" : 0, 95 "today_count" : 0 96 }, 97 "state" : "SENDING" 98 }, 99 { 100 "product_coupon_id" : "1000000014", 101 "stock_id" : "1000000014002", 102 "remark" : "8月工作日有效批次", 103 "coupon_code_mode" : "UPLOAD", 104 "coupon_code_count_info" : { 105 "total_count" : 0, 106 "available_count" : 0 107 }, 108 "stock_send_rule" : { 109 "max_count" : 10000000, 110 "max_count_per_user" : 1 111 }, 112 "progressive_bundle_usage_rule" : { 113 "coupon_available_period" : { 114 "available_begin_time" : "2025-08-01T00:00:00+08:00", 115 "available_end_time" : "2025-08-31T23:59:59+08:00", 116 "available_days" : 30, 117 "weekly_available_period" : { 118 "day_list" : [ 119 "MONDAY", 120 "TUESDAY", 121 "WEDNESDAY", 122 "THURSDAY", 123 "FRIDAY" 124 ] 125 } 126 }, 127 "discount_coupon" : { 128 "threshold" : 10000, 129 "percent_off" : 20 130 } 131 }, 132 "stock_bundle_info" : { 133 "stock_bundle_id" : "712315129419284901", 134 "stock_bundle_index" : 1 135 }, 136 "usage_rule_display_info" : { 137 "coupon_usage_method_list" : [ 138 "OFFLINE", 139 "MINI_PROGRAM", 140 "PAYMENT_CODE" 141 ], 142 "mini_program_appid" : "wx1234567890", 143 "mini_program_path" : "/pages/index/product", 144 "usage_description" : "工作日可用", 145 "coupon_available_store_info" : { 146 "description" : "所有门店可用,可使用小程序查看门店列表", 147 "mini_program_appid" : "wx1234567890", 148 "mini_program_path" : "/pages/index/store-list" 149 } 150 }, 151 "coupon_display_info" : { 152 "code_display_mode" : "QRCODE", 153 "background_color" : "Color010", 154 "entrance_mini_program" : { 155 "appid" : "wx1234567890", 156 "path" : "/pages/index/product", 157 "entrance_wording" : "欢迎选购", 158 "guidance_wording" : "获取更多优惠" 159 }, 160 "entrance_official_account" : { 161 "appid" : "wx1234567890" 162 } 163 }, 164 "notify_config" : { 165 "notify_appid" : "wx4fd12345678" 166 }, 167 "store_scope" : "NONE", 168 "sent_count_info" : { 169 "total_count" : 0, 170 "today_count" : 0 171 }, 172 "state" : "SENDING" 173 }, 174 { 175 "product_coupon_id" : "1000000014", 176 "stock_id" : "1000000014003", 177 "remark" : "8月工作日有效批次", 178 "coupon_code_mode" : "UPLOAD", 179 "coupon_code_count_info" : { 180 "total_count" : 0, 181 "available_count" : 0 182 }, 183 "stock_send_rule" : { 184 "max_count" : 10000000, 185 "max_count_per_user" : 1 186 }, 187 "progressive_bundle_usage_rule" : { 188 "coupon_available_period" : { 189 "available_begin_time" : "2025-08-01T00:00:00+08:00", 190 "available_end_time" : "2025-08-31T23:59:59+08:00", 191 "available_days" : 30, 192 "weekly_available_period" : { 193 "day_list" : [ 194 "MONDAY", 195 "TUESDAY", 196 "WEDNESDAY", 197 "THURSDAY", 198 "FRIDAY" 199 ] 200 } 201 }, 202 "discount_coupon" : { 203 "threshold" : 10000, 204 "percent_off" : 30 205 } 206 }, 207 "stock_bundle_info" : { 208 "stock_bundle_id" : "712315129419284901", 209 "stock_bundle_index" : 2 210 }, 211 "usage_rule_display_info" : { 212 "coupon_usage_method_list" : [ 213 "OFFLINE", 214 "MINI_PROGRAM", 215 "PAYMENT_CODE" 216 ], 217 "mini_program_appid" : "wx1234567890", 218 "mini_program_path" : "/pages/index/product", 219 "usage_description" : "工作日可用", 220 "coupon_available_store_info" : { 221 "description" : "所有门店可用,可使用小程序查看门店列表", 222 "mini_program_appid" : "wx1234567890", 223 "mini_program_path" : "/pages/index/store-list" 224 } 225 }, 226 "coupon_display_info" : { 227 "code_display_mode" : "QRCODE", 228 "background_color" : "Color010", 229 "entrance_mini_program" : { 230 "appid" : "wx1234567890", 231 "path" : "/pages/index/product", 232 "entrance_wording" : "欢迎选购", 233 "guidance_wording" : "获取更多优惠" 234 }, 235 "entrance_official_account" : { 236 "appid" : "wx1234567890" 237 } 238 }, 239 "notify_config" : { 240 "notify_appid" : "wx4fd12345678" 241 }, 242 "store_scope" : "NONE", 243 "sent_count_info" : { 244 "total_count" : 0, 245 "today_count" : 0 246 }, 247 "state" : "SENDING" 248 } 249 ] 250 } 251} 252
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | PARAM_ERROR | 缺少必填参数`app_jump_type` | 查看文档填写`app_jump_type` |
400 | PARAM_ERROR | 商品券APP跳转类型为口令链接时,必须提供「口令链接」 | 请在 usage_rule_display_info 中设置 passcode_link 字段 |
400 | INVALID_REQUEST | 发放类型无效,当前仅支持盲盒领取模式 | 不支持当前的玩法类型 |
403 | NO_AUTH | 品牌没有申请盲盒领取模式的权限 | 请联系微信支付申请开通盲盒券权限 |
400 | PARAM_ERROR | 盲盒券兑换价格必须为0 | 请将固定兑换价格改为 0 |
400 | PARAM_ERROR | 盲盒券单品图片必填 | 请补充单品图片 |
400 | PARAM_ERROR | 盲盒券单品ID必填 | 请补充单品标识 |
400 | PARAM_ERROR | 盲盒券必须是兑换券类型 | 请将商品券类型改为兑换券 |
400 | INVALID_REQUEST | 当前品牌未配置商品券事件通知地址,请先调用「设置商品券事件通知地址」设置通知地址后再执行此操作 | 请先调用「设置商品券事件通知地址」设置通知地址后再执行此操作 |
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 | 品牌没有此接口权限 | 品牌没有此接口权限 |
409 | ABORTED | 数据正在修改中,无法操作,请稍后再重试 | 请稍后再重试 |
400 | PARAM_ERROR | 参数错误,请参照API文档确认参数后再调用 | 参数错误,请确认请求参数是否包含接口未定义的字段,传递的参数值是否符合要求 |
400 | INVALID_REQUEST | 商品券已失效 | 商品券已失效 |
400 | ALREADY_EXISTS | 请求单号重复 | 请更换请求单号后重试 |
400 | INVALID_REQUEST | 商品券支持APP核销时,必须提供「APP跳转路径」 | 请提供「APP跳转路径」参数 |
400 | PARAM_ERROR | 分页大小超出限制,请根据接口文档调整到允许的范围 | 请调整分页大小到规定范围 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序AppID」 | 请提供「小程序AppID」 |
400 | INVALID_REQUEST | 单品券必须提供商品原价,请补充 | 请补充商品原价 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序跳转路径」 | 请提供提供「小程序跳转路径」 |
400 | PARAM_ERROR | 时间字符串格式错误,请使用 RFC3339 标准格式 | 请使用 RFC3339 标准格式 |
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 | 传入的OpenID不合法 | 请使用参数 AppID 对应的的OpenID |
400 | INVALID_REQUEST | 内容中包含敏感词或敏感图片,请修改后再重试 | 请修改内容后再重试 |
400 | PARAM_ERROR | 缺少必要的商品券图片 | 缺少必要的商品券图片,请根据API文档在传递的请求参数中补充该参数 |
400 | PARAM_ERROR | 缺少必要的商品券背景图 | 缺少商品券展示信息中的商品券背景图,请上传商品券背景图 |
400 | PARAM_ERROR | 缺少单品数量 | 请求参数缺少单品数量,请上传单品数量 |
400 | PARAM_ERROR | 参数错误,请根据接口文档检查字段要求 | 请根据接口文档检查字段要求,修复参数后重试 |
400 | PARAM_ERROR | Http header中缺少必填参数Wechatpay-Serial | 缺少必要商品券图片,请补充上传后重试 |
400 | PARAM_ERROR | 参数过短 | 请参考文档中对每个字段的要求以及组合要求,确认请求参数是否满足 |
400 | PARAM_ERROR | 参数过长 | 请参考文档中对每个字段的要求以及组合要求,确认请求参数是否满足 |
400 | PARAM_ERROR | 参数错误 | 请参考文档中对每个字段的要求以及组合要求,确认请求参数是否满足 |
400 | PARAM_ERROR | 参数超出取值范围 | 请参考文档中对每个字段的要求以及组合要求,确认请求参数是否满足 |
401 | SIGN_ERROR | Http头Authorization值格式错误,请参考《微信支付商户REST API签名规则》 | Http头Authorization值格式错误,请参考《APIv3如何签名和验签》,检查传递的Authorization值是否符合规则 |
400 | INVALID_REQUEST | Http头Content-Type值必须为application/json | 需将Http头中的Content-Type值设置为application/json |
401 | SIGN_ERROR | Http头Authorization中的timestamp与发起请求的时间不得超过5分钟 | Authorization 头 timestamp 与请求时间间隔超 5 分钟,需重新生成timestamp并替换该字段后重试。 |
401 | SIGN_ERROR | Authorization不合法 | Http头未传递Authorization值或Authorization值格式错误,请参考《APIv3如何签名和验签》,检查传递的Authorization值是否符合规则 |
400 | INVALID_REQUEST | Http头缺少Accept或User-Agent | Http头缺少Accept或User-Agent,请根据API文档在请求头中补充该参数 |
400 | PARAM_ERROR | 请求中含有未在API文档中定义的参数 | 请求中含有未在API文档中定义的参数,请检查传递的参数列表是否有编写错误的字段名 |
401 | SIGN_ERROR | Http头Authorization认证类型不正确 | Http头Authorization认证类型不正确,请将认证类型修改为WECHATPAY-BRAND-SHA256-RSA2048 |
