批次取消关联门店
更新时间:2025.08.04服务商可以通过该接口取消品牌的门店列表与商品券批次的关联关系
前置条件:
已创建
usage_mode不为PROGRESSIVE_BUNDLE的商品券对应的批次批次的
store_scope为SPECIFIC批次未失效或过期
usage_mode为PROGRESSIVE_BUNDLE的批次在批次组内,不可使用本接口,请使用【批次组批量取消关联门店API]
频率限制:20/s
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/disassociate-stores
请求域名:【主域名】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 对应的商品券,且 store_scope 为 SPECIFIC,否则无法取消关联门店
body 包体参数
store_list 必填 array[object]
【门店列表】 商户欲取消关联的门店列表,
单次最多可批量取消200个门店
| 属性 | |
store_id 必填 string 【门店ID】 门店的唯一标识,调用创建品牌门店时由微信支付生成 |
brand_id 必填 string
【品牌ID】 微信支付为品牌方分配的唯一标识,该品牌应与服务商存在授权关系
请求示例
POST
取消关联门店列表
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/product-coupon/product-coupons/1000000013/stocks/1000000013001/disassociate-stores \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "store_list" : [ 8 { 9 "store_id" : "100000001" 10 }, 11 { 12 "store_id" : "100000002" 13 }, 14 { 15 "store_id" : "100000003" 16 }, 17 { 18 "store_id" : "12" 19 } 20 ], 21 "brand_id" : "120344" 22 }' 23
需配合微信支付工具库 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 DisassociateStores { 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}/disassociate-stores"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 DisassociateStores client = new DisassociateStores( 33 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 34 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 35 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 36 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 37 "/path/to/wxp_pub.pem" // 微信支付公钥文件路径,本地文件路径 38 ); 39 40 DisassociateStoresRequest request = new DisassociateStoresRequest(); 41 request.productCouponId = "1000000013"; 42 request.stockId = "1000000013001"; 43 request.storeList = new ArrayList<>(); 44 { 45 StoreInfo storeListItem0 = new StoreInfo(); 46 storeListItem0.storeId = "100000001"; 47 request.storeList.add(storeListItem0); 48 StoreInfo storeListItem1 = new StoreInfo(); 49 storeListItem1.storeId = "100000002"; 50 request.storeList.add(storeListItem1); 51 StoreInfo storeListItem2 = new StoreInfo(); 52 storeListItem2.storeId = "100000003"; 53 request.storeList.add(storeListItem2); 54 StoreInfo storeListItem3 = new StoreInfo(); 55 storeListItem3.storeId = "12"; 56 request.storeList.add(storeListItem3); 57 }; 58 request.brandId = "120344"; 59 try { 60 DisassociateStoresResponse response = client.run(request); 61 // TODO: 请求成功,继续业务逻辑 62 System.out.println(response); 63 } catch (WXPayUtility.ApiException e) { 64 // TODO: 请求失败,根据状态码执行不同的逻辑 65 e.printStackTrace(); 66 } 67 } 68 69 public DisassociateStoresResponse run(DisassociateStoresRequest request) { 70 String uri = PATH; 71 uri = uri.replace("{product_coupon_id}", WXPayUtility.urlEncode(request.productCouponId)); 72 uri = uri.replace("{stock_id}", WXPayUtility.urlEncode(request.stockId)); 73 String reqBody = WXPayUtility.toJson(request); 74 75 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 76 reqBuilder.addHeader("Accept", "application/json"); 77 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 78 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 79 reqBuilder.addHeader("Content-Type", "application/json"); 80 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 81 reqBuilder.method(METHOD, requestBody); 82 Request httpRequest = reqBuilder.build(); 83 84 // 发送HTTP请求 85 OkHttpClient client = new OkHttpClient.Builder().build(); 86 try (Response httpResponse = client.newCall(httpRequest).execute()) { 87 String respBody = WXPayUtility.extractBody(httpResponse); 88 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 89 // 2XX 成功,验证应答签名 90 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 91 httpResponse.headers(), respBody); 92 93 // 从HTTP应答报文构建返回数据 94 return WXPayUtility.fromJson(respBody, DisassociateStoresResponse.class); 95 } else { 96 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 97 } 98 } catch (IOException e) { 99 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 100 } 101 } 102 103 private final String mchid; 104 private final String certificateSerialNo; 105 private final PrivateKey privateKey; 106 private final String wechatPayPublicKeyId; 107 private final PublicKey wechatPayPublicKey; 108 109 public DisassociateStores(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 110 this.mchid = mchid; 111 this.certificateSerialNo = certificateSerialNo; 112 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 113 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 114 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 115 } 116 117 public static class DisassociateStoresRequest { 118 @SerializedName("product_coupon_id") 119 @Expose(serialize = false) 120 public String productCouponId; 121 122 @SerializedName("stock_id") 123 @Expose(serialize = false) 124 public String stockId; 125 126 @SerializedName("store_list") 127 public List<StoreInfo> storeList = new ArrayList<StoreInfo>(); 128 129 @SerializedName("brand_id") 130 public String brandId; 131 } 132 133 public static class DisassociateStoresResponse { 134 @SerializedName("total_count") 135 public Long totalCount; 136 137 @SerializedName("success_store_list") 138 public List<StoreInfo> successStoreList; 139 140 @SerializedName("failed_store_list") 141 public List<FailedStoreInfo> failedStoreList; 142 } 143 144 public static class StoreInfo { 145 @SerializedName("store_id") 146 public String storeId; 147 } 148 149 public static class FailedStoreInfo { 150 @SerializedName("store_id") 151 public String storeId; 152 153 @SerializedName("code") 154 public String code; 155 156 @SerializedName("message") 157 public String message; 158 } 159 160} 161
需配合微信支付工具库 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) 12 13func main() { 14 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 15 config, err := wxpay_utility.CreateMchConfig( 16 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 17 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 18 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 19 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 20 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 21 ) 22 if err != nil { 23 fmt.Println(err) 24 return 25 } 26 27 request := &DisassociateStoresRequest{ 28 ProductCouponId: wxpay_utility.String("1000000013"), 29 StockId: wxpay_utility.String("1000000013001"), 30 StoreList: []StoreInfo{ 31 StoreInfo{ 32 StoreId: wxpay_utility.String("100000001"), 33 }, 34 StoreInfo{ 35 StoreId: wxpay_utility.String("100000002"), 36 }, 37 StoreInfo{ 38 StoreId: wxpay_utility.String("100000003"), 39 }, 40 StoreInfo{ 41 StoreId: wxpay_utility.String("12"), 42 }, 43 }, 44 BrandId: wxpay_utility.String("120344"), 45 } 46 47 response, err := DisassociateStores(config, request) 48 if err != nil { 49 fmt.Printf("请求失败: %+v\n", err) 50 // TODO: 请求失败,根据状态码执行不同的处理 51 return 52 } 53 54 // TODO: 请求成功,继续业务逻辑 55 fmt.Printf("请求成功: %+v\n", response) 56} 57 58func DisassociateStores(config *wxpay_utility.MchConfig, request *DisassociateStoresRequest) (response *DisassociateStoresResponse, err error) { 59 const ( 60 host = "https://api.mch.weixin.qq.com" 61 method = "POST" 62 path = "/v3/marketing/partner/product-coupon/product-coupons/{product_coupon_id}/stocks/{stock_id}/disassociate-stores" 63 ) 64 65 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 66 if err != nil { 67 return nil, err 68 } 69 reqUrl.Path = strings.Replace(reqUrl.Path, "{product_coupon_id}", url.PathEscape(*request.ProductCouponId), -1) 70 reqUrl.Path = strings.Replace(reqUrl.Path, "{stock_id}", url.PathEscape(*request.StockId), -1) 71 reqBody, err := json.Marshal(request) 72 if err != nil { 73 return nil, err 74 } 75 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 76 if err != nil { 77 return nil, err 78 } 79 httpRequest.Header.Set("Accept", "application/json") 80 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 81 httpRequest.Header.Set("Content-Type", "application/json") 82 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 83 if err != nil { 84 return nil, err 85 } 86 httpRequest.Header.Set("Authorization", authorization) 87 88 client := &http.Client{} 89 httpResponse, err := client.Do(httpRequest) 90 if err != nil { 91 return nil, err 92 } 93 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 94 if err != nil { 95 return nil, err 96 } 97 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 98 // 2XX 成功,验证应答签名 99 err = wxpay_utility.ValidateResponse( 100 config.WechatPayPublicKeyId(), 101 config.WechatPayPublicKey(), 102 &httpResponse.Header, 103 respBody, 104 ) 105 if err != nil { 106 return nil, err 107 } 108 response := &DisassociateStoresResponse{} 109 if err := json.Unmarshal(respBody, response); err != nil { 110 return nil, err 111 } 112 113 return response, nil 114 } else { 115 return nil, wxpay_utility.NewApiException( 116 httpResponse.StatusCode, 117 httpResponse.Header, 118 respBody, 119 ) 120 } 121} 122 123type DisassociateStoresRequest struct { 124 ProductCouponId *string `json:"product_coupon_id,omitempty"` 125 StockId *string `json:"stock_id,omitempty"` 126 StoreList []StoreInfo `json:"store_list,omitempty"` 127 BrandId *string `json:"brand_id,omitempty"` 128} 129 130func (o *DisassociateStoresRequest) MarshalJSON() ([]byte, error) { 131 type Alias DisassociateStoresRequest 132 a := &struct { 133 ProductCouponId *string `json:"product_coupon_id,omitempty"` 134 StockId *string `json:"stock_id,omitempty"` 135 *Alias 136 }{ 137 // 序列化时移除非 Body 字段 138 ProductCouponId: nil, 139 StockId: nil, 140 Alias: (*Alias)(o), 141 } 142 return json.Marshal(a) 143} 144 145type DisassociateStoresResponse struct { 146 TotalCount *int64 `json:"total_count,omitempty"` 147 SuccessStoreList []StoreInfo `json:"success_store_list,omitempty"` 148 FailedStoreList []FailedStoreInfo `json:"failed_store_list,omitempty"` 149} 150 151type StoreInfo struct { 152 StoreId *string `json:"store_id,omitempty"` 153} 154 155type FailedStoreInfo struct { 156 StoreId *string `json:"store_id,omitempty"` 157 Code *string `json:"code,omitempty"` 158 Message *string `json:"message,omitempty"` 159} 160
应答参数
200 OK
total_count 必填 integer
【去重后门店总数】 系统会自动对请求中的门店去重,这里是去重后的门店总数
success_store_list 选填 array[object]
【取消关联成功的门店列表】 取消关联成功的门店列表
| 属性 | |
store_id 必填 string 【门店ID】 门店的唯一标识,调用创建品牌门店时由微信支付生成 |
failed_store_list 选填 array[object]
【取消关联失败的门店列表】 每个取消关联失败门店的详细错误信息
| 属性 | |
store_id 必填 string 【门店ID】 取消关联失败的门店ID code 必填 string(40) 【失败错误码】 门店取消关联失败的错误码 message 必填 string(200) 【失败错误信息】 门店取消关联失败的错误描述 |
应答示例
200 OK
取消关联门店列表
1{ 2 "total_count" : 3, 3 "success_store_list" : [ 4 { 5 "store_id" : "100000001" 6 }, 7 { 8 "store_id" : "100000002" 9 } 10 ], 11 "failed_store_list" : [ 12 { 13 "store_id" : "12", 14 "code" : "INVALID_REQUEST", 15 "message" : "门店ID非法或不属于当前品牌" 16 } 17 ] 18} 19
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
状态码 | 错误码 | 描述 | 解决方案 |
|---|---|---|---|
400 | PARAM_ERROR | 参数错误 | 请根据错误提示正确传入参数 |
400 | INVALID_REQUEST | HTTP 请求不符合微信支付 APIv3 接口规则 | 请参阅 接口规则 |
401 | SIGN_ERROR | 验证不通过 | 请参阅 签名常见问题 |
500 | SYSTEM_ERROR | 系统异常,请稍后重试 | 请稍后重试 |
400 | INVALID_REQUEST | 已过期的批次不可取消关联门店 | 请确认批次是否处于有效期 |
400 | INVALID_REQUEST | 只有 store_scope 为 SPECIFIC 的批次可以取消关联门店 | 请确认批次 store_scope 为 SPECIFIC 再调用本接口 |
404 | NOT_FOUND | 未找到 product_coupon_id 对应的商品券 | 请确认 product_coupon_id 存在且属于当前品牌 |
404 | NOT_FOUND | 未找到 stock_id 对应的商品券批次 | 请确认 stock_id 存在且属于当前商品券 |
429 | RATELIMIT_EXCEEDED | 请求超过接口频率限制 | 请稍后使用原参数重试 |
