全部产品
云市场

IAcsClientUtil

更新时间:2018-10-19 09:00:02

获取client可参考发送邮件示例。IAcsClientUtil类,示例如下。

  1. import com.aliyuncs.DefaultAcsClient;
  2. import com.aliyuncs.IAcsClient;
  3. import com.aliyuncs.exceptions.ClientException;
  4. import com.aliyuncs.profile.DefaultProfile;
  5. import com.aliyuncs.profile.IClientProfile;
  6. public class IAcsClientUtil {
  7. private static String accessKeyId = "";
  8. private static String secret = "";
  9. private static String product = "Dm";
  10. private static String regionId_hangzhou = "cn-hangzhou";//杭州
  11. private static String accountName = "noreply@***.dmtest.club";
  12. //noreply@***.dmtest.club---杭州
  13. //noreply@***.dmtest.club---新加坡
  14. //noreply@***.dmtest.club---澳洲
  15. private static String regionId = "cn-hangzhou";//杭州
  16. private static String endpointName = "";
  17. private static String domain = "";
  18. //新加坡
  19. // private static String regionId = "ap-southeast-1";
  20. // private static String endpointName = "dm.ap-southeast-1.aliyuncs.com";
  21. // private static String domain = "dm.ap-southeast-1.aliyuncs.com";
  22. //澳洲
  23. // private static String regionId = "ap-southeast-2";
  24. // private static String endpointName = "dm.ap-southeast-2.aliyuncs.com";
  25. // private static String domain = "dm.ap-southeast-2.aliyuncs.com";
  26. protected static IAcsClient getiAcsClient() {
  27. // 如果是除杭州region外的其它region(如新加坡、澳洲Region),需要将下面的"cn-hangzhou"替换为"ap-southeast-1"、或"ap-southeast-2"。
  28. IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, secret);
  29. if (!regionId_hangzhou.equals(regionId)) {
  30. // 如果是除杭州region外的其它region(如新加坡region), 需要做如下处理
  31. try {
  32. DefaultProfile.addEndpoint(endpointName, regionId, product, domain);
  33. } catch (ClientException e) {
  34. e.printStackTrace();
  35. }
  36. }
  37. return new DefaultAcsClient(profile);
  38. }
  39. }