This topic describes how to use SMS SDK for Java to call the QueryMessage operation. This API operation allows you to query the statuses of text messages.
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
MessageId | String | Yes | 100803***03003 | The ID of the text message. |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
ResponseCode | String | OK | The status that indicates whether the message sending request was submitted. |
ResponseDescription | String | The SMS Send Request was accepted | The detailed description of the status that indicates whether the message sending request was submitted. |
To | String | 6581***810 | The mobile phone number that received the text message. |
Status | Number | 1 | The status that indicates whether the text message was sent.
|
ErrorCode | String | DELIVERED | The status code that indicates whether the text message was sent. |
ErrorDescription | String | success | The description of the status code that indicates whether the text message was sent. |
Message | String | Hello! | The content of the text message. |
SendDate | String | Mon, 24 Dec 2018 16:58:22 +0800 | The time when the text message was sent to the carrier. |
ReceiveDate | String | Mon, 24 Dec 2018 16:58:22 +0800 | The time when the delivery receipt was received from the carrier. |
NumberDetail | String | The details of the mobile phone number. | |
└Country | String | Hongkong, China | The country to which the mobile phone number belongs. |
└Country | String | HongKong | The region to which the mobile phone number belongs. |
└Region | String | CMI | The carrier that provides the mobile phone number. |
Install the core library of Alibaba Cloud SDK for Java
- Method 1: Add Maven dependencies.
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.4.6</version> </dependency>
- Method 2: Click Alibaba Cloud SDK for Java to download the core library of Alibaba Cloud SDK for Java.
Sample requests
Take note of the following information:
- When you define a new default profile, the value of the regionId parameter must be ap-southeast-1 and cannot be modified. Note that regionId is the first parameter in the default profile.
- You must set the domain parameter to dysmsapi.ap-southeast-1.aliyuncs.com.
- You must set the version parameter to 2018-05-01.
package com.alicom.dysms.api;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.6</version>
</dependency>
*/
public class CommonRpc {
public static void main(String[] args) {
// Initialize the IAcsClient object. You can query the values of the <accessKeyId> and <accessSecret> parameters in the SMS console.
DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
// The domain name, which cannot be modified.
request.setDomain("dysmsapi.ap-southeast-1.aliyuncs.com");
// The API version number, which cannot be modified.
request.setVersion("2018-05-01");
// The API operation.
request.setAction("QueryMessage");
request.putQueryParameter("MessageId", "140101545641902498");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}