失效商品券批次
更新时间:2025.08.04品牌方可以通过该接口使已经创建的某个商品券批次失效。
注意:
调用本接口只会失效单个批次,商品券本身以及其他商品券批次不受影响。
失效商品券批次后,该批次不会有新的用户领券事件,但历史已经通过该批次发放的用户商品券仍然有效。
前置条件:已创建商品券批次
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/deactivate
请求域名:【主域名】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
path 路径参数
product_coupon_id 必填 string
【商品券ID】 商品券的唯一标识,创建商品券时由微信支付生成
stock_id 必填 string
【批次ID】 商品券批次的唯一标识,商品券批次创建时由微信支付生成(可使用创建商品券或添加商品券批次创建),请确保该批次属于 product_coupon_id
对应的商品券
body 包体参数
out_request_no 必填 string(40)
【失效请求单号】 品牌失效批次的请求流水号,品牌侧需保持唯一性,可使用 数字、大小写字母、下划线_
、短横线-
组成,长度在6-40个字符之间
deactivate_reason 必填 string(150)
【失效原因】 记录批次失效原因,长度不超过150个UTF-8字符
brand_id 必填 string
【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/product-coupon/product-coupons/200000001/stocks/123456789/deactivate \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "out_request_no" : "34657_20250101_123456", 8 "deactivate_reason" : "批次信息有误,重新创建", 9 "brand_id" : "120344" 10 }' 11
需配合微信支付工具库 WXPayUtility 使用,请参考 Java
1package com.java.demo; 2 3import com.java.utils.WXPayUtility; // 引用微信支付工具库,参考:https://pay.weixin.qq.com/doc/v3/partner/4014985777 4 5import com.google.gson.annotations.SerializedName; 6import com.google.gson.annotations.Expose; 7import okhttp3.MediaType; 8import okhttp3.OkHttpClient; 9import okhttp3.Request; 10import okhttp3.RequestBody; 11import okhttp3.Response; 12 13import java.io.IOException; 14import java.io.UncheckedIOException; 15import java.security.PrivateKey; 16import java.security.PublicKey; 17import java.util.ArrayList; 18import java.util.HashMap; 19import java.util.List; 20import java.util.Map; 21 22/** 23 * 失效商品券批次 24 */ 25public class DeactivateStock { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/deactivate"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 DeactivateStock client = new DeactivateStock( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem" // 商户API证书私钥文件路径,本地文件路径 36 , 37 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 38 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 39 ); 40 41 DeactivateStockRequest request = new DeactivateStockRequest(); 42 request.productCouponId = "200000001"; 43 request.stockId = "123456789"; 44 request.outRequestNo = "34657_20250101_123456"; 45 request.deactivateReason = "批次信息有误,重新创建"; 46 request.brandId = "120344"; 47 try { 48 StockEntity response = client.run(request); 49 // TODO: 请求成功,继续业务逻辑 50 System.out.println(response); 51 } catch (WXPayUtility.ApiException e) { 52 // TODO: 请求失败,根据状态码执行不同的逻辑 53 e.printStackTrace(); 54 } 55 } 56 57 public StockEntity run(DeactivateStockRequest request) { 58 String uri = PATH; 59 uri = uri.replace("{product_coupon_id}", WXPayUtility.urlEncode(request.productCouponId)); 60 uri = uri.replace("{stock_id}", WXPayUtility.urlEncode(request.stockId)); 61 String reqBody = WXPayUtility.toJson(request); 62 63 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 64 reqBuilder.addHeader("Accept", "application/json"); 65 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 66 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 67 reqBuilder.addHeader("Content-Type", "application/json"); 68 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 69 reqBuilder.method(METHOD, requestBody); 70 Request httpRequest = reqBuilder.build(); 71 72 // 发送HTTP请求 73 OkHttpClient client = new OkHttpClient.Builder().build(); 74 try (Response httpResponse = client.newCall(httpRequest).execute()) { 75 String respBody = WXPayUtility.extractBody(httpResponse); 76 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 77 // 2XX 成功,验证应答签名 78 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 79 httpResponse.headers(), respBody); 80 81 // 从HTTP应答报文构建返回数据 82 return WXPayUtility.fromJson(respBody, StockEntity.class); 83 } else { 84 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 85 } 86 } catch (IOException e) { 87 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 88 } 89 } 90 91 private final String mchid; 92 private final String certificateSerialNo; 93 private final PrivateKey privateKey; 94 private final String wechatPayPublicKeyId; 95 private final PublicKey wechatPayPublicKey; 96 97 public DeactivateStock(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 98 this.mchid = mchid; 99 this.certificateSerialNo = certificateSerialNo; 100 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 101 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 102 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 103 } 104 105 public static class DeactivateStockRequest { 106 @SerializedName("out_request_no") 107 public String outRequestNo; 108 109 @SerializedName("product_coupon_id") 110 @Expose(serialize = false) 111 public String productCouponId; 112 113 @SerializedName("stock_id") 114 @Expose(serialize = false) 115 public String stockId; 116 117 @SerializedName("deactivate_reason") 118 public String deactivateReason; 119 120 @SerializedName("brand_id") 121 public String brandId; 122 } 123 124 public static class StockEntity { 125 @SerializedName("product_coupon_id") 126 public String productCouponId; 127 128 @SerializedName("stock_id") 129 public String stockId; 130 131 @SerializedName("remark") 132 public String remark; 133 134 @SerializedName("coupon_code_mode") 135 public CouponCodeMode couponCodeMode; 136 137 @SerializedName("coupon_code_count_info") 138 public CouponCodeCountInfo couponCodeCountInfo; 139 140 @SerializedName("stock_send_rule") 141 public StockSendRule stockSendRule; 142 143 @SerializedName("single_usage_rule") 144 public SingleUsageRule singleUsageRule; 145 146 @SerializedName("sequential_usage_rule") 147 public SequentialUsageRule sequentialUsageRule; 148 149 @SerializedName("usage_rule_display_info") 150 public UsageRuleDisplayInfo usageRuleDisplayInfo; 151 152 @SerializedName("coupon_display_info") 153 public CouponDisplayInfo couponDisplayInfo; 154 155 @SerializedName("notify_config") 156 public NotifyConfig notifyConfig; 157 158 @SerializedName("store_scope") 159 public StockStoreScope storeScope; 160 161 @SerializedName("sent_count_info") 162 public StockSentCountInfo sentCountInfo; 163 164 @SerializedName("state") 165 public StockState state; 166 167 @SerializedName("deactivate_request_no") 168 public String deactivateRequestNo; 169 170 @SerializedName("deactivate_time") 171 public String deactivateTime; 172 173 @SerializedName("deactivate_reason") 174 public String deactivateReason; 175 176 @SerializedName("brand_id") 177 public String brandId; 178 } 179 180 public enum CouponCodeMode { 181 @SerializedName("WECHATPAY") 182 WECHATPAY, 183 @SerializedName("UPLOAD") 184 UPLOAD, 185 @SerializedName("API_ASSIGN") 186 API_ASSIGN 187 } 188 189 public static class CouponCodeCountInfo { 190 @SerializedName("total_count") 191 public Long totalCount; 192 193 @SerializedName("available_count") 194 public Long availableCount; 195 } 196 197 public static class StockSendRule { 198 @SerializedName("max_count") 199 public Long maxCount; 200 201 @SerializedName("max_count_per_day") 202 public Long maxCountPerDay; 203 204 @SerializedName("max_count_per_user") 205 public Long maxCountPerUser; 206 } 207 208 public static class SingleUsageRule { 209 @SerializedName("coupon_available_period") 210 public SingleCouponAvailablePeriod couponAvailablePeriod; 211 212 @SerializedName("normal_coupon") 213 public NormalCouponUsageRule normalCoupon; 214 215 @SerializedName("discount_coupon") 216 public DiscountCouponUsageRule discountCoupon; 217 218 @SerializedName("exchange_coupon") 219 public ExchangeCouponUsageRule exchangeCoupon; 220 } 221 222 public static class SequentialUsageRule { 223 @SerializedName("coupon_available_period") 224 public SequentialCouponAvailablePeriod couponAvailablePeriod; 225 226 @SerializedName("normal_coupon_list") 227 public List<NormalCouponUsageRule> normalCouponList; 228 229 @SerializedName("discount_coupon_list") 230 public List<DiscountCouponUsageRule> discountCouponList; 231 232 @SerializedName("exchange_coupon_list") 233 public List<ExchangeCouponUsageRule> exchangeCouponList; 234 235 @SerializedName("special_first") 236 public Boolean specialFirst; 237 } 238 239 public static class UsageRuleDisplayInfo { 240 @SerializedName("coupon_usage_method_list") 241 public List<CouponUsageMethod> couponUsageMethodList = new ArrayList<CouponUsageMethod>(); 242 243 @SerializedName("mini_program_appid") 244 public String miniProgramAppid; 245 246 @SerializedName("mini_program_path") 247 public String miniProgramPath; 248 249 @SerializedName("app_path") 250 public String appPath; 251 252 @SerializedName("usage_description") 253 public String usageDescription; 254 255 @SerializedName("coupon_available_store_info") 256 public CouponAvailableStoreInfo couponAvailableStoreInfo; 257 } 258 259 public static class CouponDisplayInfo { 260 @SerializedName("code_display_mode") 261 public CouponCodeDisplayMode codeDisplayMode; 262 263 @SerializedName("background_color") 264 public String backgroundColor; 265 266 @SerializedName("entrance_mini_program") 267 public EntranceMiniProgram entranceMiniProgram; 268 269 @SerializedName("entrance_official_account") 270 public EntranceOfficialAccount entranceOfficialAccount; 271 272 @SerializedName("entrance_finder") 273 public EntranceFinder entranceFinder; 274 } 275 276 public static class NotifyConfig { 277 @SerializedName("notify_appid") 278 public String notifyAppid; 279 } 280 281 public enum StockStoreScope { 282 @SerializedName("NONE") 283 NONE, 284 @SerializedName("ALL") 285 ALL, 286 @SerializedName("SPECIFIC") 287 SPECIFIC 288 } 289 290 public static class StockSentCountInfo { 291 @SerializedName("total_count") 292 public Long totalCount; 293 294 @SerializedName("today_count") 295 public Long todayCount; 296 } 297 298 public enum StockState { 299 @SerializedName("AUDITING") 300 AUDITING, 301 @SerializedName("SENDING") 302 SENDING, 303 @SerializedName("PAUSED") 304 PAUSED, 305 @SerializedName("STOPPED") 306 STOPPED, 307 @SerializedName("DEACTIVATED") 308 DEACTIVATED 309 } 310 311 public static class SingleCouponAvailablePeriod { 312 @SerializedName("available_begin_time") 313 public String availableBeginTime; 314 315 @SerializedName("available_end_time") 316 public String availableEndTime; 317 318 @SerializedName("available_days") 319 public Long availableDays; 320 321 @SerializedName("wait_days_after_receive") 322 public Long waitDaysAfterReceive; 323 324 @SerializedName("weekly_available_period") 325 public FixedWeekPeriod weeklyAvailablePeriod; 326 327 @SerializedName("irregular_available_period_list") 328 public List<TimePeriod> irregularAvailablePeriodList; 329 } 330 331 public static class NormalCouponUsageRule { 332 @SerializedName("threshold") 333 public Long threshold; 334 335 @SerializedName("discount_amount") 336 public Long discountAmount; 337 } 338 339 public static class DiscountCouponUsageRule { 340 @SerializedName("threshold") 341 public Long threshold; 342 343 @SerializedName("percent_off") 344 public Long percentOff; 345 } 346 347 public static class ExchangeCouponUsageRule { 348 @SerializedName("threshold") 349 public Long threshold; 350 351 @SerializedName("exchange_price") 352 public Long exchangePrice; 353 } 354 355 public static class SequentialCouponAvailablePeriod { 356 @SerializedName("available_begin_time") 357 public String availableBeginTime; 358 359 @SerializedName("available_end_time") 360 public String availableEndTime; 361 362 @SerializedName("wait_days_after_receive") 363 public Long waitDaysAfterReceive; 364 365 @SerializedName("weekly_available_period") 366 public FixedWeekPeriod weeklyAvailablePeriod; 367 368 @SerializedName("irregular_available_period_list") 369 public List<TimePeriod> irregularAvailablePeriodList; 370 } 371 372 public enum CouponUsageMethod { 373 @SerializedName("OFFLINE") 374 OFFLINE, 375 @SerializedName("MINI_PROGRAM") 376 MINI_PROGRAM, 377 @SerializedName("APP") 378 APP, 379 @SerializedName("PAYMENT_CODE") 380 PAYMENT_CODE 381 } 382 383 public static class CouponAvailableStoreInfo { 384 @SerializedName("description") 385 public String description; 386 387 @SerializedName("mini_program_appid") 388 public String miniProgramAppid; 389 390 @SerializedName("mini_program_path") 391 public String miniProgramPath; 392 } 393 394 public enum CouponCodeDisplayMode { 395 @SerializedName("INVISIBLE") 396 INVISIBLE, 397 @SerializedName("BARCODE") 398 BARCODE, 399 @SerializedName("QRCODE") 400 QRCODE 401 } 402 403 public static class EntranceMiniProgram { 404 @SerializedName("appid") 405 public String appid; 406 407 @SerializedName("path") 408 public String path; 409 410 @SerializedName("entrance_wording") 411 public String entranceWording; 412 413 @SerializedName("guidance_wording") 414 public String guidanceWording; 415 } 416 417 public static class EntranceOfficialAccount { 418 @SerializedName("appid") 419 public String appid; 420 } 421 422 public static class EntranceFinder { 423 @SerializedName("finder_id") 424 public String finderId; 425 426 @SerializedName("finder_video_id") 427 public String finderVideoId; 428 429 @SerializedName("finder_video_cover_image_url") 430 public String finderVideoCoverImageUrl; 431 } 432 433 public static class FixedWeekPeriod { 434 @SerializedName("day_list") 435 public List<WeekEnum> dayList; 436 437 @SerializedName("day_period_list") 438 public List<PeriodOfTheDay> dayPeriodList; 439 } 440 441 public static class TimePeriod { 442 @SerializedName("begin_time") 443 public String beginTime; 444 445 @SerializedName("end_time") 446 public String endTime; 447 } 448 449 public enum WeekEnum { 450 @SerializedName("MONDAY") 451 MONDAY, 452 @SerializedName("TUESDAY") 453 TUESDAY, 454 @SerializedName("WEDNESDAY") 455 WEDNESDAY, 456 @SerializedName("THURSDAY") 457 THURSDAY, 458 @SerializedName("FRIDAY") 459 FRIDAY, 460 @SerializedName("SATURDAY") 461 SATURDAY, 462 @SerializedName("SUNDAY") 463 SUNDAY 464 } 465 466 public static class PeriodOfTheDay { 467 @SerializedName("begin_time") 468 public Long beginTime; 469 470 @SerializedName("end_time") 471 public Long endTime; 472 } 473 474} 475
需配合微信支付工具库 wxpay_utility 使用,请参考 Go
1package main 2 3import ( 4 "bytes" 5 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 6 "encoding/json" 7 "fmt" 8 "net/http" 9 "net/url" 10 "strings" 11 "time" 12) 13 14func main() { 15 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 config, err := wxpay_utility.CreateMchConfig( 17 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 18 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 19 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 20 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 21 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 22 ) 23 if err != nil { 24 fmt.Println(err) 25 return 26 } 27 28 request := &DeactivateStockRequest{ 29 ProductCouponId: wxpay_utility.String("200000001"), 30 StockId: wxpay_utility.String("123456789"), 31 OutRequestNo: wxpay_utility.String("34657_20250101_123456"), 32 DeactivateReason: wxpay_utility.String("批次信息有误,重新创建"), 33 BrandId: wxpay_utility.String("120344"), 34 } 35 36 response, err := DeactivateStock(config, request) 37 if err != nil { 38 fmt.Printf("请求失败: %+v\n", err) 39 // TODO: 请求失败,根据状态码执行不同的处理 40 return 41 } 42 43 // TODO: 请求成功,继续业务逻辑 44 fmt.Printf("请求成功: %+v\n", response) 45} 46 47func DeactivateStock(config *wxpay_utility.MchConfig, request *DeactivateStockRequest) (response *StockEntity, err error) { 48 const ( 49 host = "https://api.mch.weixin.qq.com" 50 method = "POST" 51 path = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/deactivate" 52 ) 53 54 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 55 if err != nil { 56 return nil, err 57 } 58 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 59 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_id}", url.PathEscape(*request.StockId), -1) 60 reqBody, err := json.Marshal(request) 61 if err != nil { 62 return nil, err 63 } 64 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 65 if err != nil { 66 return nil, err 67 } 68 httpRequest.Header.Set("Accept", "application/json") 69 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 70 httpRequest.Header.Set("Content-Type", "application/json") 71 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 72 if err != nil { 73 return nil, err 74 } 75 httpRequest.Header.Set("Authorization", authorization) 76 77 client := &http.Client{} 78 httpResponse, err := client.Do(httpRequest) 79 if err != nil { 80 return nil, err 81 } 82 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 83 if err != nil { 84 return nil, err 85 } 86 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 87 // 2XX 成功,验证应答签名 88 err = wxpay_utility.ValidateResponse( 89 config.WechatPayPublicKeyId(), 90 config.WechatPayPublicKey(), 91 &httpResponse.Header, 92 respBody, 93 ) 94 if err != nil { 95 return nil, err 96 } 97 response := &StockEntity{} 98 if err := json.Unmarshal(respBody, response); err != nil { 99 return nil, err 100 } 101 102 return response, nil 103 } else { 104 return nil, wxpay_utility.NewApiException( 105 httpResponse.StatusCode, 106 httpResponse.Header, 107 respBody, 108 ) 109 } 110} 111 112type DeactivateStockRequest struct { 113 OutRequestNo *string `json:"out_request_no,omitempty"` 114 ProductCouponId *string `json:"product_coupon_id,omitempty"` 115 StockId *string `json:"stock_id,omitempty"` 116 DeactivateReason *string `json:"deactivate_reason,omitempty"` 117 BrandId *string `json:"brand_id,omitempty"` 118} 119 120func (o *DeactivateStockRequest) MarshalJSON() ([]byte, error) { 121 type Alias DeactivateStockRequest 122 a := &struct { 123 ProductCouponId *string `json:"product_coupon_id,omitempty"` 124 StockId *string `json:"stock_id,omitempty"` 125 *Alias 126 }{ 127 // 序列化时移除非 Body 字段 128 ProductCouponId: nil, 129 StockId: nil, 130 Alias: (*Alias)(o), 131 } 132 return json.Marshal(a) 133} 134 135type StockEntity struct { 136 ProductCouponId *string `json:"product_coupon_id,omitempty"` 137 StockId *string `json:"stock_id,omitempty"` 138 Remark *string `json:"remark,omitempty"` 139 CouponCodeMode *CouponCodeMode `json:"coupon_code_mode,omitempty"` 140 CouponCodeCountInfo *CouponCodeCountInfo `json:"coupon_code_count_info,omitempty"` 141 StockSendRule *StockSendRule `json:"stock_send_rule,omitempty"` 142 SingleUsageRule *SingleUsageRule `json:"single_usage_rule,omitempty"` 143 SequentialUsageRule *SequentialUsageRule `json:"sequential_usage_rule,omitempty"` 144 UsageRuleDisplayInfo *UsageRuleDisplayInfo `json:"usage_rule_display_info,omitempty"` 145 CouponDisplayInfo *CouponDisplayInfo `json:"coupon_display_info,omitempty"` 146 NotifyConfig *NotifyConfig `json:"notify_config,omitempty"` 147 StoreScope *StockStoreScope `json:"store_scope,omitempty"` 148 SentCountInfo *StockSentCountInfo `json:"sent_count_info,omitempty"` 149 State *StockState `json:"state,omitempty"` 150 DeactivateRequestNo *string `json:"deactivate_request_no,omitempty"` 151 DeactivateTime *time.Time `json:"deactivate_time,omitempty"` 152 DeactivateReason *string `json:"deactivate_reason,omitempty"` 153 BrandId *string `json:"brand_id,omitempty"` 154} 155 156type CouponCodeMode string 157 158func (e CouponCodeMode) Ptr() *CouponCodeMode { 159 return &e 160} 161 162const ( 163 COUPONCODEMODE_WECHATPAY CouponCodeMode = "WECHATPAY" 164 COUPONCODEMODE_UPLOAD CouponCodeMode = "UPLOAD" 165 COUPONCODEMODE_API_ASSIGN CouponCodeMode = "API_ASSIGN" 166) 167 168type CouponCodeCountInfo struct { 169 TotalCount *int64 `json:"total_count,omitempty"` 170 AvailableCount *int64 `json:"available_count,omitempty"` 171} 172 173type StockSendRule struct { 174 MaxCount *int64 `json:"max_count,omitempty"` 175 MaxCountPerDay *int64 `json:"max_count_per_day,omitempty"` 176 MaxCountPerUser *int64 `json:"max_count_per_user,omitempty"` 177} 178 179type SingleUsageRule struct { 180 CouponAvailablePeriod *SingleCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 181 NormalCoupon *NormalCouponUsageRule `json:"normal_coupon,omitempty"` 182 DiscountCoupon *DiscountCouponUsageRule `json:"discount_coupon,omitempty"` 183 ExchangeCoupon *ExchangeCouponUsageRule `json:"exchange_coupon,omitempty"` 184} 185 186type SequentialUsageRule struct { 187 CouponAvailablePeriod *SequentialCouponAvailablePeriod `json:"coupon_available_period,omitempty"` 188 NormalCouponList []NormalCouponUsageRule `json:"normal_coupon_list,omitempty"` 189 DiscountCouponList []DiscountCouponUsageRule `json:"discount_coupon_list,omitempty"` 190 ExchangeCouponList []ExchangeCouponUsageRule `json:"exchange_coupon_list,omitempty"` 191 SpecialFirst *bool `json:"special_first,omitempty"` 192} 193 194type UsageRuleDisplayInfo struct { 195 CouponUsageMethodList []CouponUsageMethod `json:"coupon_usage_method_list,omitempty"` 196 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 197 MiniProgramPath *string `json:"mini_program_path,omitempty"` 198 AppPath *string `json:"app_path,omitempty"` 199 UsageDescription *string `json:"usage_description,omitempty"` 200 CouponAvailableStoreInfo *CouponAvailableStoreInfo `json:"coupon_available_store_info,omitempty"` 201} 202 203type CouponDisplayInfo struct { 204 CodeDisplayMode *CouponCodeDisplayMode `json:"code_display_mode,omitempty"` 205 BackgroundColor *string `json:"background_color,omitempty"` 206 EntranceMiniProgram *EntranceMiniProgram `json:"entrance_mini_program,omitempty"` 207 EntranceOfficialAccount *EntranceOfficialAccount `json:"entrance_official_account,omitempty"` 208 EntranceFinder *EntranceFinder `json:"entrance_finder,omitempty"` 209} 210 211type NotifyConfig struct { 212 NotifyAppid *string `json:"notify_appid,omitempty"` 213} 214 215type StockStoreScope string 216 217func (e StockStoreScope) Ptr() *StockStoreScope { 218 return &e 219} 220 221const ( 222 STOCKSTORESCOPE_NONE StockStoreScope = "NONE" 223 STOCKSTORESCOPE_ALL StockStoreScope = "ALL" 224 STOCKSTORESCOPE_SPECIFIC StockStoreScope = "SPECIFIC" 225) 226 227type StockSentCountInfo struct { 228 TotalCount *int64 `json:"total_count,omitempty"` 229 TodayCount *int64 `json:"today_count,omitempty"` 230} 231 232type StockState string 233 234func (e StockState) Ptr() *StockState { 235 return &e 236} 237 238const ( 239 STOCKSTATE_AUDITING StockState = "AUDITING" 240 STOCKSTATE_SENDING StockState = "SENDING" 241 STOCKSTATE_PAUSED StockState = "PAUSED" 242 STOCKSTATE_STOPPED StockState = "STOPPED" 243 STOCKSTATE_DEACTIVATED StockState = "DEACTIVATED" 244) 245 246type SingleCouponAvailablePeriod struct { 247 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 248 AvailableEndTime *string `json:"available_end_time,omitempty"` 249 AvailableDays *int64 `json:"available_days,omitempty"` 250 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 251 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 252 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 253} 254 255type NormalCouponUsageRule struct { 256 Threshold *int64 `json:"threshold,omitempty"` 257 DiscountAmount *int64 `json:"discount_amount,omitempty"` 258} 259 260type DiscountCouponUsageRule struct { 261 Threshold *int64 `json:"threshold,omitempty"` 262 PercentOff *int64 `json:"percent_off,omitempty"` 263} 264 265type ExchangeCouponUsageRule struct { 266 Threshold *int64 `json:"threshold,omitempty"` 267 ExchangePrice *int64 `json:"exchange_price,omitempty"` 268} 269 270type SequentialCouponAvailablePeriod struct { 271 AvailableBeginTime *string `json:"available_begin_time,omitempty"` 272 AvailableEndTime *string `json:"available_end_time,omitempty"` 273 WaitDaysAfterReceive *int64 `json:"wait_days_after_receive,omitempty"` 274 WeeklyAvailablePeriod *FixedWeekPeriod `json:"weekly_available_period,omitempty"` 275 IrregularAvailablePeriodList []TimePeriod `json:"irregular_available_period_list,omitempty"` 276} 277 278type CouponUsageMethod string 279 280func (e CouponUsageMethod) Ptr() *CouponUsageMethod { 281 return &e 282} 283 284const ( 285 COUPONUSAGEMETHOD_OFFLINE CouponUsageMethod = "OFFLINE" 286 COUPONUSAGEMETHOD_MINI_PROGRAM CouponUsageMethod = "MINI_PROGRAM" 287 COUPONUSAGEMETHOD_APP CouponUsageMethod = "APP" 288 COUPONUSAGEMETHOD_PAYMENT_CODE CouponUsageMethod = "PAYMENT_CODE" 289) 290 291type CouponAvailableStoreInfo struct { 292 Description *string `json:"description,omitempty"` 293 MiniProgramAppid *string `json:"mini_program_appid,omitempty"` 294 MiniProgramPath *string `json:"mini_program_path,omitempty"` 295} 296 297type CouponCodeDisplayMode string 298 299func (e CouponCodeDisplayMode) Ptr() *CouponCodeDisplayMode { 300 return &e 301} 302 303const ( 304 COUPONCODEDISPLAYMODE_INVISIBLE CouponCodeDisplayMode = "INVISIBLE" 305 COUPONCODEDISPLAYMODE_BARCODE CouponCodeDisplayMode = "BARCODE" 306 COUPONCODEDISPLAYMODE_QRCODE CouponCodeDisplayMode = "QRCODE" 307) 308 309type EntranceMiniProgram struct { 310 Appid *string `json:"appid,omitempty"` 311 Path *string `json:"path,omitempty"` 312 EntranceWording *string `json:"entrance_wording,omitempty"` 313 GuidanceWording *string `json:"guidance_wording,omitempty"` 314} 315 316type EntranceOfficialAccount struct { 317 Appid *string `json:"appid,omitempty"` 318} 319 320type EntranceFinder struct { 321 FinderId *string `json:"finder_id,omitempty"` 322 FinderVideoId *string `json:"finder_video_id,omitempty"` 323 FinderVideoCoverImageUrl *string `json:"finder_video_cover_image_url,omitempty"` 324} 325 326type FixedWeekPeriod struct { 327 DayList []WeekEnum `json:"day_list,omitempty"` 328 DayPeriodList []PeriodOfTheDay `json:"day_period_list,omitempty"` 329} 330 331type TimePeriod struct { 332 BeginTime *string `json:"begin_time,omitempty"` 333 EndTime *string `json:"end_time,omitempty"` 334} 335 336type WeekEnum string 337 338func (e WeekEnum) Ptr() *WeekEnum { 339 return &e 340} 341 342const ( 343 WEEKENUM_MONDAY WeekEnum = "MONDAY" 344 WEEKENUM_TUESDAY WeekEnum = "TUESDAY" 345 WEEKENUM_WEDNESDAY WeekEnum = "WEDNESDAY" 346 WEEKENUM_THURSDAY WeekEnum = "THURSDAY" 347 WEEKENUM_FRIDAY WeekEnum = "FRIDAY" 348 WEEKENUM_SATURDAY WeekEnum = "SATURDAY" 349 WEEKENUM_SUNDAY WeekEnum = "SUNDAY" 350) 351 352type PeriodOfTheDay struct { 353 BeginTime *int64 `json:"begin_time,omitempty"` 354 EndTime *int64 `json:"end_time,omitempty"` 355} 356
应答参数
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
时提供,返回品牌方调用失效商品券批次接口时传入的失效原因
brand_id 必填 string
【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系
应答示例
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 "brand_id" : "120344" 140} 141
错误码
公共错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
业务错误码
状态码 | 错误码 | 描述 | 解决方案 |
---|---|---|---|
403 | NO_AUTH | 缺少业务相关权限 | 请确认已开通商品券权限 |
404 | NOT_FOUND | 未找到 product_coupon_id 对应的商品券 | 请确认 product_coupon_id 存在且属于当前品牌 |
404 | NOT_FOUND | 未找到 stock_id 对应的商品券批次 | 请确认 stock_id 存在且属于当前商品券 |
429 | RATELIMIT_EXCEEDED | 请求超过接口频率限制 | 请稍后使用原参数重试 |