开发者

短信 API, 一个密钥,JSON 收发

把短信发送接入你的应用、网店或预约系统。请求经过与网页发送页面相同的逐行检查、价格表和退订名单,所以 API 发送也会显示在同一个发送记录和余额记录中。

20,000每批号码数
120每分钟调用次数
JSON请求和响应
窗边桌上显示代码的笔记本电脑

快速开始

从密钥到第一条短信

  1. 01在账户的 API 页面生成密钥,密钥以 sn_ 开头。
  2. 02每次调用时加上请求头 Authorization: Bearer <key>。
  3. 03先用 POST /api/v1/quote 查询一批号码的费用,再把同一批交给 POST /api/v1/messages。

基础 URL

https://smsnumber.online/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在开始前取消定时批次并退回余额

发送

提交一批号码

传入 JSON 数组,或每行一个号码的文本。以 + 开头的行按国际号码识别;不带 + 的行,请传入两位字母国家代码,如 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.0112",
    "countries": [
      { "country": "US", "recipients": 1, "cost": "0.0044" },
      { "country": "GB", "recipients": 1, "cost": "0.0068" }
    ]
  },
  "rejected": [],
  "duplicates": 0,
  "opted_out": 0,
  "balance": "48.9888"
}
POST /api/v1/messages
curl -X POST https://smsnumber.online/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://smsnumber.online/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.0087", "cost": "0.0087" },
    { "country": "US", "recipients": 1, "price": "0.0044", "cost": "0.0044" }
  ],
  "rejected": [],
  "duplicates": 0,
  "opted_out": 0
}

错误

错误码

代码HTTP出现情况
unauthorized401缺少密钥或密钥无法识别
rate_limited429该密钥在最近一分钟内调用次数过多
bad_request400请求体不是有效的 JSON
empty_text400text 为空
too_long400text 超过 10 条
no_numbers400所有行都在检查中被剔除
too_many400批次超过 20,000 行
bad_time400schedule_at 超出允许范围
low_balance402余额不足以支付这批
unavailable503暂停发送中,未扣除余额
not_found404你的账户中没有这个 id 的批次
not_scheduled409批次已经开始或已取消

限制和规则

  • 每个密钥每分钟最多调用 120 次。
  • 金额以美元字符串返回,例如 "0.0047"。
  • 批次 id 是随机的 12 位字符,不是递增编号。
  • 逐行检查和退订名单与网页发送完全一致。
获取 API 密钥