SendBatchUSMSMessage
批量发送短信
接口说明
批量发送短信消息,支持一次发送给多个手机号。
请求信息
- 获取公私钥:
ACCESSKEY_ID:ACCESSKEY_SECRET - 请求方法:
POST - 请求路径:
/api/v1/usms/SendBatchUSMSMessage - Content-Type:
application/json
请求参数
Header参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Content-Type | string | 是 | 请求内容类型 | "application/json" |
| Authorization | string | 是 | HTTP Basic认证信息 | "Basic $(echo -n 'accesskeyId:accesskeySecret' |
Body参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| TaskContent | array | 是 | 发送任务列表 | 见下方说明 |
TaskContent 数组元素说明
每个元素包含以下字段:
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| TemplateId | string | 是 | 模板ID | "template_id_1" |
| SenderId | string | 是 | 发送方标识(发送方名称) | "USpeedo" |
| Target | array | 是 | 目标手机号列表 | 见下方说明 |
Target 数组元素说明
每个元素包含以下字段:
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Phone | string | 是 | 手机号码 | "13800138000" |
| TemplateParams | array | 否 | 模板参数(根据模板变量填写) | ["123456"] |
请求示例
- CURL
- Golang
- Java
- Python
- PHP
curl -X POST "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $(echo -n 'YOUR_ACCESSKEY_ID:YOUR_ACCESSKEY_SECRET' | base64)" \
-d '{
"TaskContent": [
{
"TemplateId": "template_id_1",
"SenderId": "USpeedo",
"Target": [
{
"Phone": "13800138000",
"TemplateParams": ["123456"]
}
]
}
]
}'
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"net/http"
)
type TargetPhone struct {
Phone string `json:"Phone"`
TemplateParams []string `json:"TemplateParams,omitempty"`
}
type SendInfo struct {
TemplateId string `json:"TemplateId"`
SenderId string `json:"SenderId"`
Target []TargetPhone `json:"Target"`
}
type SendBatchRequest struct {
TaskContent []SendInfo `json:"TaskContent"`
}
func main() {
url := "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage"
// 准备请求体
requestBody := SendBatchRequest{
TaskContent: []SendInfo{
{
TemplateId: "template_id_1",
SenderId: "USpeedo",
Target: []TargetPhone{
{
Phone: "13800138000",
TemplateParams: []string{"123456"},
},
{
Phone: "13900139000",
TemplateParams: []string{"654321"},
},
},
},
},
}
jsonData, _ := json.Marshal(requestBody)
// 创建请求
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
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.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class SendBatchUSMSMessage {
public static void main(String[] args) {
try {
String url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage";
// 准备请求体
String jsonBody = "{\n" +
" \"TaskContent\": [\n" +
" {\n" +
" \"TemplateId\": \"template_id_1\",\n" +
" \"SenderId\": \"USpeedo\",\n" +
" \"Target\": [\n" +
" {\n" +
" \"Phone\": \"13800138000\",\n" +
" \"TemplateParams\": [\"123456\"]\n" +
" },\n" +
" {\n" +
" \"Phone\": \"13900139000\",\n" +
" \"TemplateParams\": [\"654321\"]\n" +
" }\n" +
" ]\n" +
" }\n" +
" ]\n" +
"}";
// 创建连接
URL apiUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) apiUrl.openConnection();
conn.setRequestMethod("POST");
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);
// 发送请求体
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = jsonBody.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 读取响应
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 send_batch_usms_message():
url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage"
# 准备请求体
payload = {
"TaskContent": [
{
"TemplateId": "template_id_1",
"SenderId": "USpeedo",
"Target": [
{
"Phone": "13800138000",
"TemplateParams": ["123456"]
},
{
"Phone": "13900139000",
"TemplateParams": ["654321"]
}
]
}
]
}
# 设置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.post(url, json=payload, headers=headers)
print(f"响应状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return response.json() if response.status_code == 200 else None
if __name__ == "__main__":
send_batch_usms_message()
<?php
function sendBatchUSMSMessage() {
$url = "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage";
// 准备请求体
$data = array(
"TaskContent" => array(
array(
"TemplateId" => "template_id_1",
"SenderId" => "USpeedo",
"Target" => array(
array(
"Phone" => "13800138000",
"TemplateParams" => array("123456")
),
array(
"Phone" => "13900139000",
"TemplateParams" => array("654321")
)
)
)
)
);
$jsonData = json_encode($data);
// 设置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_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
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);
}
sendBatchUSMSMessage();
?>
响应格式
成功响应
{
"RetCode": 0,
"Message": "success",
"SessionNo": ["session_no_1", "session_no_2"],
"FailedTargetPhones": []
}
响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| RetCode | int | 返回码,0表示成功 |
| Message | string | 返回消息 |
| SessionNo | array | 会话编号列表,用于查询发送状态 |
| FailedTargetPhones | array | 发送失败的手机号列表,每个元素包含:Phone(手机号)、TemplateParams(模板参数)、FailureReason(失败原因) |
失败响应
{
"RetCode": 215392,
"Message": "Invalid parameter [TemplateId]"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 215392 | 参数错误 |
| 215397 | 缺少必填参数 |
| 215400 | 服务器错误 |