SDK安装 通过maven进行安装添加maven库
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-pvtz</artifactId>
<version>1.0.0</version>
</dependency>
<!-- format output -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.48</version>
</dependency>
示例代码
package com.aliyun.pvtz.demo;
import com.alibaba.fastjson.JSON; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.pvtz.model.v20180101.*;
public class PopApiDemo {
public static void main(String[] args) throws ClientException {
// Create and initialize a DefaultAcsClient instance
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou", // RegionId, use "cn-hangzhou"
"***********", // The AccessKey ID of the RAM account
"**********"); // The AccessKey Secret of the RAM account
IAcsClient client = new DefaultAcsClient(profile);
// list private zone list
DescribeZonesRequest pvtzZoneListRequest = new DescribeZonesRequest();
pvtzZoneListRequest.setPageSize(10);
DescribeZonesResponse pvtzZoneListResponse = client.getAcsResponse(pvtzZoneListRequest);
System.out.println(JSON.toJSONString(pvtzZoneListResponse));
// add record to zone. (zoneid: 31c43e48a9864bc6f7ed8e72100a22f1)
AddZoneRecordRequest pvtzRecordAddRequest = new AddZoneRecordRequest();
pvtzRecordAddRequest.setZoneId("31c43e48a9864bc6f7ed8e72100a22f1");
pvtzRecordAddRequest.setRr("www");
pvtzRecordAddRequest.setTtl(60);
pvtzRecordAddRequest.setType("A");
pvtzRecordAddRequest.setValue("10.1.1.1");
AddZoneRecordResponse pvtzRecordAddResponse = client.getAcsResponse(pvtzRecordAddRequest);
System.out.println(JSON.toJSONString(pvtzRecordAddResponse));
// list record
DescribeZoneRecordsRequest pvtzRecordListRequest = new DescribeZoneRecordsRequest();
pvtzRecordListRequest.setZoneId("31c43e48a9864bc6f7ed8e72100a22f1");
DescribeZoneRecordsResponse pvtzRecordListResponse = client.getAcsResponse(pvtzRecordListRequest);
System.out.println(JSON.toJSONString(pvtzRecordListResponse));
// pause record
SetZoneRecordStatusRequest pvtzRecordPauseRequest = new SetZoneRecordStatusRequest();
pvtzRecordPauseRequest.setRecordId(15035L);
pvtzRecordPauseRequest.setStatus("DISABLE");
SetZoneRecordStatusResponse pvtzRecordPauseResponse = client.getAcsResponse(pvtzRecordPauseRequest);
System.out.println(JSON.toJSONString(pvtzRecordPauseResponse));
// delete record
DeleteZoneRecordRequest pvtzRecordDeleteRequest = new DeleteZoneRecordRequest();
pvtzRecordDeleteRequest.setRecordId(15035L);
DeleteZoneRecordResponse pvtzRecordDeleteResponse = client.getAcsResponse(pvtzRecordDeleteRequest);
System.out.println(JSON.toJSONString(pvtzRecordDeleteResponse));
}
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。