All Products
Search
Document Center

JAVA

Last Updated: Nov 26, 2019

Input parameters

Name Type O/M Description
To String Mandatory The format of a phone number: Country Code + Phone Number
From String Optional Sender ID supported, please refer to (Regulation of Sender ID
Message String Mandatory This is the text sending to the target phone number.

Output parameters

Name Type Example Description
MessageId String 10080303003003 The ID generated by Alibaba Cloud, to uniquely identify the serial number of SMS sending request.
To String 6531177810 The format of a phone number: Country Code + Phone Number
From String Alicloud Sender ID supported,please refer to (Regulation of Sender ID)
ResponseCode String OK This code indicates whether the SMS Send request is accepted by Alibaba Platform or has not been accepted.“OK” indicates the request is accepted.Other codes indicate different errors. The details please go to the StatusCode list.
ResponseDescription String The SMS Send Request was accepted The description of different Status Code.
Segments String 1 The number of parts into which Alibaba Cloud split.
NumberDetail String Detailed information of the number
└Country String Hongkong, China Number Country
└Region String HongKong Number Region
└Carrier String CMI Number Carrier/Network

Developer integration process

1.Core-sdk import

Option 1,maven

  1. <dependency>
  2. <groupId>com.aliyun</groupId>
  3. <artifactId>aliyun-java-sdk-core</artifactId>
  4. <version>4.4.6</version>
  5. </dependency>

Option 2,Core-sdk download: Java API SDK

2.Writing a sample program

When calling the interface, please note:

  • When creating DefaultProfile, the first parameter (regionId) must be “ap-southeast-1”, please do not modify it.
  • Domain must be “sms-intl.ap-southeast-1.aliyuncs.com”, please do not modify it.
  • Version must be 2018-05-01, please do not modify it.
  1. package com.alicom.dysms.api;
  2. import com.aliyuncs.CommonRequest;
  3. import com.aliyuncs.CommonResponse;
  4. import com.aliyuncs.DefaultAcsClient;
  5. import com.aliyuncs.IAcsClient;
  6. import com.aliyuncs.exceptions.ClientException;
  7. import com.aliyuncs.exceptions.ServerException;
  8. import com.aliyuncs.http.MethodType;
  9. import com.aliyuncs.profile.DefaultProfile;
  10. /*
  11. pom.xml
  12. <dependency>
  13. <groupId>com.aliyun</groupId>
  14. <artifactId>aliyun-java-sdk-core</artifactId>
  15. <version>4.4.6</version>
  16. </dependency>
  17. */
  18. public class CommonRpc {
  19. public static void main(String[] args) {
  20. // acsClient,<accessKeyId> and "<accessSecret>" can be get from the console
  21. DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
  22. IAcsClient client = new DefaultAcsClient(profile);
  23. CommonRequest request = new CommonRequest();
  24. request.setMethod(MethodType.POST);
  25. //Domain name, don’t change
  26. request.setDomain("sms-intl.ap-southeast-1.aliyuncs.com");
  27. //API Version,don’t change
  28. request.setVersion("2018-05-01");
  29. //API name
  30. request.setAction("SendMessageToGlobe");
  31. request.putQueryParameter("To", "6212345678901");
  32. //Optional
  33. //request.putQueryParameter("From", "1234567890");
  34. request.putQueryParameter("Message", "have a test.");
  35. try {
  36. CommonResponse response = client.getCommonResponse(request);
  37. System.out.println(response.getData());
  38. } catch (ServerException e) {
  39. e.printStackTrace();
  40. } catch (ClientException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44. }