更新投放计划
更新时间:2025.09.27更新投放计划
接口说明
支持商户:【普通服务商】
请求方式:【PATCH】/v3/marketing/partner/delivery-plan/delivery-plans/{plan_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
path 路径参数
plan_id 必填 string
【投放计划ID】 创建生成的投放计划 ID
body 包体参数
modify_content 必填 object
【修改内容】 修改内容,修改哪个字段就填入哪个字段
属性 | |
plan_name 选填 string(30) 【投放计划名称】 投放计划,用于内部管理,不做C端展示 delivery_end_time 选填 string 【投放结束时间】 【投放结束时间】 投放结束时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/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秒。 total_count 选填 integer 【投放总数量,库存】 约定了投放计划的总投放库存,创建投放计划的券可用库存需在 10000 以上;非必填,如未填写, 表示投放计划层不限制,投放将以批次库存为准,且后续修改不支持修改投放库存。 user_limit 选填 integer 【单用户领取上限】 单用户领取上限 daily_limit 选填 integer 【投放计划单日领取上限】 投放计划单日领取上限 recommend_word 选填 string(9) 【投放计划推荐语】 用于在“今日”二选一卡片左上角等场景展示推荐语 自定义文案,9 个中文字符以内 |
请求示例
PATCH
1curl -X PATCH \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/delivery-plan/delivery-plans/12000 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" \ 5 -H "Content-Type: application/json" \ 6 -d '{ 7 "modify_content" : { 8 "plan_name" : "冬季促销", 9 "delivery_end_time" : "2025-01-01T00:00:00+08:00", 10 "total_count" : 1, 11 "user_limit" : 1, 12 "daily_limit" : 1, 13 "recommend_word" : "冬季优惠" 14 } 15 }' 16
需配合微信支付工具库 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 UpdateDeliveryPlan { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "PATCH"; 28 private static String PATH = "/v3/marketing/partner/delivery-plan/delivery-plans/{plan_id}"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 UpdateDeliveryPlan client = new UpdateDeliveryPlan( 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 UpdateDeliveryPlanRequest request = new UpdateDeliveryPlanRequest(); 41 request.planId = "12000"; 42 request.modifyContent = new PlanModifyContent(); 43 request.modifyContent.planName = "冬季促销"; 44 request.modifyContent.deliveryEndTime = "2025-01-01T00:00:00+08:00"; 45 request.modifyContent.totalCount = 1L; 46 request.modifyContent.userLimit = 1L; 47 request.modifyContent.dailyLimit = 1L; 48 request.modifyContent.recommendWord = "冬季优惠"; 49 try { 50 UpdateDeliveryPlanResponse response = client.run(request); 51 // TODO: 请求成功,继续业务逻辑 52 System.out.println(response); 53 } catch (WXPayUtility.ApiException e) { 54 // TODO: 请求失败,根据状态码执行不同的逻辑 55 e.printStackTrace(); 56 } 57 } 58 59 public UpdateDeliveryPlanResponse run(UpdateDeliveryPlanRequest request) { 60 String uri = PATH; 61 uri = uri.replace("{plan_id}", WXPayUtility.urlEncode(request.planId)); 62 String reqBody = WXPayUtility.toJson(request); 63 64 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 65 reqBuilder.addHeader("Accept", "application/json"); 66 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 67 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo,privateKey, METHOD, uri, reqBody)); 68 reqBuilder.addHeader("Content-Type", "application/json"); 69 RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), reqBody); 70 reqBuilder.method(METHOD, requestBody); 71 Request httpRequest = reqBuilder.build(); 72 73 // 发送HTTP请求 74 OkHttpClient client = new OkHttpClient.Builder().build(); 75 try (Response httpResponse = client.newCall(httpRequest).execute()) { 76 String respBody = WXPayUtility.extractBody(httpResponse); 77 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 78 // 2XX 成功,验证应答签名 79 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 80 httpResponse.headers(), respBody); 81 82 // 从HTTP应答报文构建返回数据 83 return WXPayUtility.fromJson(respBody, UpdateDeliveryPlanResponse.class); 84 } else { 85 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 86 } 87 } catch (IOException e) { 88 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 89 } 90 } 91 92 private final String mchid; 93 private final String certificateSerialNo; 94 private final PrivateKey privateKey; 95 private final String wechatPayPublicKeyId; 96 private final PublicKey wechatPayPublicKey; 97 98 public UpdateDeliveryPlan(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 99 this.mchid = mchid; 100 this.certificateSerialNo = certificateSerialNo; 101 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 102 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 103 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 104 } 105 106 public static class UpdateDeliveryPlanRequest { 107 @SerializedName("plan_id") 108 @Expose(serialize = false) 109 public String planId; 110 111 @SerializedName("modify_content") 112 public PlanModifyContent modifyContent; 113 } 114 115 public static class UpdateDeliveryPlanResponse { 116 @SerializedName("plan") 117 public DeliveryPlan plan; 118 } 119 120 public static class PlanModifyContent { 121 @SerializedName("plan_name") 122 public String planName; 123 124 @SerializedName("delivery_end_time") 125 public String deliveryEndTime; 126 127 @SerializedName("total_count") 128 public Long totalCount; 129 130 @SerializedName("user_limit") 131 public Long userLimit; 132 133 @SerializedName("daily_limit") 134 public Long dailyLimit; 135 136 @SerializedName("recommend_word") 137 public String recommendWord; 138 } 139 140 public static class DeliveryPlan { 141 @SerializedName("plan_id") 142 public String planId; 143 144 @SerializedName("plan_name") 145 public String planName; 146 147 @SerializedName("plan_state") 148 public PlanState planState; 149 150 @SerializedName("delivery_start_time") 151 public String deliveryStartTime; 152 153 @SerializedName("delivery_end_time") 154 public String deliveryEndTime; 155 156 @SerializedName("stock_id") 157 public String stockId; 158 159 @SerializedName("product_coupon_id") 160 public String productCouponId; 161 162 @SerializedName("recommend_word") 163 public String recommendWord; 164 165 @SerializedName("brand_id") 166 public Long brandId; 167 168 @SerializedName("total_count") 169 public Long totalCount; 170 171 @SerializedName("user_limit") 172 public Long userLimit; 173 174 @SerializedName("daily_limit") 175 public Long dailyLimit; 176 } 177 178 public enum PlanState { 179 @SerializedName("PLAN_CREATING") 180 PLAN_CREATING, 181 @SerializedName("PLAN_CREATED") 182 PLAN_CREATED, 183 @SerializedName("PLAN_TERMINATING") 184 PLAN_TERMINATING, 185 @SerializedName("PLAN_TERMINATED") 186 PLAN_TERMINATED, 187 @SerializedName("PLAN_EXPIRED") 188 PLAN_EXPIRED, 189 @SerializedName("PLAN_DELIVERING") 190 PLAN_DELIVERING, 191 @SerializedName("PLAN_PAUSED") 192 PLAN_PAUSED 193 } 194 195} 196
需配合微信支付工具库 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 := &UpdateDeliveryPlanRequest{ 28 PlanId: wxpay_utility.String("12000"), 29 ModifyContent: &PlanModifyContent{ 30 PlanName: wxpay_utility.String("冬季促销"), 31 DeliveryEndTime: wxpay_utility.String("2025-01-01T00:00:00+08:00"), 32 TotalCount: wxpay_utility.Int64(1), 33 UserLimit: wxpay_utility.Int64(1), 34 DailyLimit: wxpay_utility.Int64(1), 35 RecommendWord: wxpay_utility.String("冬季优惠"), 36 }, 37 } 38 39 response, err := UpdateDeliveryPlan(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 UpdateDeliveryPlan(config *wxpay_utility.MchConfig, request *UpdateDeliveryPlanRequest) (response *UpdateDeliveryPlanResponse, err error) { 51 const ( 52 host = "https://api.mch.weixin.qq.com" 53 method = "PATCH" 54 path = "/v3/marketing/partner/delivery-plan/delivery-plans/{plan_id}" 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, "{plan_id}", url.PathEscape(*request.PlanId), -1) 62 reqBody, err := json.Marshal(request) 63 if err != nil { 64 return nil, err 65 } 66 httpRequest, err := http.NewRequest(method, reqUrl.String(), bytes.NewReader(reqBody)) 67 if err != nil { 68 return nil, err 69 } 70 httpRequest.Header.Set("Accept", "application/json") 71 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 72 httpRequest.Header.Set("Content-Type", "application/json") 73 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), reqBody) 74 if err != nil { 75 return nil, err 76 } 77 httpRequest.Header.Set("Authorization", authorization) 78 79 client := &http.Client{} 80 httpResponse, err := client.Do(httpRequest) 81 if err != nil { 82 return nil, err 83 } 84 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 85 if err != nil { 86 return nil, err 87 } 88 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 89 // 2XX 成功,验证应答签名 90 err = wxpay_utility.ValidateResponse( 91 config.WechatPayPublicKeyId(), 92 config.WechatPayPublicKey(), 93 &httpResponse.Header, 94 respBody, 95 ) 96 if err != nil { 97 return nil, err 98 } 99 response := &UpdateDeliveryPlanResponse{} 100 if err := json.Unmarshal(respBody, response); err != nil { 101 return nil, err 102 } 103 104 return response, nil 105 } else { 106 return nil, wxpay_utility.NewApiException( 107 httpResponse.StatusCode, 108 httpResponse.Header, 109 respBody, 110 ) 111 } 112} 113 114type UpdateDeliveryPlanRequest struct { 115 PlanId *string `json:"plan_id,omitempty"` 116 ModifyContent *PlanModifyContent `json:"modify_content,omitempty"` 117} 118 119func (o *UpdateDeliveryPlanRequest) MarshalJSON() ([]byte, error) { 120 type Alias UpdateDeliveryPlanRequest 121 a := &struct { 122 PlanId *string `json:"plan_id,omitempty"` 123 *Alias 124 }{ 125 // 序列化时移除非 Body 字段 126 PlanId: nil, 127 Alias: (*Alias)(o), 128 } 129 return json.Marshal(a) 130} 131 132type UpdateDeliveryPlanResponse struct { 133 Plan *DeliveryPlan `json:"plan,omitempty"` 134} 135 136type PlanModifyContent struct { 137 PlanName *string `json:"plan_name,omitempty"` 138 DeliveryEndTime *string `json:"delivery_end_time,omitempty"` 139 TotalCount *int64 `json:"total_count,omitempty"` 140 UserLimit *int64 `json:"user_limit,omitempty"` 141 DailyLimit *int64 `json:"daily_limit,omitempty"` 142 RecommendWord *string `json:"recommend_word,omitempty"` 143} 144 145type DeliveryPlan struct { 146 PlanId *string `json:"plan_id,omitempty"` 147 PlanName *string `json:"plan_name,omitempty"` 148 PlanState *PlanState `json:"plan_state,omitempty"` 149 DeliveryStartTime *string `json:"delivery_start_time,omitempty"` 150 DeliveryEndTime *string `json:"delivery_end_time,omitempty"` 151 StockId *string `json:"stock_id,omitempty"` 152 ProductCouponId *string `json:"product_coupon_id,omitempty"` 153 RecommendWord *string `json:"recommend_word,omitempty"` 154 BrandId *int64 `json:"brand_id,omitempty"` 155 TotalCount *int64 `json:"total_count,omitempty"` 156 UserLimit *int64 `json:"user_limit,omitempty"` 157 DailyLimit *int64 `json:"daily_limit,omitempty"` 158} 159 160type PlanState string 161 162func (e PlanState) Ptr() *PlanState { 163 return &e 164} 165 166const ( 167 PLANSTATE_PLAN_CREATING PlanState = "PLAN_CREATING" 168 PLANSTATE_PLAN_CREATED PlanState = "PLAN_CREATED" 169 PLANSTATE_PLAN_TERMINATING PlanState = "PLAN_TERMINATING" 170 PLANSTATE_PLAN_TERMINATED PlanState = "PLAN_TERMINATED" 171 PLANSTATE_PLAN_EXPIRED PlanState = "PLAN_EXPIRED" 172 PLANSTATE_PLAN_DELIVERING PlanState = "PLAN_DELIVERING" 173 PLANSTATE_PLAN_PAUSED PlanState = "PLAN_PAUSED" 174) 175
应答参数
200 OK
plan 必填 object
【投放计划详情】 修改后的投放计划详情
属性 | |
plan_id 必填 string 【投放计划ID】 投放计划ID plan_name 必填 string 【投放计划名称】 投放计划名称 plan_state 必填 string 【投放计划状态】 投放计划状态 可选取值
delivery_start_time 选填 string 【投放开始时间】 【投放开始时间】 投放开始时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/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秒。 delivery_end_time 选填 string 【结束可用时间】 【投放结束时间】 投放结束时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/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秒。 stock_id 必填 string(40) 【券批次ID】 券批次ID product_coupon_id 必填 string(40) 【商品券ID】 商品券ID recommend_word 选填 string(9) 【营销标签】 用于在优惠左上角展示的运营推荐语信息 自定义文案,不超过 9 个中文字符或18 个英文字符 brand_id 必填 integer 【品牌ID】 创建投放计划的品牌ID,可登录品牌经营平台查看品牌 ID 信息 total_count 选填 integer 【投放总数量,库存】 约定了投放计划的总投放库存,创建投放计划的券可用库存需在 10000 以上;非必填,如未填写, 表示投放计划层不限制,投放将以批次库存为准,且后续修改不支持修改投放库存。 user_limit 选填 integer 【单用户领取上限】 单用户领取上限 daily_limit 选填 integer 【投放计划单日领取上限】 用于约定投放计划单日可领取的最大数量,如创建时未填写,则修改时不支持填写。 |
应答示例
200 OK
1{ 2 "plan" : { 3 "plan_id" : "12000", 4 "plan_name" : "冬季优惠投放", 5 "plan_state" : "PLAN_CREATED", 6 "delivery_start_time" : "2025-01-01T00:00:00+08:00", 7 "delivery_end_time" : "2025-01-01T00:00:00+08:00", 8 "stock_id" : "123456789", 9 "product_coupon_id" : "1000000013", 10 "recommend_word" : "天天有惊喜", 11 "brand_id" : 40016, 12 "total_count" : 11000, 13 "user_limit" : 5, 14 "daily_limit" : 100 15 } 16} 17
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示