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

更多语言版本的SDK,您可以前往阿里云 SDK 服务中进行选择。

相关信息:关于AccessKey的获取

SDK安装

您可以通过添加maven库或者jar包依赖安装SDK,本文以Java语言为示例。

  • 添加maven库
    <repositories>
            <repository>
                <id>sonatype-nexus-staging</id>
                <name>Sonatype Nexus Staging</name>
                <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
    </repositories> 
  • 添加jar包依赖
    <dependency>
          <groupId>com.aliyun</groupId>
          <artifactId>aliyun-java-sdk-alidns</artifactId>
          <version>2.0.10</version>
    </dependency>
    <dependency>
          <groupId>com.aliyun</groupId>
          <artifactId>aliyun-java-sdk-core</artifactId>
          <version>4.3.2</version>
    </dependency>   

示例代码

public class DemoListDomains {

    private static IAcsClient client = null;

    static {
        String regionId = "cn-hangzhou"; //必填固定值,必须为“cn-hanghou”
        String accessKeyId = ""; // your accessKey
        String accessKeySecret = "";// your accessSecret
        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        // 若报Can not find endpoint to access异常,请添加以下此行代码
        // DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Alidns", "alidns.aliyuncs.com");  
        client = new DefaultAcsClient(profile);
    }

    public static void main(String[] args) {

        DescribeDomainsRequest request = new DescribeDomainsRequest();
        DescribeDomainsResponse response;
        // describeRegionsRequest.setProtocol(ProtocolType.HTTPS); //指定访问协议
        // describeRegionsRequest.setAcceptFormat(FormatType.JSON); //指定api返回格式
        // describeRegionsRequest.setMethod(MethodType.POST); //指定请求方法
        // describeRegionsRequest.setRegionId("cn-hangzhou");//指定要访问的Region,仅对当前请求生效,不改变client的默认设置。
        try {
            response = client.getAcsResponse(request);
            List<Domain> list = response.getDomains();
            for (Domain domain : list) {
                System.out.println(domain.getDomainName());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}