USMSSendReceipt
获取短信发送状态
接口说明
根据会话号(SessionNo)批量查询短信发送状态和回执信息。
请求信息
- 获取公私钥:
ACCESSKEY_ID:ACCESSKEY_SECRET - 请求方法:
GET - 请求路径:
/api/v1/usms/USMSSendReceipt - Content-Type:
application/json
请求参数
Header参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Content-Type | string | 是 | 请求内容类型 | "application/json" |
| Authorization | string | 是 | HTTP Basic认证信息 | "Basic $(echo -n 'accesskeyId:accesskeySecret' |
Query参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| id | string[] | 是 | 会话号列表(通过query参数传递,可多个) | ["session_no_1", "session_no_2"] |
注意: 参数通过URL查询字符串传递,格式为 ?id=session_no_1&id=session_no_2
请求示例
- CURL
- Golang
- Java
- Python
- PHP
curl -X GET "https://api.uspeedo.com/api/v1/usms/USMSSendReceipt?id=session_no_1&id=session_no_2" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)"
package main
import (
"encoding/base64"
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL := "https://api.uspeedo.com/api/v1/usms/USMSSendReceipt"
// 构建查询参数
params := url.Values{}
params.Add("id", "session_no_1")
params.Add("id", "session_no_2")
fullURL := baseURL + "?" + params.Encode()
// 创建请求
req, _ := http.NewRequest("GET", fullURL, nil)
req.Header.Set("Content-Type", "application/json")
// 设置HTTP Basic认证
accesskeyId := "YOUR_ACCESSKEY_ID"
accesskeySecret := "YOUR_ACCESSKEY_SECRET"
auth := base64.StdEncoding.EncodeToString([]byte(accesskeyId + ":" + accesskeySecret))
req.Header.Set("Authorization", "Basic "+auth)
// 发送请求
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Printf("请求失败: %v\n", err)
return
}
defer resp.Body.Close()
// 读取响应
body, _ := io.ReadAll(resp.Body)
fmt.Printf("响应状态码: %d\n", resp.StatusCode)
fmt.Printf("响应内容: %s\n", string(body))
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class GetUSMSSendReceipt {
public static void main(String[] args) {
try {
String baseURL = "https://api.uspeedo.com/api/v1/usms/USMSSendReceipt";
String[] sessionNos = {"session_no_1", "session_no_2"};
// 构建查询参数
StringBuilder queryParams = new StringBuilder();
for (String sessionNo : sessionNos) {
if (queryParams.length() > 0) {
queryParams.append("&");
}
queryParams.append("id=").append(URLEncoder.encode(sessionNo, StandardCharsets.UTF_8));
}
String url = baseURL + "?" + queryParams.toString();
// 创建连接
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
// 设置HTTP Basic认证
String accesskeyId = "YOUR_ACCESSKEY_ID";
String accesskeySecret = "YOUR_ACCESSKEY_SECRET";
String auth = accesskeyId + ":" + accesskeySecret;
String encodedAuth = Base64.getEncoder().encodeToString(auth.getBytes(StandardCharsets.UTF_8));
conn.setRequestProperty("Authorization", "Basic " + encodedAuth);
// 读取响应
int responseCode = conn.getResponseCode();
System.out.println("响应状态码: " + responseCode);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println("响应内容: " + response.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import requests
import base64
def get_usms_send_receipt(session_nos):
base_url = "https://api.uspeedo.com/api/v1/usms/USMSSendReceipt"
# 构建查询参数
params = [("id", session_no) for session_no in session_nos]
# 设置HTTP Basic认证
accesskey_id = "YOUR_ACCESSKEY_ID"
accesskey_secret = "YOUR_ACCESSKEY_SECRET"
credentials = base64.b64encode(f"{accesskey_id}:{accesskey_secret}".encode()).decode()
headers = {
"Content-Type": "application/json",
"Authorization": f"Basic {credentials}"
}
# 发送请求
response = requests.get(base_url, params=params, headers=headers)
print(f"响应状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return response.json() if response.status_code == 200 else None
if __name__ == "__main__":
session_nos = ["session_no_1", "session_no_2"]
get_usms_send_receipt(session_nos)
<?php
function getUSMSSendReceipt($sessionNos) {
$baseURL = "https://api.uspeedo.com/api/v1/usms/USMSSendReceipt";
// 构建查询参数
$queryParams = array();
foreach ($sessionNos as $sessionNo) {
$queryParams[] = "id=" . urlencode($sessionNo);
}
$url = $baseURL . "?" . implode("&", $queryParams);
// 设置HTTP Basic认证
$accesskeyId = "YOUR_ACCESSKEY_ID";
$accesskeySecret = "YOUR_ACCESSKEY_SECRET";
$auth = base64_encode($accesskeyId . ":" . $accesskeySecret);
// 初始化cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Basic " . $auth
));
// 执行请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "响应状态码: " . $httpCode . "\n";
echo "响应内容: " . $response . "\n";
return json_decode($response, true);
}
$sessionNos = array("session_no_1", "session_no_2");
getUSMSSendReceipt($sessionNos);
?>
响应格式
成功响应
{
"RetCode": 0,
"Message": "success",
"Data": [
{
"SessionNo": "session_no_1",
"Status": "success",
"Receipt": {
"Phone": "13800138000",
"Status": "delivered",
"ReceiveTime": "2024-01-01 12:00:00"
}
}
]
}
响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| RetCode | int | 返回码,0表示成功 |
| Message | string | 返回消息 |
| Data | array | 发送状态数据列表,每个元素包含:SessionNo(会话号)、Status(状态)、Receipt(回执信息) |
失败响应
{
"RetCode": 215392,
"Message": "Invalid parameter [id]"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 215392 | 参数错误 |
| 215397 | 缺少必填参数 |
| 215400 | 服务器错误 |