您可以基于阿里云 SDK 通过编写代码的方式调用阿里云 API,进而实现对阿里云产品和服务的灵活部署和快速操作。

说明
使用过程中您会需要 AccessKey。您可以在 云账号 AccessKey 管理页面 创建并管理 AccessKey。

环境准备

通过以下地址查询下载最新版本 SDK:https://oss.sonatype.org/#nexus-search;gav~com.aliyun~aliyun-java-sdk-*~~~

从 Github 上下载源代码:https://github.com/aliyun/aliyun-openapi-java-sdk/

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>
    <dependencies>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-cs</artifactId>
            <version>2.0.2</version>
        </dependency>
    </dependencies>

Sample

public static void main(String[] argc) throws Exception {
        String accessKeyID = "xx";
        String accessKeySecret = "xx";
        String region="cn-shenzhen"; // or other
        DescribeApiVersionRequest describeApiVersionRequest = new DescribeApiVersionRequest();
        IClientProfile profile = DefaultProfile.getProfile(region, accessKeyID, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);
        try {
            HttpResponse httpResponse
                    = client.doAction(describeApiVersionRequest);
            System.out.println(httpResponse.getUrl());
            System.out.println(new String(httpResponse.getContent()));
        } catch (ClientException e) {
            e.printStackTrace();
        }
}