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