终止投放计划
更新时间:2025.09.27终止投放计划
接口说明
支持商户:【普通服务商】
请求方式:【POST】/v3/marketing/partner/delivery-plan/delivery-plans/{plan_id}/terminate
请求域名:【主域名】https://api.mch.weixin.qq.com 使用该域名将访问就近的接入点
【备域名】https://api2.mch.weixin.qq.com 使用该域名将访问异地的接入点 ,指引点击查看
请求参数
Header HTTP头参数
Authorization 必填 string
请参考签名认证生成认证信息
Accept 必填 string
请设置为application/json
path 路径参数
plan_id 必填 string
【投放计划ID】 投放计划ID
请求示例
curl
Java
Go
POST
1curl -X POST \ 2 https://api.mch.weixin.qq.com/v3/marketing/partner/delivery-plan/delivery-plans/12000/terminate \ 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 TerminateDeliveryPlan { 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/delivery-plan/delivery-plans/{plan_id}/terminate"; 29 30 public static void main(String[] args) { 31 // TODO: 请准备商户开发必要参数,参考:https://pay.weixin.qq.com/doc/v3/partner/4013080340 32 TerminateDeliveryPlan client = new TerminateDeliveryPlan( 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 TerminateDeliveryPlanRequest request = new TerminateDeliveryPlanRequest(); 41 request.planId = "12000"; 42 try { 43 client.run(request); 44 } catch (WXPayUtility.ApiException e) { 45 // TODO: 请求失败,根据状态码执行不同的逻辑 46 e.printStackTrace(); 47 } 48 } 49 50 public void run(TerminateDeliveryPlanRequest request) { 51 String uri = PATH; 52 uri = uri.replace("{plan_id}", WXPayUtility.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", WXPayUtility.buildAuthorization(mchid, 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 = WXPayUtility.extractBody(httpResponse); 67 if (httpResponse.code() >= 200 && httpResponse.code() < 300) { 68 // 2XX 成功,验证应答签名 69 WXPayUtility.validateResponse(this.wechatPayPublicKeyId, this.wechatPayPublicKey, 70 httpResponse.headers(), respBody); 71 72 return; 73 } else { 74 throw new WXPayUtility.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 mchid; 82 private final String certificateSerialNo; 83 private final PrivateKey privateKey; 84 private final String wechatPayPublicKeyId; 85 private final PublicKey wechatPayPublicKey; 86 87 public TerminateDeliveryPlan(String mchid, String certificateSerialNo, String privateKeyFilePath, String wechatPayPublicKeyId, String wechatPayPublicKeyFilePath) { 88 this.mchid = mchid; 89 this.certificateSerialNo = certificateSerialNo; 90 this.privateKey = WXPayUtility.loadPrivateKeyFromPath(privateKeyFilePath); 91 this.wechatPayPublicKeyId = wechatPayPublicKeyId; 92 this.wechatPayPublicKey = WXPayUtility.loadPublicKeyFromPath(wechatPayPublicKeyFilePath); 93 } 94 95 public static class TerminateDeliveryPlanRequest { 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_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 := &TerminateDeliveryPlanRequest{ 27 PlanId: wxpay_utility.String("12000"), 28 } 29 30 err = TerminateDeliveryPlan(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 TerminateDeliveryPlan(config *wxpay_utility.MchConfig, request *TerminateDeliveryPlanRequest) (err error) { 42 const ( 43 host = "https://api.mch.weixin.qq.com" 44 method = "POST" 45 path = "/v3/marketing/partner/delivery-plan/delivery-plans/{plan_id}/terminate" 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_utility.BuildAuthorization(config.MchId(), 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_utility.ExtractResponseBody(httpResponse) 72 if err != nil { 73 return err 74 } 75 if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { 76 // 2XX 成功,验证应答签名 77 err = wxpay_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_utility.NewApiException( 89 httpResponse.StatusCode, 90 httpResponse.Header, 91 respBody, 92 ) 93 } 94} 95 96type TerminateDeliveryPlanRequest struct { 97 PlanId *string `json:"plan_id,omitempty"` 98} 99 100func (o *TerminateDeliveryPlanRequest) MarshalJSON() ([]byte, error) { 101 type Alias TerminateDeliveryPlanRequest 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
错误码
以下是本接口返回的错误码列表。详细错误码规则,请参考微信支付接口规则-错误码和错误提示
文档是否有帮助