修改商品券批次
更新时间:2025.08.28品牌方可以通过该接口修改商品券批次的基本信息,包括展示信息、通知配置。展示信息修改不会影响已经发放的用户商品券。
如果你需要调整批次的投放预算,请使用【修改商品券批次发放预算API】
前置条件:商品券批次处于 SENDING 或 PAUSED 状态
频率限制:20/s
接口说明
支持商户:【品牌商户】
请求方式:【PATCH】/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}
请求域名:【主域名】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
Wechatpay-Serial 必填 string
【微信支付公钥ID】 请传入brand_id对应的微信支付公钥ID,接口将会校验两者的关联关系,参考微信支付公钥产品简介及使用说明获取微信支付公钥ID和相关的介绍。以下两种场景将使用到微信支付公钥: 1、接收到接口的返回内容,需要使用微信支付公钥进行验签; 2、调用含有敏感信息参数(如姓名、身份证号码)的接口时,需要使用微信支付公钥加密敏感信息后再传输参数,加密指引请参考微信支付公钥加密敏感信息指引。
path 路径参数
product_coupon_id 必填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成
stock_id 必填 string
【批次ID】 商品券批次的唯一标识,商品券批次创建时由微信支付生成(可使用创建商品券或添加商品券批次创建),请确保该批次属于 product_coupon_id 对应的商品券
body 包体参数
out_request_no 必填 string(40)
【修改请求单号】 品牌修改批次请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_、短横线- 组成,长度在6-40个字符之间
remark 选填 string(20)
【备注】 仅配置品牌可见,用于自定义信息
usage_rule_display_info 选填 object
【券使用规则展示信息】 券使用规则展示信息
| 属性 | |||||
coupon_usage_method_list 必填 array[string] 【券使用方式列表】 可以配置多种使用方式 可选取值
mini_program_appid 选填 string 【小程序AppID】 品牌方小程序AppID,可在微信公众平台查看,该小程序与品牌存在绑定关系。 在 mini_program_path 选填 string 【小程序跳转路径】 品牌方小程序内部跳转路径。 在 app_path 选填 string 【APP跳转路径】 品牌方APP跳转路径,在 usage_description 必填 string(1000) 【券使用说明】 用于说明详细的券规则,长度不超过1000个UTF-8字符 coupon_available_store_info 选填 object 【券可用门店信息】 用于描述全部可用门店信息,可配置小程序跳转地址进行展示
|
coupon_display_info 选填 object
【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口
| 属性 | |||||||||||||
code_display_mode 必填 string 【用户商品券Code展示模式】 决定用户商品券Code在卡包中的展示形态 可选取值
background_color 选填 string 【背景颜色】 券的背景颜色,可设置10种颜色,色值请参考下方说明。颜色取值为颜色图中的颜色名称,不填默认为
entrance_mini_program 选填 object 【小程序入口】 展示跳转小程序的入口
entrance_official_account 选填 object 【公众号入口】 展示跳转公众号的入口
entrance_finder 选填 object 【视频号入口】 展示跳转视频号的入口
|
notify_config 选填 object
【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
| 属性 | |
notify_appid 必填 string 【事件通知AppID】 品牌方小程序或公众号AppID,可在微信公众平台查看,用于券事件通知时计算用户的OpenID,需要与品牌存在绑定关系 |
store_scope 选填 string
【可用门店范围】 控制该批次可以在品牌下哪些门店使用,不填默认设置为 NONE
可选取值
NONE: 无关联门店,该批次对外不展示可用门店信息ALL: 所有门店可用,该批次在品牌下的所有门店可用,品牌无需为该批次关联门店列表SPECIFIC: 特定门店可用,品牌需调用关联门店接口关联门店,关联后该批次在关联的门店可用
请求示例
PATCH
1curl -X PATCH \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/product-coupons/200000001/stocks/123456789 \ 3 -H "Authorization: WECHATPAY-BRAND-SHA256-RSA2048 brand_id=\"XXXX\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: PUB_KEY_ID_XXXX" \ 6 -H "Content-Type: application/json" \ 7 -d '{ 8 "out_request_no" : "34657_20250101_123456", 9 "remark" : "疯狂星期四项目专用", 10 "usage_rule_display_info" : { 11 "coupon_usage_method_list" : [ 12 "MINI_PROGRAM" 13 ], 14 "mini_program_appid" : "wx1234567890", 15 "mini_program_path" : "/pages/index/product", 16 "app_path" : "https://www.example.com/jump-to-app", 17 "usage_description" : "全场可用", 18 "coupon_available_store_info" : { 19 "description" : "可在上海市区的所有门店使用,详细列表参考小程序内信息为准", 20 "mini_program_appid" : "wx1234567890", 21 "mini_program_path" : "/pages/index/store-list" 22 } 23 }, 24 "coupon_display_info" : { 25 "code_display_mode" : "QRCODE", 26 "background_color" : "Color010", 27 "entrance_mini_program" : { 28 "appid" : "wx1234567890", 29 "path" : "/pages/index/product", 30 "entrance_wording" : "欢迎选购", 31 "guidance_wording" : "获取更多优惠" 32 }, 33 "entrance_official_account" : { 34 "appid" : "wx1234567890" 35 }, 36 "entrance_finder" : { 37 "finder_id" : "gh_12345678", 38 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 39 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 40 } 41 }, 42 "notify_config" : { 43 "notify_appid" : "wx4fd12345678" 44 }, 45 "store_scope" : "SPECIFIC" 46 }' 47
需配合微信支付工具库 WXPayUtility 使用,请参考Java
1package com.java.demo; 2 3import com.java.utils.WXPayBrandUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/brand/4015826861 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 修改商品券批次 24 */ 25public class UpdateStock { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "PATCH"; 28 private static String PATH = "/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 UpdateStock client = new UpdateStock( 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 UpdateStockRequest request = new UpdateStockRequest(); 41 request.productCouponId = "200000001"; 42 request.stockId = "123456789"; 43 request.outRequestNo = "34657_20250101_123456"; 44 request.remark = "疯狂星期四项目专用"; 45 request.usageRuleDisplayInfo = new UsageRuleDisplayInfo(); 46 request.usageRuleDisplayInfo.couponUsageMethodList = new ArrayList<>(); 47 { 48 request.usageRuleDisplayInfo.couponUsageMethodList.add(CouponUsageMethod.OFFLINE); 49 }; 50 request.usageRuleDisplayInfo.miniProgramAppid = "wx1234567890"; 51 request.usageRuleDisplayInfo.miniProgramPath = "/pages/index/product"; 52 request.usageRuleDisplayInfo.appPath = "https://www.example.com/jump-to-app"; 53 request.usageRuleDisplayInfo.usageDescription = "全场可用"; 54 request.usageRuleDisplayInfo.couponAvailableStoreInfo = new CouponAvailableStoreInfo(); 55 request.usageRuleDisplayInfo.couponAvailableStoreInfo.description = "可在上海市区的所有门店使用,详细列表参考小程序内信息为准"; 56 request.usageRuleDisplayInfo.couponAvailableStoreInfo.miniProgramAppid = "wx1234567890"; 57 request.usageRuleDisplayInfo.couponAvailableStoreInfo.miniProgramPath = "/pages/index/store-list"; 58 request.couponDisplayInfo = new CouponDisplayInfo(); 59 request.couponDisplayInfo.codeDisplayMode = CouponCodeDisplayMode.QRCODE; 60 request.couponDisplayInfo.backgroundColor = "Color010"; 61 request.couponDisplayInfo.entranceMiniProgram = new EntranceMiniProgram(); 62 request.couponDisplayInfo.entranceMiniProgram.appid = "wx1234567890"; 63 request.couponDisplayInfo.entranceMiniProgram.path = "/pages/index/product"; 64 request.couponDisplayInfo.entranceMiniProgram.entranceWording = "欢迎选购"; 65 request.couponDisplayInfo.entranceMiniProgram.guidanceWording = "获取更多优惠"; 66 request.couponDisplayInfo.entranceOfficialAccount = new EntranceOfficialAccount(); 67 request.couponDisplayInfo.entranceOfficialAccount.appid = "wx1234567890"; 68 request.couponDisplayInfo.entranceFinder = new EntranceFinder(); 69 request.couponDisplayInfo.entranceFinder.finderId = "gh_12345678"; 70 request.couponDisplayInfo.entranceFinder.finderVideoId = "UDFsdf24df34dD456Hdf34"; 71 request.couponDisplayInfo.entranceFinder.finderVideoCoverImageUrl = "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"; 72 request.notifyConfig = new NotifyConfig(); 73 request.notifyConfig.notifyAppid = "wx4fd12345678"; 74 request.storeScope = StockStoreScope.SPECIFIC; 75 try { 76 StockEntity response = client.run(request); 77 // TODO: 请求成功,继续业务逻辑 78 System.out.println(response); 79 } catch (WXPayBrandUtility.ApiException e) { 80 // TODO: 请求失败,根据状态码执行不同的逻辑 81 e.printStackTrace(); 82 } 83 } 84 85 public StockEntity run(UpdateStockRequest request) { 86 String uri = PATH; 87 uri = uri.replace("{product_coupon_id}", WXPayBrandUtility.urlEncode(request.productCouponId)); 88 uri = uri.replace("{stock_id}", WXPayBrandUtility.urlEncode(request.stockId)); 89 String reqBody = WXPayBrandUtility.toJson(request); 90 91 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 92 reqBuilder.addHeader("Accept", "application/json"); 93 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 94 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 95 reqBuilder.addHeader("Content-Type", "application/json"); 96 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 97 reqBuilder.method(METHOD, requestBody); 98 Request httpRequest = reqBuilder.build(); 99 100 // 发送HTTP请求 101 OkHttpClient client = new OkHttpClient.Builder().build(); 102 try (Response httpResponse = client.newCall(httpRequest).execute()) { 103 String respBody = WXPayBrandUtility.extractBody(httpResponse); 104 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 105 // 2XX 成功,验证应答签名 106 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 107 httpResponse.headers(), respBody); 108 109 // 从HTTP应答报文构建返回数据 110 return WXPayBrandUtility.fromJson(respBody, StockEntity.class); 111 } else { 112 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 113 } 114 } catch (IOException e) { 115 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 116 } 117 } 118 119 private final String brand_id; 120 private final String certificateSerialNo; 121 private final PrivateKey privateKey; 122 private final String wechatPayPublicKeyId; 123 private final PublicKey wechatPayPublicKey; 124 125 public UpdateStock(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 126 this.brand_id = brand_id; 127 this.certificateSerialNo = certificateSerialNo; 128 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 129 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 130 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 131 } 132 133 public static class UpdateStockRequest { 134 @SerializedName("out_request_no") 135 public String outRequestNo; 136 137 @SerializedName("product_coupon_id") 138 @Expose(serialize = false) 139 public String productCouponId; 140 141 @SerializedName("stock_id") 142 @Expose(serialize = false) 143 public String stockId; 144 145 @SerializedName("remark") 146 public String remark; 147 148 @SerializedName("usage_rule_display_info") 149 public UsageRuleDisplayInfo usageRuleDisplayInfo; 150 151 @SerializedName("coupon_display_info") 152 public CouponDisplayInfo couponDisplayInfo; 153 154 @SerializedName("notify_config") 155 public NotifyConfig notifyConfig; 156 157 @SerializedName("store_scope") 158 public StockStoreScope storeScope; 159 } 160 161 public static class StockEntity { 162 @SerializedName("product_coupon_id") 163 public String productCouponId; 164 165 @SerializedName("stock_id") 166 public String stockId; 167 168 @SerializedName("remark") 169 public String remark; 170 171 @SerializedName("coupon_code_mode") 172 public CouponCodeMode couponCodeMode; 173 174 @SerializedName("coupon_code_count_info") 175 public CouponCodeCountInfo couponCodeCountInfo; 176 177 @SerializedName("stock_send_rule") 178 public StockSendRule stockSendRule; 179 180 @SerializedName("single_usage_rule") 181 public SingleUsageRule singleUsageRule; 182 183 @SerializedName("sequential_usage_rule") 184 public SequentialUsageRule sequentialUsageRule; 185 186 @SerializedName("usage_rule_display_info") 187 public UsageRuleDisplayInfo usageRuleDisplayInfo; 188 189 @SerializedName("coupon_display_info") 190 public CouponDisplayInfo couponDisplayInfo; 191 192 @SerializedName("notify_config") 193 public NotifyConfig notifyConfig; 194 195 @SerializedName("store_scope") 196 public StockStoreScope storeScope; 197 198 @SerializedName("sent_count_info") 199 public StockSentCountInfo sentCountInfo; 200 201 @SerializedName("state") 202 public StockState state; 203 204 @SerializedName("deactivate_request_no") 205 public String deactivateRequestNo; 206 207 @SerializedName("deactivate_time") 208 public String deactivateTime; 209 210 @SerializedName("deactivate_reason") 211 public String deactivateReason; 212 } 213 214 public static class UsageRuleDisplayInfo { 215 @SerializedName("coupon_usage_method_list") 216 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 217 218 @SerializedName("mini_program_appid") 219 public String miniProgramAppid; 220 221 @SerializedName("mini_program_path") 222 public String miniProgramPath; 223 224 @SerializedName("app_path") 225 public String appPath; 226 227 @SerializedName("usage_description") 228 public String usageDescription; 229 230 @SerializedName("coupon_available_store_info") 231 public CouponAvailableStoreInfo couponAvailableStoreInfo; 232 } 233 234 public static class CouponDisplayInfo { 235 @SerializedName("code_display_mode") 236 public CouponCodeDisplayMode codeDisplayMode; 237 238 @SerializedName("background_color") 239 public String backgroundColor; 240 241 @SerializedName("entrance_mini_program") 242 public EntranceMiniProgram entranceMiniProgram; 243 244 @SerializedName("entrance_official_account") 245 public EntranceOfficialAccount entranceOfficialAccount; 246 247 @SerializedName("entrance_finder") 248 public EntranceFinder entranceFinder; 249 } 250 251 public static class NotifyConfig { 252 @SerializedName("notify_appid") 253 public String notifyAppid; 254 } 255 256 public enum StockStoreScope { 257 @SerializedName("NONE") 258 NONE, 259 @SerializedName("ALL") 260 ALL, 261 @SerializedName("SPECIFIC") 262 SPECIFIC 263 } 264 265 public enum CouponCodeMode { 266 @SerializedName("WECHATPAY") 267 WECHATPAY, 268 @SerializedName("UPLOAD") 269 UPLOAD, 270 @SerializedName("API_ASSIGN") 271 API_ASSIGN 272 } 273 274 public static class CouponCodeCountInfo { 275 @SerializedName("total_count") 276 public Long totalCount; 277 278 @SerializedName("available_count") 279 public Long availableCount; 280 } 281 282 public static class StockSendRule { 283 @SerializedName("max_count") 284 public Long maxCount; 285 286 @SerializedName("max_count_per_day") 287 public Long maxCountPerDay; 288 289 @SerializedName("max_count_per_user") 290 public Long maxCountPerUser; 291 } 292 293 public static class SingleUsageRule { 294 @SerializedName("coupon_available_period") 295 public SingleCouponAvailablePeriod couponAvailablePeriod; 296 297 @SerializedName("normal_coupon") 298 public NormalCouponUsageRule normalCoupon; 299 300 @SerializedName("discount_coupon") 301 public DiscountCouponUsageRule discountCoupon; 302 303 @SerializedName("exchange_coupon") 304 public ExchangeCouponUsageRule exchangeCoupon; 305 } 306 307 public static class SequentialUsageRule { 308 @SerializedName("coupon_available_period") 309 public SequentialCouponAvailablePeriod couponAvailablePeriod; 310 311 @SerializedName("normal_coupon_list") 312 public List<NormalCouponUsageRule> normalCouponList; 313 314 @SerializedName("discount_coupon_list") 315 public List<DiscountCouponUsageRule> discountCouponList; 316 317 @SerializedName("exchange_coupon_list") 318 public List<ExchangeCouponUsageRule> exchangeCouponList; 319 320 @SerializedName("special_first") 321 public Boolean specialFirst; 322 } 323 324 public static class StockSentCountInfo { 325 @SerializedName("total_count") 326 public Long totalCount; 327 328 @SerializedName("today_count") 329 public Long todayCount; 330 } 331 332 public enum StockState { 333 @SerializedName("AUDITING") 334 AUDITING, 335 @SerializedName("SENDING") 336 SENDING, 337 @SerializedName("PAUSED") 338 PAUSED, 339 @SerializedName("STOPPED") 340 STOPPED, 341 @SerializedName("DEACTIVATED") 342 DEACTIVATED 343 } 344 345 public enum CouponUsageMethod { 346 @SerializedName("OFFLINE") 347 OFFLINE, 348 @SerializedName("MINI_PROGRAM") 349 MINI_PROGRAM, 350 @SerializedName("APP") 351 APP, 352 @SerializedName("PAYMENT_CODE") 353 PAYMENT_CODE 354 } 355 356 public static class CouponAvailableStoreInfo { 357 @SerializedName("description") 358 public String description; 359 360 @SerializedName("mini_program_appid") 361 public String miniProgramAppid; 362 363 @SerializedName("mini_program_path") 364 public String miniProgramPath; 365 } 366 367 public enum CouponCodeDisplayMode { 368 @SerializedName("INVISIBLE") 369 INVISIBLE, 370 @SerializedName("BARCODE") 371 BARCODE, 372 @SerializedName("QRCODE") 373 QRCODE 374 } 375 376 public static class EntranceMiniProgram { 377 @SerializedName("appid") 378 public String appid; 379 380 @SerializedName("path") 381 public String path; 382 383 @SerializedName("entrance_wording") 384 public String entranceWording; 385 386 @SerializedName("guidance_wording") 387 public String guidanceWording; 388 } 389 390 public static class EntranceOfficialAccount { 391 @SerializedName("appid") 392 public String appid; 393 } 394 395 public static class EntranceFinder { 396 @SerializedName("finder_id") 397 public String finderId; 398 399 @SerializedName("finder_video_id") 400 public String finderVideoId; 401 402 @SerializedName("finder_video_cover_image_url") 403 public String finderVideoCoverImageUrl; 404 } 405 406 public static class SingleCouponAvailablePeriod { 407 @SerializedName("available_begin_time") 408 public String availableBeginTime; 409 410 @SerializedName("available_end_time") 411 public String availableEndTime; 412 413 @SerializedName("available_days") 414 public Long availableDays; 415 416 @SerializedName("wait_days_after_receive") 417 public Long waitDaysAfterReceive; 418 419 @SerializedName("weekly_available_period") 420 public FixedWeekPeriod weeklyAvailablePeriod; 421 422 @SerializedName("irregular_available_period_list") 423 public List<TimePeriod> irregularAvailablePeriodList; 424 } 425 426 public static class NormalCouponUsageRule { 427 @SerializedName("threshold") 428 public Long threshold; 429 430 @SerializedName("discount_amount") 431 public Long discountAmount; 432 } 433 434 public static class DiscountCouponUsageRule { 435 @SerializedName("threshold") 436 public Long threshold; 437 438 @SerializedName("percent_off") 439 public Long percentOff; 440 } 441 442 public static class ExchangeCouponUsageRule { 443 @SerializedName("threshold") 444 public Long threshold; 445 446 @SerializedName("exchange_price") 447 public Long exchangePrice; 448 } 449 450 public static class SequentialCouponAvailablePeriod { 451 @SerializedName("available_begin_time") 452 public String availableBeginTime; 453 454 @SerializedName("available_end_time") 455 public String availableEndTime; 456 457 @SerializedName("wait_days_after_receive") 458 public Long waitDaysAfterReceive; 459 460 @SerializedName("weekly_available_period") 461 public FixedWeekPeriod weeklyAvailablePeriod; 462 463 @SerializedName("irregular_available_period_list") 464 public List<TimePeriod> irregularAvailablePeriodList; 465 } 466 467 public static class FixedWeekPeriod { 468 @SerializedName("day_list") 469 public List<WeekEnum> dayList; 470 471 @SerializedName("day_period_list") 472 public List<PeriodOfTheDay> dayPeriodList; 473 } 474 475 public static class TimePeriod { 476 @SerializedName("begin_time") 477 public String beginTime; 478 479 @SerializedName("end_time") 480 public String endTime; 481 } 482 483 public enum WeekEnum { 484 @SerializedName("MONDAY") 485 MONDAY, 486 @SerializedName("TUESDAY") 487 TUESDAY, 488 @SerializedName("WEDNESDAY") 489 WEDNESDAY, 490 @SerializedName("THURSDAY") 491 THURSDAY, 492 @SerializedName("FRIDAY") 493 FRIDAY, 494 @SerializedName("SATURDAY") 495 SATURDAY, 496 @SerializedName("SUNDAY") 497 SUNDAY 498 } 499 500 public static class PeriodOfTheDay { 501 @SerializedName("begin_time") 502 public Long beginTime; 503 504 @SerializedName("end_time") 505 public Long endTime; 506 } 507 508} 509
需配合微信支付工具库 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 "strings" 11 "time" 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 := &UpdateStockRequest{ 29 ProductCouponId: wxpay_brand_utility.String("200000001"), 30 StockId: wxpay_brand_utility.String("123456789"), 31 OutRequestNo: wxpay_brand_utility.String("34657_20250101_123456"), 32 Remark: wxpay_brand_utility.String("疯狂星期四项目专用"), 33 UsageRuleDisplayInfo: &UsageRuleDisplayInfo{ 34 CouponUsageMethodList: []CouponUsageMethod{COUPONUSAGEMETHOD_OFFLINE}, 35 MiniProgramAppid: wxpay_brand_utility.String("wx1234567890"), 36 MiniProgramPath: wxpay_brand_utility.String("/pages/index/product"), 37 AppPath: wxpay_brand_utility.String("https://www.example.com/jump-to-app"), 38 UsageDescription: wxpay_brand_utility.String("全场可用"), 39 CouponAvailableStoreInfo: &CouponAvailableStoreInfo{ 40 Description: wxpay_brand_utility.String("可在上海市区的所有门店使用,详细列表参考小程序内信息为准"), 41 MiniProgramAppid: wxpay_brand_utility.String("wx1234567890"), 42 MiniProgramPath: wxpay_brand_utility.String("/pages/index/store-list"), 43 }, 44 }, 45 CouponDisplayInfo: &CouponDisplayInfo{ 46 CodeDisplayMode: COUPONCODEDISPLAYMODE_QRCODE.Ptr(), 47 BackgroundColor: wxpay_brand_utility.String("Color010"), 48 EntranceMiniProgram: &EntranceMiniProgram{ 49 Appid: wxpay_brand_utility.String("wx1234567890"), 50 Path: wxpay_brand_utility.String("/pages/index/product"), 51 EntranceWording: wxpay_brand_utility.String("欢迎选购"), 52 GuidanceWording: wxpay_brand_utility.String("获取更多优惠"), 53 }, 54 EntranceOfficialAccount: &EntranceOfficialAccount{ 55 Appid: wxpay_brand_utility.String("wx1234567890"), 56 }, 57 EntranceFinder: &EntranceFinder{ 58 FinderId: wxpay_brand_utility.String("gh_12345678"), 59 FinderVideoId: wxpay_brand_utility.String("UDFsdf24df34dD456Hdf34"), 60 FinderVideoCoverImageUrl: wxpay_brand_utility.String("https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx"), 61 }, 62 }, 63 NotifyConfig: &NotifyConfig{ 64 NotifyAppid: wxpay_brand_utility.String("wx4fd12345678"), 65 }, 66 StoreScope: STOCKSTORESCOPE_SPECIFIC.Ptr(), 67 } 68 69 response, err := UpdateStock(config, request) 70 if err != nil { 71 fmt.Printf("请求失败: %+v\n", err) 72 // TODO: 请求失败,根据状态码执行不同的处理 73 return 74 } 75 76 // TODO: 请求成功,继续业务逻辑 77 fmt.Printf("请求成功: %+v\n", response) 78} 79 80func UpdateStock(config *wxpay_brand_utility.BrandConfig, request *UpdateStockRequest) (response *StockEntity, err error) { 81 const ( 82 host = "https://api.mch.weixin.qq.com" 83 method = "PATCH" 84 path = "/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}" 85 ) 86 87 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 88 if err != nil { 89 return nil, err 90 } 91 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 92 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_id}", url.PathEscape(*request.StockId), -1) 93 reqBody, err := json.Marshal(request) 94 if err != nil { 95 return nil, err 96 } 97 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 98 if err != nil { 99 return nil, err 100 } 101 httpRequest.Header.Set("Accept", "application/json") 102 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 103 httpRequest.Header.Set("Content-Type", "application/json") 104 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 105 if err != nil { 106 return nil, err 107 } 108 httpRequest.Header.Set("Authorization", authorization) 109 110 client := &http.Client{} 111 httpResponse, err := client.Do(httpRequest) 112 if err != nil { 113 return nil, err 114 } 115 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 116 if err != nil { 117 return nil, err 118 } 119 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 120 // 2XX 成功,验证应答签名 121 err = wxpay_brand_utility.ValidateResponse( 122 config.WechatPayPublicKeyId(), 123 config.WechatPayPublicKey(), 124 &httpResponse.Header, 125 respBody, 126 ) 127 if err != nil { 128 return nil, err 129 } 130 response := &StockEntity{} 131 if err := json.Unmarshal(respBody, response); err != nil { 132 return nil, err 133 } 134 135 return response, nil 136 } else { 137 return nil, wxpay_brand_utility.NewApiException( 138 httpResponse.StatusCode, 139 httpResponse.Header, 140 respBody, 141 ) 142 } 143} 144 145type UpdateStockRequest struct { 146 OutRequestNo *string `json:"out_request_no,omitempty"` 147 ProductCouponId *string `json:"product_coupon_id,omitempty"` 148 StockId *string `json:"stock_id,omitempty"` 149 Remark *string `json:"remark,omitempty"` 150 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 151 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 152 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 153 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 154} 155 156func (o *UpdateStockRequest) MarshalJSON() ([]byte, error) { 157 type Alias UpdateStockRequest 158 a := &struct { 159 ProductCouponId *string `json:"product_coupon_id,omitempty"` 160 StockId *string `json:"stock_id,omitempty"` 161 *Alias 162 }{ 163 // 序列化时移除非 Body 字段 164 ProductCouponId: nil, 165 StockId: nil, 166 Alias: (*Alias)(o), 167 } 168 return json.Marshal(a) 169} 170 171type StockEntity struct { 172 ProductCouponId *string `json:"product_coupon_id,omitempty"` 173 StockId *string `json:"stock_id,omitempty"` 174 Remark *string `json:"remark,omitempty"` 175 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 176 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 177 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 178 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 179 SequentialUsageRule *SequentialUsageRule `json:"sequential_usage_rule,omitempty"` 180 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 181 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 182 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 183 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 184 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 185 State *StockState `json:"state,omitempty"` 186 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 187 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 188 DeactivateReason *string `json:"deactivate_reason,omitempty"` 189} 190 191type UsageRuleDisplayInfo struct { 192 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 193 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 194 MiniProgramPath *string `json:"mini_program_path,omitempty"` 195 AppPath *string `json:"app_path,omitempty"` 196 UsageDescription *string `json:"usage_description,omitempty"` 197 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 198} 199 200type CouponDisplayInfo struct { 201 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 202 BackgroundColor *string `json:"background_color,omitempty"` 203 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 204 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 205 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 206} 207 208type NotifyConfig struct { 209 NotifyAppid *string `json:"notify_appid,omitempty"` 210} 211 212type StockStoreScope string 213 214func (e StockStoreScope) Ptr() *StockStoreScope { 215 return &e 216} 217 218const ( 219 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 220 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 221 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 222) 223 224type CouponCodeMode string 225 226func (e CouponCodeMode) Ptr() *CouponCodeMode { 227 return &e 228} 229 230const ( 231 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 232 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 233 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 234) 235 236type CouponCodeCountInfo struct { 237 TotalCount *int64 `json:"total_count,omitempty"` 238 AvailableCount *int64 `json:"available_count,omitempty"` 239} 240 241type StockSendRule struct { 242 MaxCount *int64 `json:"max_count,omitempty"` 243 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 244 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 245} 246 247type SingleUsageRule struct { 248 CouponAvailablePeriod *SingleCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 249 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 250 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 251 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 252} 253 254type SequentialUsageRule struct { 255 CouponAvailablePeriod *SequentialCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 256 NormalCouponList []NormalCouponUsageRule `json:"normal_coupon_list,omitempty"` 257 DiscountCouponList []DiscountCouponUsageRule `json:"discount_coupon_list,omitempty"` 258 ExchangeCouponList []ExchangeCouponUsageRule `json:"exchange_coupon_list,omitempty"` 259 SpecialFirst *bool `json:"special_first,omitempty"` 260} 261 262type StockSentCountInfo struct { 263 TotalCount *int64 `json:"total_count,omitempty"` 264 TodayCount *int64 `json:"today_count,omitempty"` 265} 266 267type StockState string 268 269func (e StockState) Ptr() *StockState { 270 return &e 271} 272 273const ( 274 STOCKSTATE_AUDITING StockState = "AUDITING" 275 STOCKSTATE_SENDING StockState = "SENDING" 276 STOCKSTATE_PAUSED StockState = "PAUSED" 277 STOCKSTATE_STOPPED StockState = "STOPPED" 278 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 279) 280 281type CouponUsageMethod string 282 283func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 284 return &e 285} 286 287const ( 288 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 289 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 290 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 291 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 292) 293 294type CouponAvailableStoreInfo struct { 295 Description *string `json:"description,omitempty"` 296 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 297 MiniProgramPath *string `json:"mini_program_path,omitempty"` 298} 299 300type CouponCodeDisplayMode string 301 302func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 303 return &e 304} 305 306const ( 307 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 308 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 309 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 310) 311 312type EntranceMiniProgram struct { 313 Appid *string `json:"appid,omitempty"` 314 Path *string `json:"path,omitempty"` 315 EntranceWording *string `json:"entrance_wording,omitempty"` 316 GuidanceWording *string `json:"guidance_wording,omitempty"` 317} 318 319type EntranceOfficialAccount struct { 320 Appid *string `json:"appid,omitempty"` 321} 322 323type EntranceFinder struct { 324 FinderId *string `json:"finder_id,omitempty"` 325 FinderVideoId *string `json:"finder_video_id,omitempty"` 326 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 327} 328 329type SingleCouponAvailablePeriod struct { 330 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 331 AvailableEndTime *string `json:"available_end_time,omitempty"` 332 AvailableDays *int64 `json:"available_days,omitempty"` 333 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 334 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 335 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 336} 337 338type NormalCouponUsageRule struct { 339 Threshold *int64 `json:"threshold,omitempty"` 340 DiscountAmount *int64 `json:"discount_amount,omitempty"` 341} 342 343type DiscountCouponUsageRule struct { 344 Threshold *int64 `json:"threshold,omitempty"` 345 PercentOff *int64 `json:"percent_off,omitempty"` 346} 347 348type ExchangeCouponUsageRule struct { 349 Threshold *int64 `json:"threshold,omitempty"` 350 ExchangePrice *int64 `json:"exchange_price,omitempty"` 351} 352 353type SequentialCouponAvailablePeriod struct { 354 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 355 AvailableEndTime *string `json:"available_end_time,omitempty"` 356 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 357 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 358 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 359} 360 361type FixedWeekPeriod struct { 362 DayList []WeekEnum `json:"day_list,omitempty"` 363 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 364} 365 366type TimePeriod struct { 367 BeginTime *string `json:"begin_time,omitempty"` 368 EndTime *string `json:"end_time,omitempty"` 369} 370 371type WeekEnum string 372 373func (e WeekEnum) Ptr() *WeekEnum { 374 return &e 375} 376 377const ( 378 WEEKENUM_MONDAY WeekEnum = "MONDAY" 379 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 380 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 381 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 382 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 383 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 384 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 385) 386 387type PeriodOfTheDay struct { 388 BeginTime *int64 `json:"begin_time,omitempty"` 389 EndTime *int64 `json:"end_time,omitempty"` 390} 391
应答参数
200 OK
product_coupon_id 必填 string(40)
【商品券ID】 商品券的唯一标识,由微信支付生成
stock_id 必填 string(40)
【批次ID】 商品券批次的唯一标识,由微信支付生成
remark 选填 string(20)
【备注】 仅配置品牌可见,用于自定义信息
coupon_code_mode 必填 string
【券Code分配模式】 决定发券时用户商品券Code如何产生
可选取值
WECHATPAY: 微信支付随机生成,发券时由微信支付系统自动随机生成券码,品牌方无需干预,微信支付随机生成的券Code长度限制为40个字符以内UPLOAD: 品牌方预上传Code,品牌方需先使用预上传券Code API上传自定义Code,微信支付系统发券时从中随机选取,当预存Code不足时可能影响发券,品牌应及时补充API_ASSIGN: 品牌方自行指定,品牌方通过发券API自行发券时指定,微信支付系统不再进行自动分配。特别注意:这种模式的商品批次只可由品牌方自行发券,无法在摇一摇有优惠等微信支付渠道投放
coupon_code_count_info 选填 object
【品牌方预上传的券Code数量信息】 当且仅当 coupon_code_mode 为 UPLOAD 时存在此字段
| 属性 | |
total_count 必填 integer 【已上传的Code总数】 品牌方为此批次已经上传过的券Code总数量 available_count 必填 integer 【当前可用的Code数】 品牌方为此批次已经上传过的券Code中,当前剩余可用的券Code数量 |
stock_send_rule 必填 object
【发放规则】 发放规则
| 属性 | |
max_count 必填 integer 【发放次数总上限】 批次在生命周期内总发放次数,最多 100,000,000 次 max_count_per_day 选填 integer 【每日发放次数上限】 批次在每天内发放次数上限,每日刷新,最多 100,000,000 次。默认不限制每日发放上限 max_count_per_user 必填 integer 【每个用户领取次数上限】 每个用户最多可领取本批次的次数,最多 100 次。 |
single_usage_rule 选填 object
【单券使用规则】 当且仅当 usage_mode 为 SINGLE 时提供,其他场景不提供
| 属性 | |||||||||||||||||||||||||||||
coupon_available_period 必填 object 【券可核销时间】 确定用户领券后在什么时间段内可以核销
normal_coupon 选填 object 【满减券使用规则】 当且仅当
discount_coupon 选填 object 【折扣券使用规则】 当且仅当
exchange_coupon 选填 object 【兑换券使用规则】 当且仅当
|
sequential_usage_rule 选填 object
【多次优惠使用规则】 当且仅当 usage_mode 为 SEQUENTIAL 时提供,其他场景不提供
| 属性 | |||||||||||||||||||||||||||||
coupon_available_period 必填 object 【多次优惠可核销时间】 确定用户领取多次优惠后在什么时间段内可以核销,多次优惠可核销时间不会超过多次优惠有效天数(多次优惠商品券中配置的
normal_coupon_list 选填 array[object] 【满减券使用规则】 当且仅当
discount_coupon_list 选填 array[object] 【折扣券使用规则】 当且仅当
exchange_coupon_list 选填 array[object] 【兑换券使用规则】 当且仅当
special_first 选填 boolean 【多次优惠是否提供首笔特惠】 默认情况下为 当此字段设置为 |
usage_rule_display_info 必填 object
【券使用规则展示信息】 券使用规则展示信息
| 属性 | |||||
coupon_usage_method_list 必填 array[string] 【券使用方式列表】 可以配置多种使用方式 可选取值
mini_program_appid 选填 string 【小程序AppID】 品牌方小程序AppID,可在微信公众平台查看,该小程序与品牌存在绑定关系。 在 mini_program_path 选填 string 【小程序跳转路径】 品牌方小程序内部跳转路径。 在 app_path 选填 string 【APP跳转路径】 品牌方APP跳转路径,在 usage_description 必填 string(1000) 【券使用说明】 用于说明详细的券规则,长度不超过1000个UTF-8字符 coupon_available_store_info 选填 object 【券可用门店信息】 用于描述全部可用门店信息,可配置小程序跳转地址进行展示
|
coupon_display_info 必填 object
【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口
| 属性 | |||||||||||||
code_display_mode 必填 string 【用户商品券Code展示模式】 决定用户商品券Code在卡包中的展示形态 可选取值
background_color 选填 string 【背景颜色】 券的背景颜色,可设置10种颜色,色值请参考下方说明。颜色取值为颜色图中的颜色名称,不填默认为
entrance_mini_program 选填 object 【小程序入口】 展示跳转小程序的入口
entrance_official_account 选填 object 【公众号入口】 展示跳转公众号的入口
entrance_finder 选填 object 【视频号入口】 展示跳转视频号的入口
|
notify_config 必填 object
【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
| 属性 | |
notify_appid 必填 string 【事件通知AppID】 品牌方小程序或公众号AppID,可在微信公众平台查看,用于券事件通知时计算用户的OpenID,需要与品牌存在绑定关系 |
store_scope 必填 string
【可用门店范围】 控制该批次可以在品牌下哪些门店使用
可选取值
NONE: 无关联门店,该批次对外不展示可用门店信息ALL: 所有门店可用,该批次在品牌下的所有门店可用,品牌无需为该批次关联门店列表SPECIFIC: 特定门店可用,品牌需调用关联门店接口关联门店,关联后该批次在关联的门店可用
sent_count_info 必填 object
【已发放次数】 本批次已发放次数
| 属性 | |
total_count 必填 integer 【已发放总次数】 批次在生命周期内已发放次数 today_count 必填 integer 【当天已发放次数】 批次在当天已发放次数 |
state 必填 string
【批次状态】 商品券批次状态
可选取值
AUDITING: 审批中SENDING: 发放中PAUSED: 已暂停STOPPED: 已停止,当前已到达结束时间DEACTIVATED: 已失效,品牌方主动调用失效接口使批次失效
deactivate_request_no 选填 string
【失效请求单号】 当且仅当 state 为 DEACTIVATED 时提供,返回品牌方调用失效接口时传入的请求流水号
deactivate_time 选填 string
【失效时间】 当且仅当 state 为 DEACTIVATED 时提供,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
deactivate_reason 选填 string
【失效原因】 当且仅当 state 为 DEACTIVATED 时提供,返回品牌方调用失效商品券批次接口时传入的失效原因
应答示例
200 OK
1{ 2 "product_coupon_id" : "200000001", 3 "stock_id" : "123456789", 4 "remark" : "满减券", 5 "coupon_code_mode" : "UPLOAD", 6 "coupon_code_count_info" : { 7 "total_count" : 10000, 8 "available_count" : 999 9 }, 10 "stock_send_rule" : { 11 "max_count" : 10000000, 12 "max_count_per_day" : 10000, 13 "max_count_per_user" : 1 14 }, 15 "single_usage_rule" : { 16 "coupon_available_period" : { 17 "available_begin_time" : "2025-01-01T00:00:00+08:00", 18 "available_end_time" : "2025-10-01T00:00:00+08:00", 19 "available_days" : 10, 20 "wait_days_after_receive" : 1, 21 "weekly_available_period" : { 22 "day_list" : [ 23 "MONDAY" 24 ], 25 "day_period_list" : [ 26 { 27 "begin_time" : 60, 28 "end_time" : 86399 29 } 30 ] 31 }, 32 "irregular_available_period_list" : [ 33 { 34 "begin_time" : "2025-01-01T00:00:00+08:00", 35 "end_time" : "2025-10-01T00:00:00+08:00" 36 } 37 ] 38 }, 39 "normal_coupon" : { 40 "threshold" : 10000, 41 "discount_amount" : 100 42 }, 43 "discount_coupon" : { 44 "threshold" : 10000, 45 "percent_off" : 30 46 }, 47 "exchange_coupon" : { 48 "threshold" : 10000, 49 "exchange_price" : 100 50 } 51 }, 52 "sequential_usage_rule" : { 53 "coupon_available_period" : { 54 "available_begin_time" : "2025-01-01T00:00:00+08:00", 55 "available_end_time" : "2025-10-01T00:00:00+08:00", 56 "wait_days_after_receive" : 1, 57 "weekly_available_period" : { 58 "day_list" : [ 59 "MONDAY" 60 ], 61 "day_period_list" : [ 62 { 63 "begin_time" : 60, 64 "end_time" : 86399 65 } 66 ] 67 }, 68 "irregular_available_period_list" : [ 69 { 70 "begin_time" : "2025-01-01T00:00:00+08:00", 71 "end_time" : "2025-10-01T00:00:00+08:00" 72 } 73 ] 74 }, 75 "normal_coupon_list" : [ 76 { 77 "threshold" : 10000, 78 "discount_amount" : 100 79 } 80 ], 81 "discount_coupon_list" : [ 82 { 83 "threshold" : 10000, 84 "percent_off" : 30 85 } 86 ], 87 "exchange_coupon_list" : [ 88 { 89 "threshold" : 10000, 90 "exchange_price" : 100 91 } 92 ], 93 "special_first" : false 94 }, 95 "usage_rule_display_info" : { 96 "coupon_usage_method_list" : [ 97 "MINI_PROGRAM" 98 ], 99 "mini_program_appid" : "wx1234567890", 100 "mini_program_path" : "/pages/index/product", 101 "app_path" : "https://www.example.com/jump-to-app", 102 "usage_description" : "全场可用", 103 "coupon_available_store_info" : { 104 "description" : "可在上海市区的所有门店使用,详细列表参考小程序内信息为准", 105 "mini_program_appid" : "wx1234567890", 106 "mini_program_path" : "/pages/index/store-list" 107 } 108 }, 109 "coupon_display_info" : { 110 "code_display_mode" : "QRCODE", 111 "background_color" : "Color010", 112 "entrance_mini_program" : { 113 "appid" : "wx1234567890", 114 "path" : "/pages/index/product", 115 "entrance_wording" : "欢迎选购", 116 "guidance_wording" : "获取更多优惠" 117 }, 118 "entrance_official_account" : { 119 "appid" : "wx1234567890" 120 }, 121 "entrance_finder" : { 122 "finder_id" : "gh_12345678", 123 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 124 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 125 } 126 }, 127 "notify_config" : { 128 "notify_appid" : "wx4fd12345678" 129 }, 130 "store_scope" : "SPECIFIC", 131 "sent_count_info" : { 132 "total_count" : 100, 133 "today_count" : 10 134 }, 135 "state" : "SENDING", 136 "deactivate_request_no" : "1002600620019090123143254436", 137 "deactivate_time" : "2025-01-01T00:00+08:00", 138 "deactivate_reason" : "批次信息有误,重新创建" 139} 140
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 单券使用模式的商品券批次,应该在「单券使用规则」中包含对应类型的优惠规则。对于文档中标记不应填写的优惠规则应删除。 | 请在「单券使用规则」中包含对应类型的优惠规则,并删除文档中标记不应填写的优惠规则。 |
400 | INVALID_REQUEST | 多次优惠使用模式的商品券批次,应该在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 | 在「多次优惠使用规则」中包含对应类型的优惠规则,且数量与多次优惠的优惠次数相等 |
400 | INVALID_REQUEST | 单品满减券或单品折扣券不应在商品券中设置「满减券使用规则」或「折扣券使用规则」,而是应该在商品券批次中设置 | 请删除商品券中的「满减券使用规则」或「折扣券使用规则」,并在商品券批次中设置对应的优惠规则 |
403 | NO_AUTH | 品牌没有此接口权限 | 品牌没有此接口权限 |
400 | INVALID_REQUEST | 商品券支持APP核销时,必须提供「APP跳转路径」 | 请提供「APP跳转路径」参数 |
400 | PARAM_ERROR | 分页大小超出限制,请根据接口文档调整到允许的范围 | 请调整分页大小到规定范围 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序AppID」 | 请提供「小程序AppID」 |
400 | INVALID_REQUEST | 单品券必须提供商品原价,请补充 | 请补充商品原价 |
400 | INVALID_REQUEST | 商品券支持小程序核销时,必须提供「小程序跳转路径」 | 请提供提供「小程序跳转路径」 |
400 | INVALID_REQUEST | 单品券必须提供商品券套餐组合信息,请补充 | 请提供商品券套餐组合信息 |
400 | PARAM_ERROR | 时间字符串格式错误,请使用 RFC3339 标准格式 | 请使用 RFC3339 标准格式 |
400 | INVALID_REQUEST | 单券模式下,全场折扣券应在商品券中提供折扣券使用规则信息 | 请在商品券中提供「折扣券使用规则信息」 |
400 | INVALID_REQUEST | 单券模式下,全场满减券应在商品券中提供满减券使用规则信息 | 请在商品券中提供「满减券使用规则信息」 |
400 | INVALID_REQUEST | 每周固定可用时间(weekly_available_period)中提供当天可用时间段时(day_period_list),每周可用星期数(day_list)必填 | 请补充 每周可用星期数(day_list) |
400 | INVALID_REQUEST | 单券模式下,全场券需要提供「单券模式信息(single_usage_info)」 | 请提供单券模式信息(single_usage_info) |
400 | INVALID_REQUEST | 多次优惠模式下必须提供「多次优惠模式信息(sequential_usage_info)」 | 请填写 多次优惠模式信息(sequential_usage_info) |
400 | INVALID_REQUEST | 传入的OpenID不合法 | 请使用参数 AppID 对应的的OpenID |


