分页查询投放计划列表
更新时间:2025.09.27分页查询投放计划列表
接口说明
支持商户:【普通服务商】
请求方式:【GET】/v3/marketing/partner/delivery-plan/delivery-plans/{brand_id}/delivery-plans
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
brand_id 必填 string
【品牌ID】 品牌ID
query 查询参数
page_size 选填 integer
【分页大小】 批量查询下每页的数量,最大不超过50
offset 选填 integer
【offset】 该次请求资源的起始位置
plan_state 选填 string
【投放计划线上状态】 · 不填写表示返回所有线上状态的投放计划 · 填写表示过滤特定状态 线上状态包含: · 创建成功 · 投放中 · 活动暂停 · 活动终止 · 活动过期
可选取值
PLAN_CREATING
: 创建中PLAN_CREATED
: 创建成功PLAN_TERMINATING
: 终止中PLAN_TERMINATED
: 已终止PLAN_EXPIRED
: 已过期PLAN_DELIVERING
: 投放中PLAN_PAUSED
: 已暂停
audit_state 选填 string
【投放计划审核状态】 · 不填写表示所有审核状态的投放计划 · 填写表示过滤特定状态 审核状态包含: · 审核中 · 审核通过 · 审核不通过
可选取值
AUDIT_INITIAL
: 初始化AUDIT_PROCESSING
: 审批中AUDIT_PASSED
: 审批通过AUDIT_REJECTED
: 审批拒绝
plan_id 选填 string
【投放计划ID】 投放计划ID,如果填入该字段,则只返回该ID对应的投放计划
请求示例
GET
1curl -X GET \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/delivery-plan/delivery-plans/40016/delivery-plans?page_size=5&offset=10&plan_state=PLAN_CREATING&audit_state=AUDIT_INITIAL&plan_id=12000 \ 3 -H "Authorization: WECHATPAY2-SHA256-RSA2048 mchid=\"1900000001\",..." \ 4 -H "Accept: application/json" 5
需配合微信支付工具库 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 ListDeliveryPlans { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "GET"; 28 private static String PATH = "/v3/marketing/partner/delivery-plan/delivery-plans/{brand_id}/delivery-plans"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 ListDeliveryPlans client = new ListDeliveryPlans( 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 ListDeliveryPlansRequest request = new ListDeliveryPlansRequest(); 41 request.brandId = "40016"; 42 request.pageSize = 5L; 43 request.offset = 10L; 44 request.planState = PlanState.PLAN_CREATING; 45 request.auditState = PlanAuditState.AUDIT_INITIAL; 46 request.planId = "12000"; 47 try { 48 ListDeliveryPlansResponse 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 ListDeliveryPlansResponse run(ListDeliveryPlansRequest request) { 58 String uri = PATH; 59 uri = uri.replace("{brand_id}", WXPayUtility.urlEncode(request.brandId)); 60 Map<String, Object> args = new HashMap<>(); 61 args.put("page_size", request.pageSize); 62 args.put("offset", request.offset); 63 args.put("plan_state", request.planState); 64 args.put("audit_state", request.auditState); 65 args.put("plan_id", request.planId); 66 String queryString = WXPayUtility.urlEncode(args); 67 if (!queryString.isEmpty()) { 68 uri = uri + "?" + queryString; 69 } 70 71 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 72 reqBuilder.addHeader("Accept", "application/json"); 73 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 74 reqBuilder.addHeader("Authorization", WXPayUtility.buildAuthorization(mchid, certificateSerialNo, privateKey, METHOD, uri, null)); 75 reqBuilder.method(METHOD, null); 76 Request httpRequest = reqBuilder.build(); 77 78 // 发送HTTP请求 79 OkHttpClient client = new OkHttpClient.Builder().build(); 80 try (Response httpResponse = client.newCall(httpRequest).execute()) { 81 String respBody = WXPayUtility.extractBody(httpResponse); 82 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 83 // 2XX 成功,验证应答签名 84 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 85 httpResponse.headers(), respBody); 86 87 // 从HTTP应答报文构建返回数据 88 return WXPayUtility.fromJson(respBody, ListDeliveryPlansResponse.class); 89 } else { 90 throw new WXPayUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 91 } 92 } catch (IOException e) { 93 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 94 } 95 } 96 97 private final String mchid; 98 private final String certificateSerialNo; 99 private final PrivateKey privateKey; 100 private final String wechatPayPublicKeyId; 101 private final PublicKey wechatPayPublicKey; 102 103 public ListDeliveryPlans(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 104 this.mchid = mchid; 105 this.certificateSerialNo = certificateSerialNo; 106 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 107 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 108 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 109 } 110 111 public static class ListDeliveryPlansRequest { 112 @SerializedName("brand_id") 113 @Expose(serialize = false) 114 public String brandId; 115 116 @SerializedName("page_size") 117 @Expose(serialize = false) 118 public Long pageSize; 119 120 @SerializedName("offset") 121 @Expose(serialize = false) 122 public Long offset; 123 124 @SerializedName("plan_id") 125 @Expose(serialize = false) 126 public String planId; 127 128 @SerializedName("plan_state") 129 @Expose(serialize = false) 130 public PlanState planState; 131 132 @SerializedName("audit_state") 133 @Expose(serialize = false) 134 public PlanAuditState auditState; 135 } 136 137 public static class ListDeliveryPlansResponse { 138 @SerializedName("total_count") 139 public Long totalCount; 140 141 @SerializedName("plan_list") 142 public List<DeliveryPlan> planList; 143 } 144 145 public enum PlanState { 146 @SerializedName("PLAN_CREATING") 147 PLAN_CREATING, 148 @SerializedName("PLAN_CREATED") 149 PLAN_CREATED, 150 @SerializedName("PLAN_TERMINATING") 151 PLAN_TERMINATING, 152 @SerializedName("PLAN_TERMINATED") 153 PLAN_TERMINATED, 154 @SerializedName("PLAN_EXPIRED") 155 PLAN_EXPIRED, 156 @SerializedName("PLAN_DELIVERING") 157 PLAN_DELIVERING, 158 @SerializedName("PLAN_PAUSED") 159 PLAN_PAUSED 160 } 161 162 public enum PlanAuditState { 163 @SerializedName("AUDIT_INITIAL") 164 AUDIT_INITIAL, 165 @SerializedName("AUDIT_PROCESSING") 166 AUDIT_PROCESSING, 167 @SerializedName("AUDIT_PASSED") 168 AUDIT_PASSED, 169 @SerializedName("AUDIT_REJECTED") 170 AUDIT_REJECTED 171 } 172 173 public static class DeliveryPlan { 174 @SerializedName("plan_id") 175 public String planId; 176 177 @SerializedName("plan_name") 178 public String planName; 179 180 @SerializedName("plan_state") 181 public PlanState planState; 182 183 @SerializedName("delivery_start_time") 184 public String deliveryStartTime; 185 186 @SerializedName("delivery_end_time") 187 public String deliveryEndTime; 188 189 @SerializedName("stock_id") 190 public String stockId; 191 192 @SerializedName("product_coupon_id") 193 public String productCouponId; 194 195 @SerializedName("recommend_word") 196 public String recommendWord; 197 198 @SerializedName("brand_id") 199 public Long brandId; 200 201 @SerializedName("total_count") 202 public Long totalCount; 203 204 @SerializedName("user_limit") 205 public Long userLimit; 206 207 @SerializedName("daily_limit") 208 public Long dailyLimit; 209 } 210 211} 212
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/v3/partner/4015119446 5 "encoding/json" 6 "fmt" 7 "net/http" 8 "net/url" 9 "strings" 10) 11 12func main() { 13 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 14 config, err := wxpay_utility.CreateMchConfig( 15 "19xxxxxxxx", // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/partner/4013080340 16 "1DDE55AD98Exxxxxxxxxx", // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013058924 17 "/path/to/apiclient_key.pem", // 商户API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/partner/4013038589 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &ListDeliveryPlansRequest{ 27 BrandId: wxpay_utility.String("40016"), 28 PageSize: wxpay_utility.Int64(5), 29 Offset: wxpay_utility.Int64(10), 30 PlanState: PLANSTATE_PLAN_CREATING.Ptr(), 31 AuditState: PLANAUDITSTATE_AUDIT_INITIAL.Ptr(), 32 PlanId: wxpay_utility.String("12000"), 33 } 34 35 response, err := ListDeliveryPlans(config, request) 36 if err != nil { 37 fmt.Printf("请求失败: %+v\n", err) 38 // TODO: 请求失败,根据状态码执行不同的处理 39 return 40 } 41 42 // TODO: 请求成功,继续业务逻辑 43 fmt.Printf("请求成功: %+v\n", response) 44} 45 46func ListDeliveryPlans(config *wxpay_utility.MchConfig, request *ListDeliveryPlansRequest) (response *ListDeliveryPlansResponse, err error) { 47 const ( 48 host = "https://api.mch.weixin.qq.com" 49 method = "GET" 50 path = "/v3/marketing/partner/delivery-plan/delivery-plans/{brand_id}/delivery-plans" 51 ) 52 53 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 54 if err != nil { 55 return nil, err 56 } 57 reqUrl.Path = strings.Replace(reqUrl.Path, "{brand_id}", url.PathEscape(*request.BrandId), -1) 58 query := reqUrl.Query() 59 if request.PageSize != nil { 60 query.Add("page_size", fmt.Sprintf("%v", *request.PageSize)) 61 } 62 if request.Offset != nil { 63 query.Add("offset", fmt.Sprintf("%v", *request.Offset)) 64 } 65 if request.PlanState != nil { 66 query.Add("plan_state", fmt.Sprintf("%v", *request.PlanState)) 67 } 68 if request.AuditState != nil { 69 query.Add("audit_state", fmt.Sprintf("%v", *request.AuditState)) 70 } 71 if request.PlanId != nil { 72 query.Add("plan_id", *request.PlanId) 73 } 74 reqUrl.RawQuery = query.Encode() 75 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 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 authorization, err := wxpay_utility.BuildAuthorization(config.MchId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 82 if err != nil { 83 return nil, err 84 } 85 httpRequest.Header.Set("Authorization", authorization) 86 87 client := &http.Client{} 88 httpResponse, err := client.Do(httpRequest) 89 if err != nil { 90 return nil, err 91 } 92 respBody, err := wxpay_utility.ExtractResponseBody(httpResponse) 93 if err != nil { 94 return nil, err 95 } 96 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 97 // 2XX 成功,验证应答签名 98 err = wxpay_utility.ValidateResponse( 99 config.WechatPayPublicKeyId(), 100 config.WechatPayPublicKey(), 101 &httpResponse.Header, 102 respBody, 103 ) 104 if err != nil { 105 return nil, err 106 } 107 response := &ListDeliveryPlansResponse{} 108 if err := json.Unmarshal(respBody, response); err != nil { 109 return nil, err 110 } 111 112 return response, nil 113 } else { 114 return nil, wxpay_utility.NewApiException( 115 httpResponse.StatusCode, 116 httpResponse.Header, 117 respBody, 118 ) 119 } 120} 121 122type ListDeliveryPlansRequest struct { 123 BrandId *string `json:"brand_id,omitempty"` 124 PageSize *int64 `json:"page_size,omitempty"` 125 Offset *int64 `json:"offset,omitempty"` 126 PlanId *string `json:"plan_id,omitempty"` 127 PlanState *PlanState `json:"plan_state,omitempty"` 128 AuditState *PlanAuditState `json:"audit_state,omitempty"` 129} 130 131func (o *ListDeliveryPlansRequest) MarshalJSON() ([]byte, error) { 132 type Alias ListDeliveryPlansRequest 133 a := &struct { 134 BrandId *string `json:"brand_id,omitempty"` 135 PageSize *int64 `json:"page_size,omitempty"` 136 Offset *int64 `json:"offset,omitempty"` 137 PlanId *string `json:"plan_id,omitempty"` 138 PlanState *PlanState `json:"plan_state,omitempty"` 139 AuditState *PlanAuditState `json:"audit_state,omitempty"` 140 *Alias 141 }{ 142 // 序列化时移除非 Body 字段 143 BrandId: nil, 144 PageSize: nil, 145 Offset: nil, 146 PlanId: nil, 147 PlanState: nil, 148 AuditState: nil, 149 Alias: (*Alias)(o), 150 } 151 return json.Marshal(a) 152} 153 154type ListDeliveryPlansResponse struct { 155 TotalCount *int64 `json:"total_count,omitempty"` 156 PlanList []DeliveryPlan `json:"plan_list,omitempty"` 157} 158 159type PlanState string 160 161func (e PlanState) Ptr() *PlanState { 162 return &e 163} 164 165const ( 166 PLANSTATE_PLAN_CREATING PlanState = "PLAN_CREATING" 167 PLANSTATE_PLAN_CREATED PlanState = "PLAN_CREATED" 168 PLANSTATE_PLAN_TERMINATING PlanState = "PLAN_TERMINATING" 169 PLANSTATE_PLAN_TERMINATED PlanState = "PLAN_TERMINATED" 170 PLANSTATE_PLAN_EXPIRED PlanState = "PLAN_EXPIRED" 171 PLANSTATE_PLAN_DELIVERING PlanState = "PLAN_DELIVERING" 172 PLANSTATE_PLAN_PAUSED PlanState = "PLAN_PAUSED" 173) 174 175type PlanAuditState string 176 177func (e PlanAuditState) Ptr() *PlanAuditState { 178 return &e 179} 180 181const ( 182 PLANAUDITSTATE_AUDIT_INITIAL PlanAuditState = "AUDIT_INITIAL" 183 PLANAUDITSTATE_AUDIT_PROCESSING PlanAuditState = "AUDIT_PROCESSING" 184 PLANAUDITSTATE_AUDIT_PASSED PlanAuditState = "AUDIT_PASSED" 185 PLANAUDITSTATE_AUDIT_REJECTED PlanAuditState = "AUDIT_REJECTED" 186) 187 188type DeliveryPlan struct { 189 PlanId *string `json:"plan_id,omitempty"` 190 PlanName *string `json:"plan_name,omitempty"` 191 PlanState *PlanState `json:"plan_state,omitempty"` 192 DeliveryStartTime *string `json:"delivery_start_time,omitempty"` 193 DeliveryEndTime *string `json:"delivery_end_time,omitempty"` 194 StockId *string `json:"stock_id,omitempty"` 195 ProductCouponId *string `json:"product_coupon_id,omitempty"` 196 RecommendWord *string `json:"recommend_word,omitempty"` 197 BrandId *int64 `json:"brand_id,omitempty"` 198 TotalCount *int64 `json:"total_count,omitempty"` 199 UserLimit *int64 `json:"user_limit,omitempty"` 200 DailyLimit *int64 `json:"daily_limit,omitempty"` 201} 202
应答参数
200 OK
total_count 选填 integer
【资源总条数】 返回资源总条数
plan_list 选填 array[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 "total_count" : 1234, 3 "plan_list" : [ 4 { 5 "plan_id" : "12000", 6 "plan_name" : "冬季优惠投放", 7 "plan_state" : "PLAN_CREATED", 8 "delivery_start_time" : "2025-01-01T00:00:00+08:00", 9 "delivery_end_time" : "2025-01-01T00:00:00+08:00", 10 "stock_id" : "123456789", 11 "product_coupon_id" : "1000000013", 12 "recommend_word" : "天天有惊喜", 13 "brand_id" : 40016, 14 "total_count" : 11000, 15 "user_limit" : 5, 16 "daily_limit" : 100 17 } 18 ] 19} 20
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示