提交投放计划
更新时间:2026.03.16若创建投放计划仅保存草稿,即「创建投放计划API」中save_as_draft填入值为“true”, 则可通过本接口完成投放计划草稿的提神提审操作, 提交后, 投放计划进入审核中状态, 若审核通过, 则草稿数据会成为线上正式数据。
接口说明
支持商户:【品牌商户】
请求方式:【POST】/brand/marketing/delivery-plan/delivery-plans/{plan_id}/submit
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
接口限频:50/秒(品牌ID维度)
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
Wechatpay-Serial 必填 string
【微信支付公钥ID】 请传入brand_id对应的微信支付公钥ID,接口将会校验两者的关联关系,参考微信支付公钥产品简介及使用说明获取微信支付公钥ID和相关的介绍。以下两种场景将使用到微信支付公钥: 1、接收到接口的返回内容,需要使用微信支付公钥进行验签; 2、调用含有敏感信息参数(如姓名、身份证号码)的接口时,需要使用微信支付公钥加密敏感信息后再传输参数,加密指引请参考微信支付公钥加密敏感信息指引。
path 路径参数
plan_id 必填 string
【投放计划ID】 投放计划ID
请求示例
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/brand/marketing/delivery-plan/delivery-plans/12000/submit \ 3 -H "Authorization: WECHATPAY-BRAND-SHA256-RSA2048 brand_id=\"XXXX\",..." \ 4 -H "Accept: application/json" \ 5 -H "Wechatpay-Serial: PUB_KEY_ID_XXXX" 6
需配合微信支付工具库 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 SubmitDeliveryPlan { 26 private static String HOST = "https://api.mch.weixin.qq.com"; 27 private static String METHOD = "POST"; 28 private static String PATH = "/brand/marketing/delivery-plan/delivery-plans/{plan_id}/submit"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/brand/4015415289 32 SubmitDeliveryPlan client = new SubmitDeliveryPlan( 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 SubmitDeliveryPlanRequest request = new SubmitDeliveryPlanRequest(); 41 request.planId = "12000"; 42 try { 43 client.run(request); 44 } catch (WXPayBrandUtility.ApiException e) { 45 // TODO: 请求失败,根据状态码执行不同的逻辑 46 e.printStackTrace(); 47 } 48 } 49 50 public void run(SubmitDeliveryPlanRequest request) { 51 String uri = PATH; 52 uri = uri.replace("{plan_id}", WXPayBrandUtility.urlEncode(request.planId)); 53 54 Request.Builder reqBuilder = new Request.Builder().url(HOST + uri); 55 reqBuilder.addHeader("Accept", "application/json"); 56 reqBuilder.addHeader("Wechatpay-Serial", wechatPayPublicKeyId); 57 reqBuilder.addHeader("Authorization", WXPayBrandUtility.buildAuthorization(brand_id, certificateSerialNo, privateKey, METHOD, uri, null)); 58 reqBuilder.addHeader("Content-Type", "application/json"); 59 RequestBody emptyBody = RequestBody.create(null, ""); 60 reqBuilder.method(METHOD, emptyBody); 61 Request httpRequest = reqBuilder.build(); 62 63 // 发送HTTP请求 64 OkHttpClient client = new OkHttpClient.Builder().build(); 65 try (Response httpResponse = client.newCall(httpRequest).execute()) { 66 String respBody = WXPayBrandUtility.extractBody(httpResponse); 67 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 68 // 2XX 成功,验证应答签名 69 WXPayBrandUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 70 httpResponse.headers(), respBody); 71 72 return; 73 } else { 74 throw new WXPayBrandUtility.ApiException(httpResponse.code(), respBody, httpResponse.headers()); 75 } 76 } catch (IOException e) { 77 throw new UncheckedIOException("Sending request to " + uri + " failed.", e); 78 } 79 } 80 81 private final String brand_id; 82 private final String certificateSerialNo; 83 private final PrivateKey privateKey; 84 private final String wechatPayPublicKeyId; 85 private final PublicKey wechatPayPublicKey; 86 87 public SubmitDeliveryPlan(String brand_id, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 88 this.brand_id = brand_id; 89 this.certificateSerialNo = certificateSerialNo; 90 this.privateKey = WXPayBrandUtility.loadPrivateKeyFromPath(privateKeyFilePath); 91 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 92 this.wechatPayPublicKey = WXPayBrandUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 93 } 94 95 public static class SubmitDeliveryPlanRequest { 96 @SerializedName("plan_id") 97 @Expose(serialize = false) 98 public String planId; 99 } 100 101} 102
需配合微信支付工具库 wxpay_utility 使用,请参考Go
1package main 2 3import ( 4 "demo/wxpay_brand_utility" // 引用微信支付工具库,参考 https://pay.weixin.qq.com/doc/brand/4015826866 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/brand/4015415289 14 config, err := wxpay_brand_utility.CreateBrandConfig( 15 "xxxxxxxx", // 品牌ID,是由微信支付系统生成并分配给每个品牌方的唯一标识符,品牌ID获取方式参考 https://pay.weixin.qq.com/doc/brand/4015415289 16 "1DDE55AD98Exxxxxxxxxx", // 品牌API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015407570 17 "/path/to/apiclient_key.pem", // 品牌API证书私钥文件路径,本地文件路径 18 "PUB_KEY_ID_xxxxxxxxxxxxx", // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/brand/4015453439 19 "/path/to/wxp_pub.pem", // 微信支付公钥文件路径,本地文件路径 20 ) 21 if err != nil { 22 fmt.Println(err) 23 return 24 } 25 26 request := &SubmitDeliveryPlanRequest{ 27 PlanId: wxpay_brand_utility.String("12000"), 28 } 29 30 err = SubmitDeliveryPlan(config, request) 31 if err != nil { 32 fmt.Printf("请求失败: %+v\n", err) 33 // TODO: 请求失败,根据状态码执行不同的处理 34 return 35 } 36 37 // TODO: 请求成功,继续业务逻辑 38 fmt.Println("请求成功") 39} 40 41func SubmitDeliveryPlan(config *wxpay_brand_utility.BrandConfig, request *SubmitDeliveryPlanRequest) (err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "POST" 45 path = "/brand/marketing/delivery-plan/delivery-plans/{plan_id}/submit" 46 ) 47 48 reqUrl, err := url.Parse(fmt.Sprintf("%s%s", host, path)) 49 if err != nil { 50 return err 51 } 52 reqUrl.Path = strings.Replace(reqUrl.Path, "{plan_id}", url.PathEscape(*request.PlanId), -1) 53 httpRequest, err := http.NewRequest(method, reqUrl.String(), nil) 54 if err != nil { 55 return err 56 } 57 httpRequest.Header.Set("Accept", "application/json") 58 httpRequest.Header.Set("Wechatpay-Serial", config.WechatPayPublicKeyId()) 59 httpRequest.Header.Set("Content-Type", "application/json") 60 authorization, err := wxpay_brand_utility.BuildAuthorization(config.BrandId(), config.CertificateSerialNo(), config.PrivateKey(), method, reqUrl.RequestURI(), nil) 61 if err != nil { 62 return err 63 } 64 httpRequest.Header.Set("Authorization", authorization) 65 66 client := &http.Client{} 67 httpResponse, err := client.Do(httpRequest) 68 if err != nil { 69 return err 70 } 71 respBody, err := wxpay_brand_utility.ExtractResponseBody(httpResponse) 72 if err != nil { 73 return err 74 } 75 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 76 // 2XX 成功,验证应答签名 77 err = wxpay_brand_utility.ValidateResponse( 78 config.WechatPayPublicKeyId(), 79 config.WechatPayPublicKey(), 80 &httpResponse.Header, 81 respBody, 82 ) 83 if err != nil { 84 return err 85 } 86 return nil 87 } else { 88 return wxpay_brand_utility.NewApiException( 89 httpResponse.StatusCode, 90 httpResponse.Header, 91 respBody, 92 ) 93 } 94} 95 96type SubmitDeliveryPlanRequest struct { 97 PlanId *string `json:"plan_id,omitempty"` 98} 99 100func (o *SubmitDeliveryPlanRequest) MarshalJSON() ([]byte, error) { 101 type Alias SubmitDeliveryPlanRequest 102 a := &struct { 103 PlanId *string `json:"plan_id,omitempty"` 104 *Alias 105 }{ 106 // 序列化时移除非 Body 字段 107 PlanId: nil, 108 Alias: (*Alias)(o), 109 } 110 return json.Marshal(a) 111} 112
应答参数
无应答包体
应答示例
204 No Content
1'无应答包体' 2
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示

