目前阿里云官方提供的 SDK 分4种语言版本,分别为 Java、Python、PHP、C#,具体链接如下:
更多语言版本的 SDK,您可以前往
第三方 SDK 服务中进行选择。
相关信息:
关于AccessKey的获取
SDK安装
通过maven进行安装添加maven库
- [backcolor=transparent]<repositories>
- [backcolor=transparent] [backcolor=transparent]<repository>
- [backcolor=transparent] [backcolor=transparent]<id>[backcolor=transparent]sonatype-nexus-staging[backcolor=transparent]</id>
- [backcolor=transparent] [backcolor=transparent]<name>[backcolor=transparent]Sonatype Nexus Staging[backcolor=transparent]</name>
- [backcolor=transparent] [backcolor=transparent]<url>[backcolor=transparent]https://oss.sonatype.org/service/local/staging/deploy/maven2/[backcolor=transparent]</url>
- [backcolor=transparent] [backcolor=transparent]<releases>
- [backcolor=transparent] [backcolor=transparent]<enabled>[backcolor=transparent]true[backcolor=transparent]</enabled>
- [backcolor=transparent] [backcolor=transparent]</releases>
- [backcolor=transparent] [backcolor=transparent]<snapshots>
- [backcolor=transparent] [backcolor=transparent]<enabled>[backcolor=transparent]true[backcolor=transparent]</enabled>
- [backcolor=transparent] [backcolor=transparent]</snapshots>
- [backcolor=transparent] [backcolor=transparent]</repository>
- [backcolor=transparent]</repositories>
添加jar包依赖
- [backcolor=transparent]<dependency>
- [backcolor=transparent] [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun[backcolor=transparent]</groupId>
- [backcolor=transparent] [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-java-sdk-alidns[backcolor=transparent]</artifactId>
- [backcolor=transparent] [backcolor=transparent]<version>[backcolor=transparent]2.0.1[backcolor=transparent]</version>
- [backcolor=transparent]</dependency>
- [backcolor=transparent]<dependency>
- [backcolor=transparent] [backcolor=transparent]<groupId>[backcolor=transparent]com.aliyun[backcolor=transparent]</groupId>
- [backcolor=transparent] [backcolor=transparent]<artifactId>[backcolor=transparent]aliyun-java-sdk-core[backcolor=transparent]</artifactId>
- [backcolor=transparent] [backcolor=transparent]<version>[backcolor=transparent]2.3.8[backcolor=transparent]</version>
- [backcolor=transparent]</dependency>
示例代码
- [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]class[backcolor=transparent] [backcolor=transparent]DemoListDomains[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]private[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]IAcsClient[backcolor=transparent] client [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]null[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] regionId [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]"cn-hangzhou"[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]//必填固定值,必须为“cn-hanghou”
- [backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] accessKeyId [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]""[backcolor=transparent];[backcolor=transparent] [backcolor=transparent]// your accessKey
- [backcolor=transparent] [backcolor=transparent]String[backcolor=transparent] accessKeySecret [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]""[backcolor=transparent];[backcolor=transparent]// your accessSecret
- [backcolor=transparent] [backcolor=transparent]IClientProfile[backcolor=transparent] profile [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]DefaultProfile[backcolor=transparent].[backcolor=transparent]getProfile[backcolor=transparent]([backcolor=transparent]regionId[backcolor=transparent],[backcolor=transparent] accessKeyId[backcolor=transparent],[backcolor=transparent] accessKeySecret[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]// 若报Can not find endpoint to access异常,请添加以下此行代码
- [backcolor=transparent] [backcolor=transparent]// DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", "Alidns", "alidns.aliyuncs.com");
- [backcolor=transparent] client [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DefaultAcsClient[backcolor=transparent]([backcolor=transparent]profile[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]public[backcolor=transparent] [backcolor=transparent]static[backcolor=transparent] [backcolor=transparent]void[backcolor=transparent] main[backcolor=transparent]([backcolor=transparent]String[backcolor=transparent][][backcolor=transparent] args[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]DescribeDomainsRequest[backcolor=transparent] request [backcolor=transparent]=[backcolor=transparent] [backcolor=transparent]new[backcolor=transparent] [backcolor=transparent]DescribeDomainsRequest[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]DescribeDomainsResponse[backcolor=transparent] response[backcolor=transparent];
- [backcolor=transparent] [backcolor=transparent]// describeRegionsRequest.setProtocol(ProtocolType.HTTPS); //指定访问协议
- [backcolor=transparent] [backcolor=transparent]// describeRegionsRequest.setAcceptFormat(FormatType.JSON); //指定api返回格式
- [backcolor=transparent] [backcolor=transparent]// describeRegionsRequest.setMethod(MethodType.POST); //指定请求方法
- [backcolor=transparent] [backcolor=transparent]// describeRegionsRequest.setRegionId("cn-hangzhou");//指定要访问的Region,仅对当前请求生效,不改变client的默认设置。
- [backcolor=transparent] [backcolor=transparent]try[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] response [backcolor=transparent]=[backcolor=transparent] client[backcolor=transparent].[backcolor=transparent]getAcsResponse[backcolor=transparent]([backcolor=transparent]request[backcolor=transparent]);
- [backcolor=transparent] [backcolor=transparent]List[backcolor=transparent]<[backcolor=transparent]Domain[backcolor=transparent]>[backcolor=transparent] list [backcolor=transparent]=[backcolor=transparent] response[backcolor=transparent].[backcolor=transparent]getDomains[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]for[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]Domain[backcolor=transparent] domain [backcolor=transparent]:[backcolor=transparent] list[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] [backcolor=transparent]System[backcolor=transparent].[backcolor=transparent]out[backcolor=transparent].[backcolor=transparent]println[backcolor=transparent]([backcolor=transparent]domain[backcolor=transparent].[backcolor=transparent]getDomainName[backcolor=transparent]());
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ServerException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]}[backcolor=transparent] [backcolor=transparent]catch[backcolor=transparent] [backcolor=transparent]([backcolor=transparent]ClientException[backcolor=transparent] e[backcolor=transparent])[backcolor=transparent] [backcolor=transparent]{
- [backcolor=transparent] e[backcolor=transparent].[backcolor=transparent]printStackTrace[backcolor=transparent]();
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent] [backcolor=transparent]}
- [backcolor=transparent]}