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

