面向开发者
短信API 通过 REST 发送群发短信和验证码
把你的应用、网店或预约系统接入 WorldText 短信平台。价格和发送规则与网页发送后台一致。
20,000每次请求最多号码数
120每个密钥每分钟请求数
JSON请求和响应
快速开始
第一个请求
- 01进入账户的 API 页面生成密钥。密钥以 wt_ 开头。
- 02在每个请求中加上请求头 Authorization: Bearer <密钥>。
- 03用 POST /api/v1/quote 获取价格,再通过 POST /api/v1/messages 发送。
基础 URL
https://worldtext.world/api/v1
接口
接口列表
| 方法和路径 | 用途 |
|---|---|
GET /api/v1/balance | 当前余额,以美元计 |
GET /api/v1/countries | 覆盖国家及每条价格(无需密钥) |
POST /api/v1/quote | 价格、条数和被过滤的号码,不发送 |
POST /api/v1/messages | 立即发送,设置 schedule_at 时定时发送 |
GET /api/v1/messages | 最近的发送列表(limit, offset) |
GET /api/v1/messages/{id} | 单次发送及其按国家的结果 |
POST /api/v1/messages/{id}/cancel | 取消尚未发出的定时发送并全额退款 |
发送
发送短信
to 字段可传号码数组,或每行一个号码的文本。对于不带 + 的号码,请把 country 字段设为两位字母的国家代码,例如 us 或 cn。
| 字段 | 说明 |
|---|---|
to | 接收人。数组或每行一个号码,最多 20,000 个 |
text | 短信内容,不超过 10 条 |
country | 可选。不带 + 的号码使用的两位国家代码 |
schedule_at | 可选。带时区的 ISO 时间(如 2026-12-01T09:00:00Z)或 Unix 秒数,须在 5 分钟后至 30 天内 |
client_ref | 可选。你自己的参考编号,最多 64 个字符 |
响应 · 201201 Created
{
"ok": true,
"campaign": {
"id": "K7Q2M9XD4TPA",
"status": "sending",
"recipients": 2,
"parts": 1,
"encoding": "GSM-7",
"cost": "0.0105",
"countries": [
{ "country": "US", "recipients": 1, "cost": "0.0041" },
{ "country": "GB", "recipients": 1, "cost": "0.0064" }
]
},
"rejected": [],
"duplicates": 0,
"opted_out": 0,
"balance": "48.9895"
}POST /api/v1/messages
curl -X POST https://worldtext.world/api/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": ["+14155550142", "+447400123456"],
"text": "Your order #A2847 has shipped."
}'POST /api/v1/quote
curl -X POST https://worldtext.world/api/v1/quote \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "to": ["+14155550142", "+819012345678"], "text": "Hello" }'响应 · 200200 OK
{
"ok": true,
"recipients": 2,
"parts": 1,
"encoding": "GSM-7",
"cost": "0.0131",
"balance": "49.00",
"countries": [
{ "country": "JP", "recipients": 1, "price": "0.009", "cost": "0.009" },
{ "country": "US", "recipients": 1, "price": "0.0041", "cost": "0.0041" }
],
"rejected": [],
"duplicates": 0,
"opted_out": 0
}错误
错误响应
| 代码 | HTTP | 原因 |
|---|---|---|
unauthorized | 401 | 没有密钥或密钥无效 |
rate_limited | 429 | 本分钟请求过多 |
bad_request | 400 | 无法解析请求体 |
empty_text | 400 | 没有短信内容 |
too_long | 400 | 内容超过 10 条 |
no_numbers | 400 | 没有可发送的号码 |
too_many | 400 | 一次请求超过 20,000 个号码 |
bad_time | 400 | schedule_at 不在允许的时间范围内 |
low_balance | 402 | 余额不足以完成这次发送 |
unavailable | 503 | 发送暂时停止,未扣余额 |
not_found | 404 | 该发送 ID 不存在 |
not_scheduled | 409 | 该发送已发出或已取消 |