云防火墙售卖功能API最佳实践
云防火墙服务不提供管理(包含查询、创建、变更、续费)实例的接口。您可以通过调用阿里云交易和账单管理API提供的接口来管理云防火墙实例。文本介绍调用API管理云防火墙实例的请求方法和示例。
背景信息
阿里云交易和账单管理API是一套通用的管理阿里云资源的接口,可以用于查询服务价格、管理实例、获取账单信息等。关于阿里云交易和账单管理API支持的所有接口,请参见API概览。
您可以调用阿里云交易和账单管理API提供的接口,查询、创建、变更、续费云防火墙实例。关于该接口的调用方式,请参见请求结构。
查询实例
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 |
类型 |
必填 |
示例值 |
描述 |
Region |
String |
否 |
cn-hangzhou |
地域。 |
PageNum |
Integer |
否 |
1 |
页码。 |
PageSize |
Integer |
否 |
20 |
每页条数。 |
ProductCode |
String |
是 |
vipcloudfw |
产品代码。可通过接口QueryProductList - 查询产品信息查询产品代码,或查看阿里云产品Code速查手册。云防火墙的产品代码。取值:
|
ProductType |
String |
否 |
vipcloudfw |
产品类型。 |
SubscriptionType |
String |
否 |
Subscription |
付费类型。取值:
|
InstanceIDs |
String |
否 |
vipcloudfw-cn-pe3xxxxxx |
实例ID。多个ID用英文逗号分隔,最大不超过100个。 |
EndTimeStart |
String |
否 |
2016-05-23T12:00:00Z |
结束时间段起。符合ISO8601标准的utc时间格式。 |
EndTimeEnd |
String |
否 |
2016-05-23T12:00:00Z |
结束时间段止。符合ISO8601标准的utc时间格式。 |
CreateTimeStart |
String |
否 |
2016-05-23T12:00:00Z |
创建时间段起。符合ISO8601标准的utc时间格式。 |
CreateTimeEnd |
String |
否 |
2016-05-23T12:00:00Z |
创建时间段止。符合ISO8601标准的utc时间格式。 |
RenewStatus |
String |
否 |
AutoRenewal |
续费状态。取值:
|
响应参数
名称 |
类型 |
示例值 |
描述 |
Code |
String |
Success |
状态码。 |
Message |
String |
Successful! |
错误信息。 |
RequestId |
String |
C7C15585-8349-4C62-BEE4-5A391841XXXX |
请求ID。 |
Success |
Boolean |
TRUE |
是否成功。 |
Data |
Object |
返回数据。关于Data的详细信息,请参见Data。 |
Data
名称 |
类型 |
示例值 |
描述 |
PageNum |
Integer |
1 |
页码。 |
PageSize |
Integer |
10 |
每页条数。 |
TotalCount |
Integer |
11 |
总记录数。 |
InstanceList |
Object |
实例信息的列表。关于InstanceList的详细介绍,请参见InstanceList。 |
InstanceList
名称 |
类型 |
示例值 |
描述 |
SubStatus |
String |
Normal |
续费的子状态。取值:
|
Status |
String |
Normal |
购买的云防火墙状态。取值:
|
ExpectedReleaseTime |
String |
2019-09-08T16:00:00Z |
期望释放时间。 |
RenewStatus |
String |
ManualRenewal |
续费状态。取值:
|
CreateTime |
String |
2019-09-08T16:00:00Z |
创建时间。 |
SellerId |
Long |
123123123 |
卖方ID。 |
InstanceID |
String |
vipcloudfw-cn-pe333nx**** |
订单对应的实例ID。 |
Seller |
String |
2**** |
卖方。 |
StopTime |
String |
2019-09-08T16:00:00Z |
停止时间。 |
RenewalDurationUnit |
String |
M |
自动续费周期单位。取值:
|
SubscriptionType |
String |
Subscription |
订阅类型。取值:
|
OwnerId |
Long |
325352345 |
所有者ID。 |
EndTime |
String |
2019-09-08T16:00:00Z |
结束时间。 |
ProductType |
String |
vipcloudfw |
产品类型。 |
Region |
String |
cn-hangzhou |
地域。 |
ReleaseTime |
String |
2019-09-08T16:00:00Z |
释放时间。 |
RenewalDuration |
Integer |
1 |
自动续费周期数量。 |
ProductCode |
String |
vipcloudfw |
产品代码。 |
示例
请求示例
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.bssopenapi.model.v20171214.*;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
*/
public class QueryAvailableInstances {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your-access-key-id>", "<your-access-key-secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID.
"<your-access-key-id>", // The AccessKey ID of the RAM account.
"<your-access-key-secret>", // The AccessKey Secret of the RAM account
"<your-sts-token>"); // STS Token.
**/
IAcsClient client = new DefaultAcsClient(profile);
QueryAvailableInstancesRequest request = new QueryAvailableInstancesRequest();
request.setProductCode("vipcloudfw");
try {
QueryAvailableInstancesResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
正常返回示例
{
"RequestId": "FDE58AA9-37C8-5001-948B-82DE61353864",
"Message": "Successful!",
"Data": {
"TotalCount": 1,
"PageNum": 1,
"PageSize": 20,
"InstanceList": [
{
"Status": "Normal",
"SubscriptionType": "Subscription",
"OwnerId": 19xxxxxxxxx6359163,
"EndTime": "2023-06-21T16:00:00Z",
"ProductCode": "vipcloudfw",
"InstanceID": "vipcloudfw-cn-pe333nx****",
"CreateTime": "2021-12-21T05:17:32Z",
"ProductType": "vipcloudfw",
"RenewalDurationUnit": "M",
"Seller": "2****",
"SubStatus": "Normal",
"RenewStatus": "ManualRenewal"
}
]
},
"Code": "Success",
"Success": true
}
创建实例
调用CreateInstance创建一个实例资源,调用接口会自动创建一个新购实例资源的订单,并自动支付。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 |
类型 |
是否必选 |
示例值 |
描述 |
Action |
String |
是 |
CreateInstance |
系统规定参数。取值:CreateInstance。 |
Parameter.N.Code |
String |
是 |
|
第n个模块属性code配置,n的取值范围为(1~100),如有多个模块属性参数,按照n=1,2,3…n的形式拼接多个参数。具体信息,请参见Parameter。 |
Parameter.N.Value |
String |
是 |
|
第n个模块属性value配置,n的取值范围为(1~100)。具体信息,请参见Parameter。 |
ProductCode |
String |
是 |
vipcloudfw |
产品代码。可通过接口QueryProductList - 查询产品信息查询产品代码,或查看阿里云产品Code速查手册。 云防火墙的产品代码,取值:
|
SubscriptionType |
String |
是 |
Subscription |
付费类型。取值:
|
RenewPeriod |
Integer |
否 |
12 |
自动续费周期。单位为月。
说明
当设置RenewalStatus为AutoRenewal时,必须设置。 |
Period |
Integer |
否 |
1 |
预付费周期。单位为月,按年付费产品请输入12的整数倍。
说明
当创建预付费实例时,必须设置。 |
RenewalStatus |
String |
否 |
ManualRenewal |
自动续费状态。取值:
|
Parameter
Parameter.N.Code |
类型 |
是否必选 |
示例值 |
描述 |
CfwAccount |
String |
是 |
true |
多账户统一管理。取值:
|
VpcBandwidth |
Integer |
是 |
1000 |
VPC流量处理能力。单位:Mbps。各版本支持情况和取值范围:
|
AclExtension |
Integer |
是 |
1000 |
访问控制全局扩展。各版本取值范围:
|
AccountNum |
Integer |
是 |
1 |
多账号管控数。各版本取值范围:
|
VpcExtension |
Integer |
是 |
10 |
可防护VPC数。各版本支持情况和取值范围:
|
IpExtension |
Integer |
是 |
100 |
可防护公网IP数。各版本取值范围:
|
CfwLogStorage |
Integer |
是 |
10000 |
日志存储容量。单位:GB。各版本取值范围:
|
CfwLog |
String |
是 |
true |
日志分析。取值:
|
BandWidth |
Integer |
200 |
公网流量处理能力。单位:Mbps。各版本取值范围:
|
|
Spec |
String |
2 |
当前云防火墙版本。取值:
|
返回参数
名称 |
类型 |
示例值 |
描述 |
Code |
String |
Success |
状态码。 |
InstanceId |
String |
vipcloudfw-cn-pe333nx**** |
订单对应的实例ID。 |
OrderId |
String |
22165938636**** |
创建成功的订单ID。 |
Message |
String |
Successful! |
错误信息。 |
RequestId |
String |
13B1DCF7-0B7C-5426-BC08-869887FCCCEC |
请求ID。 |
Success |
Boolean |
true |
是否成功。 |
示例
下面代码创建了预付费中国站云防火墙,使用手动续费,且预付费用1个月。
请求示例
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
*/
public class CreateInstance {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your-access-key-id>", "<your-access-key-secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID.
"<your-access-key-id>", // The AccessKey ID of the RAM account.
"<your-access-key-secret>", // The AccessKey Secret of the RAM account.
"<your-sts-token>"); // STS Token.
**/
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("business.aliyuncs.com");
request.setSysVersion("2017-12-14");
request.setSysAction("CreateInstance");
request.putQueryParameter("RenewalStatus", "ManualRenewal");
request.putQueryParameter("ProductCode", "vipcloudfw");
request.putQueryParameter("Parameter.1.Code", "CfwAccount");
request.putQueryParameter("Parameter.1.Value", "true");
request.putQueryParameter("Parameter.2.Code", "CfwAccount");
request.putQueryParameter("Parameter.2.Value", "true");
request.putQueryParameter("Parameter.3.Code", "VpcBandwidth");
request.putQueryParameter("Parameter.3.Value", "1000");//VPC流量处理能力为1000 Mbps。
request.putQueryParameter("Parameter.4.Code", "AclExtension");
request.putQueryParameter("Parameter.4.Value", "1000");//访问控制全局扩展为1000条。
request.putQueryParameter("Parameter.5.Code", "AccountNum");
request.putQueryParameter("Parameter.5.Value", "1");//多账号管控数为1。
request.putQueryParameter("Parameter.6.Code", "VpcExtension");
request.putQueryParameter("Parameter.6.Value", "10");//可防护的VPC数为10个。
request.putQueryParameter("Parameter.7.Code", "IpExtension");
request.putQueryParameter("Parameter.7.Value", "400");//可防护公网IP数为400。
request.putQueryParameter("Parameter.8.Code", "CfwLogStorage");
request.putQueryParameter("Parameter.8.Value", "10000");//日志存储容量为10000 GB。
request.putQueryParameter("Parameter.9.Code", "CfwLog");
request.putQueryParameter("Parameter.9.Value", "true");//开通日志分析功能。
request.putQueryParameter("Parameter.10.Code", "BandWidth");
request.putQueryParameter("Parameter.10.Value", "200");//公网流量处理能力为200 Mbps。
request.putQueryParameter("Parameter.11.Code", "Spec");
request.putQueryParameter("Parameter.11.Value", "4");//旗舰版。
request.putQueryParameter("SubscriptionType", "Subscription");//预付费类型。
request.putQueryParameter("Period", "1");//1个月。
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}
正常返回示例
云防火墙创建成功会返回实例ID(InstanceId),实例ID在后续变配和续费中将用到。
{
"RequestId": "13B1DCF7-0B7C-5426-BC08-869887FCCCEC",
"Message": "Successful!",
"Data": {
"InstanceId": "vipcloudfw-cn-pe333nx****",
"OrderId": 22165938636****
},
"Code": "Success",
"Success": true
}
变更实例
调用ModifyInstance对实例资源配置进行变更。调用接口会创建一个变配实例资源的订单,并自动支付。
降低配置后,已经开始的收费周期内不支持退费,会从下一个收费周期开始按照降配后的最新规格计费。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 |
类型 |
是否必选 |
示例值 |
描述 |
Action |
String |
是 |
ModifyInstance |
系统规定参数。取值:ModifyInstance。 |
Parameter.N.Code |
String |
是 |
|
第n个模块属性code配置,n的取值范围为(1~100),如有多个模块属性参数,按照n=1,2,3…n的形式拼接多个参数。具体信息,请参见Parameter。 |
Parameter.N.Value |
String |
是 |
|
第n个模块属性value配置,n的取值范围为(1~100)。具体信息,请参见Parameter。 |
ProductCode |
String |
是 |
vipcloudfw |
产品代码。可通过接口QueryProductList - 查询产品信息查询产品代码,或查看阿里云产品Code速查手册。 云防火墙的产品代码。取值:
|
SubscriptionType |
String |
是 |
Subscription |
付费类型。取值:
|
ModifyType |
Upgrade |
变配类型。取值:
|
||
InstanceId |
String |
否 |
vipcloudfw-cn-pe333nx**** |
订单对应的实例ID。 |
Parameter
Parameter.N.Code |
类型 |
是否必选 |
示例值 |
描述 |
CfwAccount |
String |
是 |
true |
多账户统一管理。取值:
|
VpcBandwidth |
Integer |
是 |
1000 |
VPC流量处理能力。单位:Mbps。各版本支持情况和取值范围:
|
AclExtension |
Integer |
是 |
1000 |
访问控制全局扩展。各版本取值范围:
|
AccountNum |
Integer |
是 |
1 |
多账号管控数。各版本取值范围:
|
VpcExtension |
Integer |
是 |
10 |
可防护VPC数。各版本支持情况和取值范围:
|
IpExtension |
Integer |
是 |
100 |
可防护公网IP数。各版本取值范围:
|
CfwLogStorage |
Integer |
是 |
10000 |
日志存储容量。单位:GB。各版本取值范围:
|
CfwLog |
String |
是 |
true |
日志分析。取值:
|
BandWidth |
Integer |
200 |
公网流量处理能力。单位:Mbps。各版本取值范围:
|
|
Spec |
String |
2 |
当前云防火墙版本。取值:
|
响应参数
名称 |
类型 |
示例值 |
描述 |
Code |
String |
Success |
状态码。 |
HostId |
String |
cn**** |
主机ID。 |
OrderId |
String |
22165938810**** |
创建成功的订单ID。 |
Message |
String |
Successful! |
错误信息。 |
RequestId |
String |
3EC4C157-46E3-5341-82B0-8CEEC7637F93 |
请求ID。 |
Success |
Boolean |
true |
是否成功。 |
示例
下面代码为您实现将公网流量处理能力从200 Mbps升级到500 Mbps。
请求示例
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
*/
public class ModifyInstance {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your-access-key-id>", "<your-access-key-secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID
"<your-access-key-id>", // The AccessKey ID of the RAM account
"<your-access-key-secret>", // The AccessKey Secret of the RAM account
"<your-sts-token>"); // STS Token
**/
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("business.aliyuncs.com");
request.setSysVersion("2017-12-14");
request.setSysAction("ModifyInstance");
request.putQueryParameter("ProductCode", "vipcloudfw");
request.putQueryParameter("SubscriptionType", "Subscription");
request.putQueryParameter("ModifyType", "Upgrade");
request.putQueryParameter("InstanceId", "vipcloudfw-cn-pe333nx****");
request.putQueryParameter("Parameter.1.Code", "BandWidth");
request.putQueryParameter("Parameter.1.Value", "500");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}
正常返回示例
{
"Message": "Successful!",
"RequestId": "3EC4C157-46E3-5341-82B0-8CEEC7637F93",
"Data": {
"OrderId": 22165938810****,
"HostId": "cn****"
},
"Code": "Success",
"Success": true
}
实例续费
调用RenewInstance对相关实例进行续费。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 |
类型 |
是否必选 |
示例值 |
描述 |
Action |
String |
是 |
RenewInstance |
系统规定参数。取值:RenewInstance。 |
ProductCode |
String |
是 |
vipcloudfw |
产品代码。可通过接口QueryProductList - 查询产品信息查询产品代码,或查看阿里云产品Code速查手册。 云防火墙的产品代码。取值:
|
RenewPeriod |
Integer |
是 |
6 |
预付费续费时长。单位:月。取值:
|
InstanceId |
String |
否 |
vipcloudfw-cn-pe333nx**** |
订单对应的实例ID。 |
响应参数
错误码 |
类型 |
示例值 |
描述 |
Code |
String |
Success |
状态码。 |
OrderId |
String |
22165938810**** |
创建成功的订单ID。 |
Message |
String |
Successful! |
错误信息。 |
RequestId |
String |
E15FB71F-7FF8-5272-80B1-B4E73BE4CB99 |
请求ID。 |
Success |
Boolean |
true |
是否成功。 |
示例
以下是实现续费6个月的代码示例。
请求示例
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.bssopenapi.model.v20171214.*;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.0</version>
</dependency>
*/
public class RenewInstance {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<your-access-key-id>", "<your-access-key-secret>");
/** use STS Token
DefaultProfile profile = DefaultProfile.getProfile(
"<your-region-id>", // The region ID.
"<your-access-key-id>", // The AccessKey ID of the RAM account.
"<your-access-key-secret>", // The AccessKey Secret of the RAM account.
"<your-sts-token>"); // STS Token.
**/
IAcsClient client = new DefaultAcsClient(profile);
RenewInstanceRequest request = new RenewInstanceRequest();
request.setProductCode("vipcloudfw");
request.setInstanceId("vipcloudfw-cn-pe333nx****");
request.setRenewPeriod(6);
try {
RenewInstanceResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
正常返回示例
{
"Message": "Successful!",
"RequestId": "E15FB71F-7FF8-5272-80B1-B4E73BE4CB99",
"Data": {
"OrderId": 22167752456****
},
"Code": "Success",
"Success": true
}