全部产品
Search
文档中心

SDK手册

更新时间: 2018-05-16

目前,阿里云官方提供的 SDK 分4种语言版本,分别为 Java、Python、PHP、C#。每个版本的下载安装和使用方法如下:

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

快速入门

Java

以Java为例,SDK可以通过如下方式安装和使用:

  1. 在阿里云官网创建并管理你的AccessKey。

  2. 通过maven安装SDK。

    1. 使用以下代码添加maven库:
      1. <repositories>
      2. <repository>
      3. <id>sonatype-nexus-staging</id>
      4. name>Sonatype Nexus Staging</name>
      5. <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
      6. <releases>
      7. <enabled>true</enabled>
      8. </releases>
      9. <snapshots>
      10. <enabled>true</enabled>
      11. </snapshots>
      12. </repository>
      13. </repositories>
    2. 使用以下代码添加jar包依赖:
      1. <dependency>
      2. <groupId>com.aliyun</groupId>
      3. <artifactId>aliyun-java-sdk-domain-intl</artifactId>
      4. <version>1.0.0</version>
      5. </dependency>
      6. <dependency>
      7. <groupId>com.aliyun</groupId>
      8. <artifactId>aliyun-java-sdk-core</artifactId>
      9. <version>3.5.0</version>
      10. </dependency>
  3. 示例代码。

    下面以批量提交域名注册任务为示例:

    1. import java.util.ArrayList;
    2. import com.aliyuncs.DefaultAcsClient;
    3. import com.aliyuncs.IAcsClient;
    4. import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateRequest;
    5. import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateRequest.OrderActivateParam;
    6. import com.aliyuncs.domain_intl.model.v20171218.SaveBatchTaskForCreatingOrderActivateResponse;
    7. import com.aliyuncs.exceptions.ClientException;
    8. import com.aliyuncs.exceptions.ServerException;
    9. import com.aliyuncs.profile.DefaultProfile;
    10. import com.aliyuncs.profile.IClientProfile;
    11. public class DomainSdkDemo {
    12. private static IAcsClient client = null;
    13. //初始化client
    14. static {
    15. String regionId = "ap-southeast-1"; //域名SDK请使用固定值"ap-southeast-1"
    16. String accessKeyId = ""; // your accessKey
    17. String accessKeySecret = "";// your accessSecret
    18. IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
    19. // 若报Can not find endpoint to access异常,请添加以下此行代码
    20. // DefaultProfile.addEndpoint("ap-southeast-1", "ap-southeast-1", "Domain-intl", "domain-intl.aliyuncs.com");
    21. client = new DefaultAcsClient(profile);
    22. }
    23. public static void main(String[] args) {
    24. //初始化请求
    25. SaveBatchTaskForCreatingOrderActivateRequest request = new SaveBatchTaskForCreatingOrderActivateRequest();
    26. // request.setProtocol(ProtocolType.HTTPS); //指定访问协议
    27. // request.setAcceptFormat(FormatType.JSON); //指定api返回格式
    28. // request.setMethod(MethodType.POST); //指定请求方法
    29. ArrayList<OrderActivateParam> list = new ArrayList<OrderActivateParam>();
    30. OrderActivateParam orderActivateParam = new OrderActivateParam();
    31. orderActivateParam.setDomainName("yourdomain.com");
    32. orderActivateParam.setRegistrantProfileId(0L);
    33. orderActivateParam.setEnableDomainProxy(false);
    34. orderActivateParam.setSubscriptionDuration(1);
    35. orderActivateParam.setPermitPremiumActivation(false);
    36. list.add(orderActivateParam);
    37. request.setOrderActivateParams(list);
    38. //发起api调用并解析结果
    39. try {
    40. //IAcsClient提供了两种类型的调用结果返回, 一种方式是通过调用doAction方法获取取得原始的api调用结果, 即返回HttpResponse类型的结果. 示例代码如下:
    41. //HttpResponse httpResponse = client.doAction(describeCdnServiceRequest);
    42. //System.out.println(httpResponse.getUrl());
    43. //System.out.println(new String(httpResponse.getContent()));
    44. //另一种方式, 通过调用getAcsResponse方法, 获取反序列化后的对象, 示例代码如下:
    45. SaveBatchTaskForCreatingOrderActivateResponse response = client.getAcsResponse(request);
    46. System.out.println(response.getTaskNo());
    47. } catch (ServerException e) {
    48. e.printStackTrace();
    49. } catch (ClientException e) {
    50. e.printStackTrace();
    51. }
    52. }
    53. }