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

