批量发送短信
接口说明
批量发送短信,支持一次向多个手机号发送。
请求信息
- 获取公私钥:
ACCESSKEY_ID:ACCESSKEY_SECRET - 请求方法:
POST - 请求路径:
/api/v1/usms/SendBatchUSMSMessage - Content-Type:
application/json
说明:
- 单次请求的号码总数(所有
Target数组之和)最多 1000 个。 - 响应中的
SessionNo是一个 UUID 字符串,标识本次批量发送任务,不是数组;一次请求中的所有号码共用同一个SessionNo。
AccountIdint
模板所属的项目 ID。非必填——不传时使用当前 API Key 的默认项目。若使用的模板不属于默认项目,必须传入该模板所属的项目 ID,否则会返回 "Invalid Template"。当前 API Key 需对该项目有访问权限。
?
TaskContentarray必填
通过表单列表逐条添加发送任务,组件会自动拼装为 TaskContent JSON 结构。
TaskContent 预览
以下内容会被自动拼装到请求体中。
[
{
"TemplateId": "template_id_1",
"SenderId": "uSpeedo",
"Target": [
{
"Phone": "13800138000",
"TemplateParams": [
"123456"
]
}
]
}
]任务 1
Body 参数
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| AccountId | int | 否 | 模板所属项目 ID。不传时使用当前 API Key 的默认项目;模板不属于默认项目时必须传入。 | 60000001 |
| TaskContent | array | 是 | 发送任务列表 | 见下方结构说明 |
TaskContent 数组元素说明
每个元素包含以下字段:
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| TemplateId | string | 是 | 模板 ID | "template_id_1" |
| SenderId | string | 否 | 发送方标识(发送方名称),最长 11 个字符;不传或为空时默认为 Uinter;不能包含中文 | "uSpeedo" |
| Target | array | 是 | 目标手机号列表 | 见下方说明 |
Target 数组元素说明
每个元素包含以下字段:
| 参数名 | 类型 | 必填 | 说明 | 示例值 |
|---|---|---|---|---|
| Phone | string | 是 | 手机号 | "13800138000" |
| TemplateParams | array | 否 | 模板参数(按模板变量顺序填写) | ["123456"] |
| ExtendCode | string | 否 | 短信扩展码,最长 32 个字符 | "123" |
| UserId | string | 否 | 自定义业务标识 ID,最长 32 个字符 | "456" |
响应格式
成功响应
{
"Action": "SendBatchUSMSMessageResponse",
"RetCode": 0,
"Message": "Send success",
"ReqUuid": "cbfaf1a2-9d12-4f8a-81c7-56f67ba708ea",
"SessionNo": "550e8400-e29b-41d4-a716-446655440000",
"SuccessCount": 2
}
部分成功响应
只要存在失败号码,RetCode 即为 18046,失败明细通过 FailContent 返回。全部号码都失败时同样返回 18046(此时 SuccessCount 为 0,且不返回 SessionNo),具体原因需查看 FailContent:
{
"Action": "SendBatchUSMSMessageResponse",
"RetCode": 18046,
"Message": "USMS Batch Send Partial Success, Number of successfully sent is 1",
"ReqUuid": "cbfaf1a2-9d12-4f8a-81c7-56f67ba708ea",
"SessionNo": "550e8400-e29b-41d4-a716-446655440000",
"SuccessCount": 1,
"FailContent": [
{
"TemplateId": "template_id_1",
"SenderId": "uSpeedo",
"Target": [
{
"Phone": "13800138001",
"TemplateParams": ["123456"],
"FailureDetails": "Invalid phone number [13800138001]",
"Invalid": true
}
]
}
]
}
响应字段说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| Action | string | 固定值 SendBatchUSMSMessageResponse |
| RetCode | int | 返回码,0 表示成功,18046 表示部分成功 |
| Message | string | 返回消息 |
| ReqUuid | string | 请求 UUID,反馈问题时请提供 |
| SessionNo | string | 本次批量发送任务的会话号(单个 UUID 字符串,不是数组),仅在有号码提交成功时返回。据此调用 获取短信发送状态 查询发送结果 |
| SuccessCount | int | 提交成功的号码数(拆分前) |
| FailContent | array | 失败明细,仅在 RetCode 为 18046 时返回。每个元素对应 TaskContent 中的一个失败任务 |
FailContent 元素说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| TemplateId | string | 失败任务的模板 ID |
| SenderId | string | 失败任务的发送方标识 |
| Target | array | 失败的号码列表,见下方说明 |
| FailureDetails | string | 整个任务的失败原因(如模板无效、SenderId 非法)。该字段有值时,号码粒度的 FailureDetails 可能为空 |
FailContent Target 元素说明
| 字段名 | 类型 | 说明 |
|---|---|---|
| Phone | string | 手机号 |
| TemplateParams | array | 模板参数 |
| ExtendCode | string | 短信扩展码(请求中传了才返回) |
| UserId | string | 自定义业务标识 ID(请求中传了才返回) |
| FailureDetails | string | 该号码的失败原因,如 Invalid phone number [...]、Quota is not enough in area [...]、Invalid Template para numbers (should be N) |
| Invalid | bool | 失败明细中恒为 true |
错误响应
{
"Action": "SendBatchUSMSMessageResponse",
"RetCode": 18001,
"Message": "Missing parameter [TaskContent]",
"ReqUuid": "cbfaf1a2-9d12-4f8a-81c7-56f67ba708ea"
}
常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 18001 | 缺少必填参数 |
| 18003 | 参数格式错误 |
| 18019 | 号码数量超限(单次请求超过 1000 个) |
| 18046 | 部分成功(部分号码失败,详见 FailContent) |
| 215392 | 参数错误(网关) |
| 215397 | 缺少必填参数(网关) |
| 215400 | 服务器错误(网关) |
语言
请求地址
POST
CURL 请求▼
curl -X POST "https://api.uspeedo.com/api/v1/usms/SendBatchUSMSMessage" \-H "Content-Type: application/json" \-H "Accept: application/json" \-H "Authorization: Basic $(echo -n 'ACCESSKEY_ID:ACCESSKEY_SECRET' | base64)" \-d '{"TaskContent": [{"TemplateId": "template_id_1","SenderId": "uSpeedo","Target": [{"Phone": "13800138000","TemplateParams": ["123456"]}]}]}'
响应
点击“发起请求”后,可在此查看响应结果。