DEVELOPER API
SMS API 一个密钥即可发送
通过 SMSOnline 从你的应用、网店或预约系统发送短信。价格和规则与网页发送页面相同。
20,000每次请求号码数
120每分钟请求数
JSON请求和响应
QUICK START
快速开始
- 01在账户的 API 页面创建密钥(以 so_ 开头)。
- 02每次请求都带上请求头 Authorization: Bearer <key>。
- 03用 POST /api/v1/quote 确认费用,再用 POST /api/v1/messages 发送。
基础 URL
https://smsonline.blog/api/v1
ENDPOINTS
接口
| 请求 | 说明 |
|---|---|
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 | 发送前取消定时,全额退款 |
SEND
发送
to 是号码数组或用换行分隔的文本。要使用不带 + 的号码,请把 country 设为默认国家代码(如 us 或 kr)。
| 字段 | 说明 |
|---|---|
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.012",
"countries": [
{ "country": "US", "recipients": 1, "cost": "0.0047" },
{ "country": "GB", "recipients": 1, "cost": "0.0073" }
]
},
"rejected": [],
"duplicates": 0,
"opted_out": 0,
"balance": "48.988"
}POST /api/v1/messages
curl -X POST https://smsonline.blog/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://smsonline.blog/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.0147",
"balance": "49.00",
"countries": [
{ "country": "JP", "recipients": 1, "price": "0.01", "cost": "0.01" },
{ "country": "US", "recipients": 1, "price": "0.0047", "cost": "0.0047" }
],
"rejected": [],
"duplicates": 0,
"opted_out": 0
}ERRORS
错误码
| 代码 | 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 | 定时时间超出范围 |
low_balance | 402 | 余额不足 |
unavailable | 503 | 暂时无法发送(未扣费) |
not_found | 404 | 没有这次发送 |
not_scheduled | 409 | 已发送或已取消 |