本文为您介绍了Java调用QueryMessage查看短信状态。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
MessageId | String | 是 | 100803***03003 | 短信发送ID。 |
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
ResponseCode | String | OK | 短信提交的状态。 |
ResponseDescription | String | The SMS Send Request was accepted | 短信提交状态的详细描述。 |
To | String | 6581***810 | 发送号码。 |
Status | Number | 1 | 短信的发送状态:
|
ErrorCode | String | DELIVERED | 短信的发送状态码。 |
ErrorDescription | String | success | 短信发送状态码的详细描述。 |
Message | String | Hello! | 短信内容。 |
SendDate | String | Mon, 24 Dec 2018 16:58:22 +0800 | 短信转发给运营商的时间。 |
ReceiveDate | String | Mon, 24 Dec 2018 16:58:22 +0800 | 短信收到运营商回执的时间。 |
NumberDetail | String | 号码的详细属性。 | |
└Country | String | Hongkong, China | 号码所属国家。 |
└Region | String | HongKong | Number Region。 |
└Carrier | String | CMI | 号码所属的运营商网络。 |
引入阿里云核心包
- 方法1:maven
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.4.6</version> </dependency>
- 方法2:core-sdk下载地址:Java API SDK。
调用示例
注意事项如下:
- 构造DefaultProfile时,第一个参数(regionId)必须为ap-southeast-1,请勿修改。
- domain必须为dysmsapi.ap-southeast-1.aliyuncs.com,请勿修改。
- version必须为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) {
//初始化acsClient,<accessKeyId>和"<accessSecret>"在短信控制台查询即可。
DefaultProfile profile = DefaultProfile.getProfile("ap-southeast-1", "<accessKeyId>", "<accessSecret>");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
//域名,请勿修改
request.setDomain("dysmsapi.ap-southeast-1.aliyuncs.com");
//API版本号,请勿修改
request.setVersion("2018-05-01");
//API名称
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();
}
}
}