修改商品券批次组发放预算
更新时间:2025.11.27品牌方可以通过本接口批量修改商品券批次组内所有批次的投放预算。
注:本接口每次调用只能调整一个维度的投放预算,如果你需要调整多个维度的预算,请多次调用本接口。
前置条件:
已创建
usage_mode为PROGRESSIVE_BUNDLE的商品券对应的批次组批次组内批次未失效或过期
频率限制:20/s
接口说明
支持商户:【品牌商户】
请求方式:【POST】/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stock-bundles/{stock_bundle_id}/update-budget
请求域名:【主域名】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_bundle_id 必填 string
【批次组ID】 商品券批次组的唯一标识,由微信支付生成,本接口会同步修改批次组内所有批次的对应预算信息。请确保该批次组属于 product_coupon_id 对应的商品券
body 包体参数
out_request_no 必填 string(40)
【修改请求单号】 品牌修改批次发放次数的请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_、短横线- 组成,长度在6-40个字符之间
update_mode 必填 string
【更新模式】 本接口每次只支持更新一种限额,请选择对应的模式,并传入对应的字段。如果你需要调整多个维度的限制,请使用不同的模式多次调用本接口
可选取值
MAX_COUNT: 更新批次发放次数总上限MAX_COUNT_PER_DAY: 更新批次每日发放次数上限
current_max_count 选填 integer
【当前批次发放次数总上限】 当前批次发放次数总上限,调用本接口前,请先通过【查询商品券批次详情API】获取。当且仅当 update_mode 为 MAX_COUNT 时必传,其他模式下不应填写
target_max_count 选填 integer
【目标批次发放次数总上限】 将批次发放次数总上限更新为本值,允许小于当前批次发放次数总上限,但是不得小于当前已发放总次数。当且仅当 update_mode 为 MAX_COUNT 时必传,其他模式下不应填写
current_max_count_per_day 选填 integer
【当前批次每日发放次数上限】 当前批次每日发放次数上限,调用本接口前,请先通过【查询商品券批次详情API】获取。当且仅当 update_mode 为 MAX_COUNT_PER_DAY 时必传,其他模式下不应填写
target_max_count_per_day 选填 integer
【目标批次每日发放次数上限】 将批次每日发放次数上限更新为本值,允许小于当前批次每日发放次数上限。当且仅当 update_mode 为 MAX_COUNT_PER_DAY 时必传,其他模式下不应填写
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/brand/marketing/product-coupon/product-coupons/200000001/stock-bundles/123456789/update-budget \ 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" : "BUDGET1212512514", 9 "update_mode" : "MAX_COUNT", 10 "current_max_count" : 1, 11 "target_max_count" : 1, 12 "current_max_count_per_day" : 1, 13 "target_max_count_per_day" : 1 14 }' 15
需配合微信支付工具库 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 UpdateStockBundleBudget { 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/{product_coupon_id}/stock-bundles/{stock_bundle_id}/update-budget"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 UpdateStockBundleBudget client = new UpdateStockBundleBudget( 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 UpdateStockBundleBudgetRequest request = new UpdateStockBundleBudgetRequest(); 41 request.productCouponId = "200000001"; 42 request.stockBundleId = "123456789"; 43 request.outRequestNo = "BUDGET1212512514"; 44 request.updateMode = UpdateBudgetMode.MAX_COUNT; 45 request.currentMaxCount = 1L; 46 request.targetMaxCount = 1L; 47 request.currentMaxCountPerDay = 1L; 48 request.targetMaxCountPerDay = 1L; 49 try { 50 StockBundleEntity response = client.run(request); 51 // TODO: 请求成功,继续业务逻辑 52 System.out.println(response); 53 } catch (WXPayBrandUtility.ApiException e) { 54 // TODO: 请求失败,根据状态码执行不同的逻辑 55 e.printStackTrace(); 56 } 57 } 58 59 public StockBundleEntity run(UpdateStockBundleBudgetRequest request) { 60 String uri = PATH; 61 uri = uri.replace("{product_coupon_id}", WXPayBrandUtility.urlEncode(request.productCouponId)); 62 uri = uri.replace("{stock_bundle_id}", WXPayBrandUtility.urlEncode(request.stockBundleId)); 63 String reqBody = WXPayBrandUtility.toJson(request); 64 65 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 66 reqBuilder.addHeader("Accept", "application/json"); 67 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 68 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 69 reqBuilder.addHeader("Content-Type", "application/json"); 70 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 71 reqBuilder.method(METHOD, requestBody); 72 Request httpRequest = reqBuilder.build(); 73 74 // 发送HTTP请求 75 OkHttpClient client = new OkHttpClient.Builder().build(); 76 try (Response httpResponse = client.newCall(httpRequest).execute()) { 77 String respBody = WXPayBrandUtility.extractBody(httpResponse); 78 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 79 // 2XX 成功,验证应答签名 80 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 81 httpResponse.headers(), respBody); 82 83 // 从HTTP应答报文构建返回数据 84 return WXPayBrandUtility.fromJson(respBody, StockBundleEntity.class); 85 } else { 86 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 87 } 88 } catch (IOException e) { 89 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 90 } 91 } 92 93 private final String brand_id; 94 private final String certificateSerialNo; 95 private final PrivateKey privateKey; 96 private final String wechatPayPublicKeyId; 97 private final PublicKey wechatPayPublicKey; 98 99 public UpdateStockBundleBudget(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 100 this.brand_id = brand_id; 101 this.certificateSerialNo = certificateSerialNo; 102 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 103 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 104 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 105 } 106 107 public static class UpdateStockBundleBudgetRequest { 108 @SerializedName("out_request_no") 109 public String outRequestNo; 110 111 @SerializedName("product_coupon_id") 112 @Expose(serialize = false) 113 public String productCouponId; 114 115 @SerializedName("stock_bundle_id") 116 @Expose(serialize = false) 117 public String stockBundleId; 118 119 @SerializedName("update_mode") 120 public UpdateBudgetMode updateMode; 121 122 @SerializedName("current_max_count") 123 public Long currentMaxCount; 124 125 @SerializedName("target_max_count") 126 public Long targetMaxCount; 127 128 @SerializedName("current_max_count_per_day") 129 public Long currentMaxCountPerDay; 130 131 @SerializedName("target_max_count_per_day") 132 public Long targetMaxCountPerDay; 133 } 134 135 public static class StockBundleEntity { 136 @SerializedName("stock_bundle_id") 137 public String stockBundleId; 138 139 @SerializedName("stock_list") 140 public List<StockEntityInBundle> stockList = new ArrayList<StockEntityInBundle>(); 141 } 142 143 public enum UpdateBudgetMode { 144 @SerializedName("MAX_COUNT") 145 MAX_COUNT, 146 @SerializedName("MAX_COUNT_PER_DAY") 147 MAX_COUNT_PER_DAY 148 } 149 150 public static class StockEntityInBundle { 151 @SerializedName("product_coupon_id") 152 public String productCouponId; 153 154 @SerializedName("stock_id") 155 public String stockId; 156 157 @SerializedName("remark") 158 public String remark; 159 160 @SerializedName("coupon_code_mode") 161 public CouponCodeMode couponCodeMode; 162 163 @SerializedName("coupon_code_count_info") 164 public CouponCodeCountInfo couponCodeCountInfo; 165 166 @SerializedName("stock_send_rule") 167 public StockSendRule stockSendRule; 168 169 @SerializedName("progressive_bundle_usage_rule") 170 public StockUsageRule progressiveBundleUsageRule; 171 172 @SerializedName("stock_bundle_info") 173 public StockBundleInfo stockBundleInfo; 174 175 @SerializedName("usage_rule_display_info") 176 public UsageRuleDisplayInfo usageRuleDisplayInfo; 177 178 @SerializedName("coupon_display_info") 179 public CouponDisplayInfo couponDisplayInfo; 180 181 @SerializedName("notify_config") 182 public NotifyConfig notifyConfig; 183 184 @SerializedName("store_scope") 185 public StockStoreScope storeScope; 186 187 @SerializedName("sent_count_info") 188 public StockSentCountInfo sentCountInfo; 189 190 @SerializedName("state") 191 public StockState state; 192 193 @SerializedName("deactivate_request_no") 194 public String deactivateRequestNo; 195 196 @SerializedName("deactivate_time") 197 public String deactivateTime; 198 199 @SerializedName("deactivate_reason") 200 public String deactivateReason; 201 } 202 203 public enum CouponCodeMode { 204 @SerializedName("WECHATPAY") 205 WECHATPAY, 206 @SerializedName("UPLOAD") 207 UPLOAD 208 } 209 210 public static class CouponCodeCountInfo { 211 @SerializedName("total_count") 212 public Long totalCount; 213 214 @SerializedName("available_count") 215 public Long availableCount; 216 } 217 218 public static class StockSendRule { 219 @SerializedName("max_count") 220 public Long maxCount; 221 222 @SerializedName("max_count_per_day") 223 public Long maxCountPerDay; 224 225 @SerializedName("max_count_per_user") 226 public Long maxCountPerUser; 227 } 228 229 public static class StockUsageRule { 230 @SerializedName("coupon_available_period") 231 public CouponAvailablePeriod couponAvailablePeriod; 232 233 @SerializedName("normal_coupon") 234 public NormalCouponUsageRule normalCoupon; 235 236 @SerializedName("discount_coupon") 237 public DiscountCouponUsageRule discountCoupon; 238 239 @SerializedName("exchange_coupon") 240 public ExchangeCouponUsageRule exchangeCoupon; 241 } 242 243 public static class StockBundleInfo { 244 @SerializedName("stock_bundle_id") 245 public String stockBundleId; 246 247 @SerializedName("stock_bundle_index") 248 public Long stockBundleIndex; 249 } 250 251 public static class UsageRuleDisplayInfo { 252 @SerializedName("coupon_usage_method_list") 253 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 254 255 @SerializedName("mini_program_appid") 256 public String miniProgramAppid; 257 258 @SerializedName("mini_program_path") 259 public String miniProgramPath; 260 261 @SerializedName("app_path") 262 public String appPath; 263 264 @SerializedName("usage_description") 265 public String usageDescription; 266 267 @SerializedName("coupon_available_store_info") 268 public CouponAvailableStoreInfo couponAvailableStoreInfo; 269 } 270 271 public static class CouponDisplayInfo { 272 @SerializedName("code_display_mode") 273 public CouponCodeDisplayMode codeDisplayMode; 274 275 @SerializedName("background_color") 276 public String backgroundColor; 277 278 @SerializedName("entrance_mini_program") 279 public EntranceMiniProgram entranceMiniProgram; 280 281 @SerializedName("entrance_official_account") 282 public EntranceOfficialAccount entranceOfficialAccount; 283 284 @SerializedName("entrance_finder") 285 public EntranceFinder entranceFinder; 286 } 287 288 public static class NotifyConfig { 289 @SerializedName("notify_appid") 290 public String notifyAppid; 291 } 292 293 public enum StockStoreScope { 294 @SerializedName("NONE") 295 NONE, 296 @SerializedName("ALL") 297 ALL, 298 @SerializedName("SPECIFIC") 299 SPECIFIC 300 } 301 302 public static class StockSentCountInfo { 303 @SerializedName("total_count") 304 public Long totalCount; 305 306 @SerializedName("today_count") 307 public Long todayCount; 308 } 309 310 public enum StockState { 311 @SerializedName("AUDITING") 312 AUDITING, 313 @SerializedName("SENDING") 314 SENDING, 315 @SerializedName("PAUSED") 316 PAUSED, 317 @SerializedName("STOPPED") 318 STOPPED, 319 @SerializedName("DEACTIVATED") 320 DEACTIVATED 321 } 322 323 public static class CouponAvailablePeriod { 324 @SerializedName("available_begin_time") 325 public String availableBeginTime; 326 327 @SerializedName("available_end_time") 328 public String availableEndTime; 329 330 @SerializedName("available_days") 331 public Long availableDays; 332 333 @SerializedName("wait_days_after_receive") 334 public Long waitDaysAfterReceive; 335 336 @SerializedName("weekly_available_period") 337 public FixedWeekPeriod weeklyAvailablePeriod; 338 339 @SerializedName("irregular_available_period_list") 340 public List<TimePeriod> irregularAvailablePeriodList; 341 } 342 343 public static class NormalCouponUsageRule { 344 @SerializedName("threshold") 345 public Long threshold; 346 347 @SerializedName("discount_amount") 348 public Long discountAmount; 349 } 350 351 public static class DiscountCouponUsageRule { 352 @SerializedName("threshold") 353 public Long threshold; 354 355 @SerializedName("percent_off") 356 public Long percentOff; 357 } 358 359 public static class ExchangeCouponUsageRule { 360 @SerializedName("threshold") 361 public Long threshold; 362 363 @SerializedName("exchange_price") 364 public Long exchangePrice; 365 } 366 367 public enum CouponUsageMethod { 368 @SerializedName("OFFLINE") 369 OFFLINE, 370 @SerializedName("MINI_PROGRAM") 371 MINI_PROGRAM, 372 @SerializedName("APP") 373 APP, 374 @SerializedName("PAYMENT_CODE") 375 PAYMENT_CODE 376 } 377 378 public static class CouponAvailableStoreInfo { 379 @SerializedName("description") 380 public String description; 381 382 @SerializedName("mini_program_appid") 383 public String miniProgramAppid; 384 385 @SerializedName("mini_program_path") 386 public String miniProgramPath; 387 } 388 389 public enum CouponCodeDisplayMode { 390 @SerializedName("INVISIBLE") 391 INVISIBLE, 392 @SerializedName("BARCODE") 393 BARCODE, 394 @SerializedName("QRCODE") 395 QRCODE 396 } 397 398 public static class EntranceMiniProgram { 399 @SerializedName("appid") 400 public String appid; 401 402 @SerializedName("path") 403 public String path; 404 405 @SerializedName("entrance_wording") 406 public String entranceWording; 407 408 @SerializedName("guidance_wording") 409 public String guidanceWording; 410 } 411 412 public static class EntranceOfficialAccount { 413 @SerializedName("appid") 414 public String appid; 415 } 416 417 public static class EntranceFinder { 418 @SerializedName("finder_id") 419 public String finderId; 420 421 @SerializedName("finder_video_id") 422 public String finderVideoId; 423 424 @SerializedName("finder_video_cover_image_url") 425 public String finderVideoCoverImageUrl; 426 } 427 428 public static class FixedWeekPeriod { 429 @SerializedName("day_list") 430 public List<WeekEnum> dayList; 431 432 @SerializedName("day_period_list") 433 public List<PeriodOfTheDay> dayPeriodList; 434 } 435 436 public static class TimePeriod { 437 @SerializedName("begin_time") 438 public String beginTime; 439 440 @SerializedName("end_time") 441 public String endTime; 442 } 443 444 public enum WeekEnum { 445 @SerializedName("MONDAY") 446 MONDAY, 447 @SerializedName("TUESDAY") 448 TUESDAY, 449 @SerializedName("WEDNESDAY") 450 WEDNESDAY, 451 @SerializedName("THURSDAY") 452 THURSDAY, 453 @SerializedName("FRIDAY") 454 FRIDAY, 455 @SerializedName("SATURDAY") 456 SATURDAY, 457 @SerializedName("SUNDAY") 458 SUNDAY 459 } 460 461 public static class PeriodOfTheDay { 462 @SerializedName("begin_time") 463 public Long beginTime; 464 465 @SerializedName("end_time") 466 public Long endTime; 467 } 468 469} 470
需配合微信支付工具库 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 := &UpdateStockBundleBudgetRequest{ 29 ProductCouponId: wxpay_brand_utility.String("200000001"), 30 StockBundleId: wxpay_brand_utility.String("123456789"), 31 OutRequestNo: wxpay_brand_utility.String("BUDGET1212512514"), 32 UpdateMode: UPDATEBUDGETMODE_MAX_COUNT.Ptr(), 33 CurrentMaxCount: wxpay_brand_utility.Int64(1), 34 TargetMaxCount: wxpay_brand_utility.Int64(1), 35 CurrentMaxCountPerDay: wxpay_brand_utility.Int64(1), 36 TargetMaxCountPerDay: wxpay_brand_utility.Int64(1), 37 } 38 39 response, err := UpdateStockBundleBudget(config, request) 40 if err != nil { 41 fmt.Printf("请求失败: %+v\n", err) 42 // TODO: 请求失败,根据状态码执行不同的处理 43 return 44 } 45 46 // TODO: 请求成功,继续业务逻辑 47 fmt.Printf("请求成功: %+v\n", response) 48} 49 50func UpdateStockBundleBudget(config *wxpay_brand_utility.BrandConfig, request *UpdateStockBundleBudgetRequest) (response *StockBundleEntity, err error) { 51 const ( 52 host = "https://api.mch.weixin.qq.com" 53 method = "POST" 54 path = "/brand/marketing/product-coupon/product-coupons/{product_coupon_id}/stock-bundles/{stock_bundle_id}/update-budget" 55 ) 56 57 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 58 if err != nil { 59 return nil, err 60 } 61 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 62 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_bundle_id}", url.PathEscape(*request.StockBundleId), -1) 63 reqBody, err := json.Marshal(request) 64 if err != nil { 65 return nil, err 66 } 67 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 68 if err != nil { 69 return nil, err 70 } 71 httpRequest.Header.Set("Accept", "application/json") 72 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 73 httpRequest.Header.Set("Content-Type", "application/json") 74 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 75 if err != nil { 76 return nil, err 77 } 78 httpRequest.Header.Set("Authorization", authorization) 79 80 client := &http.Client{} 81 httpResponse, err := client.Do(httpRequest) 82 if err != nil { 83 return nil, err 84 } 85 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 86 if err != nil { 87 return nil, err 88 } 89 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 90 // 2XX 成功,验证应答签名 91 err = wxpay_brand_utility.ValidateResponse( 92 config.WechatPayPublicKeyId(), 93 config.WechatPayPublicKey(), 94 &httpResponse.Header, 95 respBody, 96 ) 97 if err != nil { 98 return nil, err 99 } 100 response := &StockBundleEntity{} 101 if err := json.Unmarshal(respBody, response); err != nil { 102 return nil, err 103 } 104 105 return response, nil 106 } else { 107 return nil, wxpay_brand_utility.NewApiException( 108 httpResponse.StatusCode, 109 httpResponse.Header, 110 respBody, 111 ) 112 } 113} 114 115type UpdateStockBundleBudgetRequest struct { 116 OutRequestNo *string `json:"out_request_no,omitempty"` 117 ProductCouponId *string `json:"product_coupon_id,omitempty"` 118 StockBundleId *string `json:"stock_bundle_id,omitempty"` 119 UpdateMode *UpdateBudgetMode `json:"update_mode,omitempty"` 120 CurrentMaxCount *int64 `json:"current_max_count,omitempty"` 121 TargetMaxCount *int64 `json:"target_max_count,omitempty"` 122 CurrentMaxCountPerDay *int64 `json:"current_max_count_per_day,omitempty"` 123 TargetMaxCountPerDay *int64 `json:"target_max_count_per_day,omitempty"` 124} 125 126func (o *UpdateStockBundleBudgetRequest) MarshalJSON() ([]byte, error) { 127 type Alias UpdateStockBundleBudgetRequest 128 a := &struct { 129 ProductCouponId *string `json:"product_coupon_id,omitempty"` 130 StockBundleId *string `json:"stock_bundle_id,omitempty"` 131 *Alias 132 }{ 133 // 序列化时移除非 Body 字段 134 ProductCouponId: nil, 135 StockBundleId: nil, 136 Alias: (*Alias)(o), 137 } 138 return json.Marshal(a) 139} 140 141type StockBundleEntity struct { 142 StockBundleId *string `json:"stock_bundle_id,omitempty"` 143 StockList []StockEntityInBundle `json:"stock_list,omitempty"` 144} 145 146type UpdateBudgetMode string 147 148func (e UpdateBudgetMode) Ptr() *UpdateBudgetMode { 149 return &e 150} 151 152const ( 153 UPDATEBUDGETMODE_MAX_COUNT UpdateBudgetMode = "MAX_COUNT" 154 UPDATEBUDGETMODE_MAX_COUNT_PER_DAY UpdateBudgetMode = "MAX_COUNT_PER_DAY" 155) 156 157type StockEntityInBundle struct { 158 ProductCouponId *string `json:"product_coupon_id,omitempty"` 159 StockId *string `json:"stock_id,omitempty"` 160 Remark *string `json:"remark,omitempty"` 161 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 162 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 163 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 164 ProgressiveBundleUsageRule *StockUsageRule `json:"progressive_bundle_usage_rule,omitempty"` 165 StockBundleInfo *StockBundleInfo `json:"stock_bundle_info,omitempty"` 166 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 167 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 168 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 169 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 170 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 171 State *StockState `json:"state,omitempty"` 172 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 173 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 174 DeactivateReason *string `json:"deactivate_reason,omitempty"` 175} 176 177type CouponCodeMode string 178 179func (e CouponCodeMode) Ptr() *CouponCodeMode { 180 return &e 181} 182 183const ( 184 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 185 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 186) 187 188type CouponCodeCountInfo struct { 189 TotalCount *int64 `json:"total_count,omitempty"` 190 AvailableCount *int64 `json:"available_count,omitempty"` 191} 192 193type StockSendRule struct { 194 MaxCount *int64 `json:"max_count,omitempty"` 195 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 196 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 197} 198 199type StockUsageRule struct { 200 CouponAvailablePeriod *CouponAvailablePeriod `json:"coupon_available_period,omitempty"` 201 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 202 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 203 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 204} 205 206type StockBundleInfo struct { 207 StockBundleId *string `json:"stock_bundle_id,omitempty"` 208 StockBundleIndex *int64 `json:"stock_bundle_index,omitempty"` 209} 210 211type UsageRuleDisplayInfo struct { 212 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 213 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 214 MiniProgramPath *string `json:"mini_program_path,omitempty"` 215 AppPath *string `json:"app_path,omitempty"` 216 UsageDescription *string `json:"usage_description,omitempty"` 217 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 218} 219 220type CouponDisplayInfo struct { 221 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 222 BackgroundColor *string `json:"background_color,omitempty"` 223 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 224 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 225 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 226} 227 228type NotifyConfig struct { 229 NotifyAppid *string `json:"notify_appid,omitempty"` 230} 231 232type StockStoreScope string 233 234func (e StockStoreScope) Ptr() *StockStoreScope { 235 return &e 236} 237 238const ( 239 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 240 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 241 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 242) 243 244type StockSentCountInfo struct { 245 TotalCount *int64 `json:"total_count,omitempty"` 246 TodayCount *int64 `json:"today_count,omitempty"` 247} 248 249type StockState string 250 251func (e StockState) Ptr() *StockState { 252 return &e 253} 254 255const ( 256 STOCKSTATE_AUDITING StockState = "AUDITING" 257 STOCKSTATE_SENDING StockState = "SENDING" 258 STOCKSTATE_PAUSED StockState = "PAUSED" 259 STOCKSTATE_STOPPED StockState = "STOPPED" 260 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 261) 262 263type CouponAvailablePeriod struct { 264 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 265 AvailableEndTime *string `json:"available_end_time,omitempty"` 266 AvailableDays *int64 `json:"available_days,omitempty"` 267 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 268 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 269 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 270} 271 272type NormalCouponUsageRule struct { 273 Threshold *int64 `json:"threshold,omitempty"` 274 DiscountAmount *int64 `json:"discount_amount,omitempty"` 275} 276 277type DiscountCouponUsageRule struct { 278 Threshold *int64 `json:"threshold,omitempty"` 279 PercentOff *int64 `json:"percent_off,omitempty"` 280} 281 282type ExchangeCouponUsageRule struct { 283 Threshold *int64 `json:"threshold,omitempty"` 284 ExchangePrice *int64 `json:"exchange_price,omitempty"` 285} 286 287type CouponUsageMethod string 288 289func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 290 return &e 291} 292 293const ( 294 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 295 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 296 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 297 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 298) 299 300type CouponAvailableStoreInfo struct { 301 Description *string `json:"description,omitempty"` 302 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 303 MiniProgramPath *string `json:"mini_program_path,omitempty"` 304} 305 306type CouponCodeDisplayMode string 307 308func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 309 return &e 310} 311 312const ( 313 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 314 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 315 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 316) 317 318type EntranceMiniProgram struct { 319 Appid *string `json:"appid,omitempty"` 320 Path *string `json:"path,omitempty"` 321 EntranceWording *string `json:"entrance_wording,omitempty"` 322 GuidanceWording *string `json:"guidance_wording,omitempty"` 323} 324 325type EntranceOfficialAccount struct { 326 Appid *string `json:"appid,omitempty"` 327} 328 329type EntranceFinder struct { 330 FinderId *string `json:"finder_id,omitempty"` 331 FinderVideoId *string `json:"finder_video_id,omitempty"` 332 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 333} 334 335type FixedWeekPeriod struct { 336 DayList []WeekEnum `json:"day_list,omitempty"` 337 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 338} 339 340type TimePeriod struct { 341 BeginTime *string `json:"begin_time,omitempty"` 342 EndTime *string `json:"end_time,omitempty"` 343} 344 345type WeekEnum string 346 347func (e WeekEnum) Ptr() *WeekEnum { 348 return &e 349} 350 351const ( 352 WEEKENUM_MONDAY WeekEnum = "MONDAY" 353 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 354 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 355 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 356 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 357 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 358 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 359) 360 361type PeriodOfTheDay struct { 362 BeginTime *int64 `json:"begin_time,omitempty"` 363 EndTime *int64 `json:"end_time,omitempty"` 364} 365
应答参数
200 OK
stock_bundle_id 必填 string(40)
【批次组ID】 商品券批次组的唯一标识,由微信支付生成
stock_list 必填 array[object]
【批次列表】 批次组内批次列表
| 属性 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
product_coupon_id 必填 string(40) 【商品券ID】 商品券的唯一标识,由微信支付生成 stock_id 必填 string(40) 【批次ID】 商品券批次的唯一标识,由微信支付生成 remark 选填 string(20) 【备注】 仅配置品牌可见,用于自定义信息 coupon_code_mode 必填 string 【券Code分配模式】 决定发券时用户商品券Code如何产生 可选取值
coupon_code_count_info 选填 object 【品牌方预上传的券Code数量信息】 当且仅当
stock_send_rule 必填 object 【发放规则】 发放规则
progressive_bundle_usage_rule 选填 object 【多次优惠使用规则】 本批次属于某个多次优惠批次组,这里记录的是本批次的使用规则,当且仅当
stock_bundle_info 必填 object 【批次组信息】 批次所在批次组信息
usage_rule_display_info 必填 object 【券使用规则展示信息】 券使用规则展示信息
coupon_display_info 必填 object 【用户商品券展示信息】 用户商品券在卡包中的展示详情,包括引导用户的自定义入口
notify_config 必填 object 【事件通知配置】 发生券相关事件时,微信支付会向品牌方发送通知,需要提供通知相关配置
store_scope 必填 string 【可用门店范围】 控制该批次可以在品牌下哪些门店使用 可选取值
sent_count_info 必填 object 【已发放次数】 本批次已发放次数
state 必填 string 【批次状态】 商品券批次状态 可选取值
deactivate_request_no 选填 string(128) 【失效请求单号】 当且仅当 deactivate_time 选填 string 【失效时间】 当且仅当 deactivate_reason 选填 string(150) 【失效原因】 当且仅当 |
应答示例
200 OK
1{ 2 "stock_bundle_id" : "123456789", 3 "stock_list" : [ 4 { 5 "product_coupon_id" : "200000001", 6 "stock_id" : "123456789", 7 "remark" : "满减券", 8 "coupon_code_mode" : "UPLOAD", 9 "coupon_code_count_info" : { 10 "total_count" : 10000, 11 "available_count" : 999 12 }, 13 "stock_send_rule" : { 14 "max_count" : 10000000, 15 "max_count_per_day" : 10000, 16 "max_count_per_user" : 1 17 }, 18 "progressive_bundle_usage_rule" : { 19 "coupon_available_period" : { 20 "available_begin_time" : "2025-01-01T00:00:00+08:00", 21 "available_end_time" : "2025-10-01T00:00:00+08:00", 22 "available_days" : 10, 23 "wait_days_after_receive" : 1, 24 "weekly_available_period" : { 25 "day_list" : [ 26 "MONDAY" 27 ], 28 "day_period_list" : [ 29 { 30 "begin_time" : 60, 31 "end_time" : 86399 32 } 33 ] 34 }, 35 "irregular_available_period_list" : [ 36 { 37 "begin_time" : "2025-01-01T00:00:00+08:00", 38 "end_time" : "2025-10-01T00:00:00+08:00" 39 } 40 ] 41 }, 42 "normal_coupon" : { 43 "threshold" : 10000, 44 "discount_amount" : 100 45 }, 46 "discount_coupon" : { 47 "threshold" : 10000, 48 "percent_off" : 30 49 }, 50 "exchange_coupon" : { 51 "threshold" : 10000, 52 "exchange_price" : 100 53 } 54 }, 55 "stock_bundle_info" : { 56 "stock_bundle_id" : "123456789", 57 "stock_bundle_index" : 0 58 }, 59 "usage_rule_display_info" : { 60 "coupon_usage_method_list" : [ 61 "MINI_PROGRAM" 62 ], 63 "mini_program_appid" : "wx1234567890", 64 "mini_program_path" : "/pages/index/product", 65 "app_path" : "https://www.example.com/jump-to-app", 66 "usage_description" : "全场可用", 67 "coupon_available_store_info" : { 68 "description" : "可在上海市区的所有门店使用,详细列表参考小程序内信息为准", 69 "mini_program_appid" : "wx1234567890", 70 "mini_program_path" : "/pages/index/store-list" 71 } 72 }, 73 "coupon_display_info" : { 74 "code_display_mode" : "QRCODE", 75 "background_color" : "Color010", 76 "entrance_mini_program" : { 77 "appid" : "wx1234567890", 78 "path" : "/pages/index/product", 79 "entrance_wording" : "欢迎选购", 80 "guidance_wording" : "获取更多优惠" 81 }, 82 "entrance_official_account" : { 83 "appid" : "wx1234567890" 84 }, 85 "entrance_finder" : { 86 "finder_id" : "gh_12345678", 87 "finder_video_id" : "UDFsdf24df34dD456Hdf34", 88 "finder_video_cover_image_url" : "https://wxpaylogo.qpic.cn/wxpaylogo/xxxxx/xxx" 89 } 90 }, 91 "notify_config" : { 92 "notify_appid" : "wx4fd12345678" 93 }, 94 "store_scope" : "SPECIFIC", 95 "sent_count_info" : { 96 "total_count" : 100, 97 "today_count" : 10 98 }, 99 "state" : "SENDING", 100 "deactivate_request_no" : "1002600620019090123143254436", 101 "deactivate_time" : "2025-01-01T00:00+08:00", 102 "deactivate_reason" : "批次信息有误,重新创建" 103 } 104 ] 105} 106
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示


