全部产品
云市场

SDK参考

更新时间:2018-06-11 10:43:48

目前阿里云官方提供的 SDK 分4种语言版本,分别为 Java、Python、go,具体链接如下:

更多语言版本的 SDK,您可以前往第三方 SDK 服务中进行选择。

相关信息:关于AccessKey的获取

SDK安装

通过maven进行安装添加maven库

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>3.6.0</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>com.aliyun</groupId>
  8. <artifactId>aliyun-java-sdk-pvtz</artifactId>
  9. <version>1.0.0</version>
  10. </dependency>
  11. <!-- format output -->
  12. <dependency>
  13. <groupId>com.alibaba</groupId>
  14. <artifactId>fastjson</artifactId>
  15. <version>1.2.48</version>
  16. </dependency>

示例代码

  1. package com.aliyun.pvtz.demo;
  2. import com.alibaba.fastjson.JSON;
  3. import com.aliyuncs.DefaultAcsClient;
  4. import com.aliyuncs.IAcsClient;
  5. import com.aliyuncs.exceptions.ClientException;
  6. import com.aliyuncs.profile.DefaultProfile;
  7. import com.aliyuncs.pvtz.model.v20180101.*;
  8. public class PopApiDemo {
  9. public static void main(String[] args) throws ClientException {
  10. // Create and initialize a DefaultAcsClient instance
  11. DefaultProfile profile = DefaultProfile.getProfile(
  12. "cn-hangzhou", // RegionId, use "cn-hangzhou"
  13. "***********", // The AccessKey ID of the RAM account
  14. "**********"); // The AccessKey Secret of the RAM account
  15. IAcsClient client = new DefaultAcsClient(profile);
  16. // list private zone list
  17. DescribeZonesRequest pvtzZoneListRequest = new DescribeZonesRequest();
  18. pvtzZoneListRequest.setPageSize(10);
  19. DescribeZonesResponse pvtzZoneListResponse = client.getAcsResponse(pvtzZoneListRequest);
  20. System.out.println(JSON.toJSONString(pvtzZoneListResponse));
  21. // add record to zone. (zoneid: 31c43e48a9864bc6f7ed8e72100a22f1)
  22. AddZoneRecordRequest pvtzRecordAddRequest = new AddZoneRecordRequest();
  23. pvtzRecordAddRequest.setZoneId("31c43e48a9864bc6f7ed8e72100a22f1");
  24. pvtzRecordAddRequest.setRr("www");
  25. pvtzRecordAddRequest.setTtl(60);
  26. pvtzRecordAddRequest.setType("A");
  27. pvtzRecordAddRequest.setValue("10.1.1.1");
  28. AddZoneRecordResponse pvtzRecordAddResponse = client.getAcsResponse(pvtzRecordAddRequest);
  29. System.out.println(JSON.toJSONString(pvtzRecordAddResponse));
  30. // list record
  31. DescribeZoneRecordsRequest pvtzRecordListRequest = new DescribeZoneRecordsRequest();
  32. pvtzRecordListRequest.setZoneId("31c43e48a9864bc6f7ed8e72100a22f1");
  33. DescribeZoneRecordsResponse pvtzRecordListResponse = client.getAcsResponse(pvtzRecordListRequest);
  34. System.out.println(JSON.toJSONString(pvtzRecordListResponse));
  35. // pause record
  36. SetZoneRecordStatusRequest pvtzRecordPauseRequest = new SetZoneRecordStatusRequest();
  37. pvtzRecordPauseRequest.setRecordId(15035L);
  38. pvtzRecordPauseRequest.setStatus("DISABLE");
  39. SetZoneRecordStatusResponse pvtzRecordPauseResponse = client.getAcsResponse(pvtzRecordPauseRequest);
  40. System.out.println(JSON.toJSONString(pvtzRecordPauseResponse));
  41. // delete record
  42. DeleteZoneRecordRequest pvtzRecordDeleteRequest = new DeleteZoneRecordRequest();
  43. pvtzRecordDeleteRequest.setRecordId(15035L);
  44. DeleteZoneRecordResponse pvtzRecordDeleteResponse = client.getAcsResponse(pvtzRecordDeleteRequest);
  45. System.out.println(JSON.toJSONString(pvtzRecordDeleteResponse));
  46. }
  47. }