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