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