号屿开放 API
把你的系统接到号屿:查价、下单、取验证码、取消退款,全部走 HTTP 接口。价格和网页端一致,扣的是你账户余额。
1. 概述
- 接口地址:
https://你的域名/api.php?path=/open/v1/...(不需要配伪静态,宝塔默认就能跑) - 数据格式:请求与响应都是 JSON(UTF-8),金额单位统一是人民币元
- 认证方式:API Key + HMAC-SHA256 签名(详见第 3 节)
- 调用方:只能从你自己的服务端调用,不要放在浏览器 / App / 小程序前端
insufficient_balance,不会透支。号码没收到短信时,取消会全额退回余额(产品类卡密订单不支持自助取消)。
2. 接入准备
- 登录号屿 → 底部「活动」→「开放 API」→「管理 API Key」
- 点右上角 + 新建一个 Key,建议填上 IP 白名单(你服务器的出口 IP)
- 创建成功后会显示 key 和 secret——secret 只显示这一次,请立刻存进配置或环境变量
- 先用
GET /open/v1/ping跑通签名,再调业务接口
3. 认证与签名
每个请求必须带 4 个头:
| 请求头 | 说明 |
|---|---|
X-Api-Key | 创建 Key 时给的 key,形如 hy_xxxxxxxx |
X-Api-Timestamp | 当前秒级时间戳,与服务器相差不能超过 5 分钟 |
X-Api-Nonce | 每次请求都要新的随机串(8–48 位字母数字),重复会被拒 |
X-Api-Sign | 下面这个签名串的 HMAC-SHA256(十六进制小写),密钥是你的 secret |
签名串怎么拼
6 行,用 \n 连接,顺序不能变:
第 1 行:HTTP 方法(大写) GET
第 2 行:业务路径(不含 /api) /open/v1/balance
第 3 行:查询参数(按 key 升序,k=v 用 & 连接,不含 path) page=1&status=PENDING
第 4 行:时间戳 1730000000
第 5 行:nonce a1b2c3d4e5f6
第 6 行:请求体的 SHA-256(小写) 空请求体就是空字符串的 sha256:e3b0c442...
然后 sign = hash_hmac('sha256', 签名串, secret)。
① 第 2 行是业务路径(
/open/v1/orders),不是 /api.php;② 第 3 行的参数要按 key 字典序排,值要做 URL 编码(和 URL 里的写法一致);
③ 第 6 行是对原始请求体字符串做 sha256,不是对解析后的数组——JSON 里空格、字段顺序都要和你实际发出去的一模一样。
PHP 示例
<?php
$base = 'https://你的域名';
$key = 'hy_xxxxxxxx';
$secret = '你的 secret';
function openApi(string $method, string $path, array $query = [], array $body = null): array {
global $base, $key, $secret;
$ts = (string) time();
$nonce = bin2hex(random_bytes(8));
$raw = $body === null ? '' : json_encode($body, JSON_UNESCAPED_UNICODE);
ksort($query);
$pairs = [];
foreach ($query as $k => $v) {
$pairs[] = rawurlencode((string) $k) . '=' . rawurlencode((string) $v);
}
$qs = implode('&', $pairs);
$signStr = implode("\n", [$method, $path, $qs, $ts, $nonce, hash('sha256', $raw)]);
$sign = hash_hmac('sha256', $signStr, $secret);
$url = $base . '/api.php?path=' . rawurlencode($path) . ($qs !== '' ? '&' . $qs : '');
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => [
'X-Api-Key: ' . $key,
'X-Api-Timestamp: ' . $ts,
'X-Api-Nonce: ' . $nonce,
'X-Api-Sign: ' . $sign,
'Content-Type: application/json',
],
CURLOPT_TIMEOUT => 30,
]);
if ($raw !== '') {
curl_setopt($ch, CURLOPT_POSTFIELDS, $raw);
}
$resp = curl_exec($ch);
curl_close($ch);
return json_decode((string) $resp, true);
}
// 查余额
print_r(openApi('GET', '/open/v1/balance'));
// 下一单(国内通道)
print_r(openApi('POST', '/open/v1/orders', [], [
'channel' => 'domestic',
'keyword' => '抖音',
]));
Node.js 示例
const crypto = require('crypto');
const BASE = 'https://你的域名';
const KEY = 'hy_xxxxxxxx';
const SECRET = '你的 secret';
async function openApi(method, path, query = {}, body = null) {
const ts = String(Math.floor(Date.now() / 1000));
const nonce = crypto.randomBytes(8).toString('hex');
const raw = body === null ? '' : JSON.stringify(body);
const qs = Object.keys(query).sort()
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(query[k]))
.join('&');
const signStr = [method, path, qs, ts, nonce,
crypto.createHash('sha256').update(raw).digest('hex')].join('\n');
const sign = crypto.createHmac('sha256', SECRET).update(signStr).digest('hex');
const url = `${BASE}/api.php?path=${encodeURIComponent(path)}${qs ? '&' + qs : ''}`;
const res = await fetch(url, {
method,
headers: {
'X-Api-Key': KEY,
'X-Api-Timestamp': ts,
'X-Api-Nonce': nonce,
'X-Api-Sign': sign,
'Content-Type': 'application/json',
},
body: raw === '' ? undefined : raw,
});
return res.json();
}
// 查余额
console.log(await openApi('GET', '/open/v1/balance'));
Python 示例
import time, json, hashlib, hmac, secrets, urllib.parse, urllib.request
BASE = "https://你的域名"
KEY = "hy_xxxxxxxx"
SECRET = "你的 secret"
def open_api(method, path, query=None, body=None):
query = query or {}
ts = str(int(time.time()))
nonce = secrets.token_hex(8)
raw = "" if body is None else json.dumps(body, ensure_ascii=False, separators=(",", ":"))
qs = "&".join(f"{urllib.parse.quote(str(k), safe='')}={urllib.parse.quote(str(query[k]), safe='')}"
for k in sorted(query))
sign_str = "\n".join([method, path, qs, ts, nonce,
hashlib.sha256(raw.encode()).hexdigest()])
sign = hmac.new(SECRET.encode(), sign_str.encode(), hashlib.sha256).hexdigest()
url = f"{BASE}/api.php?path={urllib.parse.quote(path, safe='')}" + (f"&{qs}" if qs else "")
data = raw.encode() if raw else None
req = urllib.request.Request(url, data=data, method=method, headers={
"X-Api-Key": KEY,
"X-Api-Timestamp": ts,
"X-Api-Nonce": nonce,
"X-Api-Sign": sign,
"Content-Type": "application/json",
})
with urllib.request.urlopen(req, timeout=30) as r:
return json.loads(r.read().decode())
print(open_api("GET", "/open/v1/balance"))
bad_signature = 签名串拼错了(八成是 query 没排序,或 body 被重新序列化过);
② timestamp_expired = 你服务器时间不准,装个 NTP;
③ nonce_reused = 你复用了 nonce(比如重试时用了同一组参数)。
4. 公共约定
成功:
{ "ok": true, "data": { ... } }
失败(HTTP 4xx/5xx):
{ "ok": false, "error": { "code": "insufficient_balance", "message": "余额不足,请先充值" } }
5. 接口清单
| 方法 | 路径 | 说明 |
|---|---|---|
| GET | /open/v1/ping | 连通性与签名自检 |
| GET | /open/v1/balance | 账户余额 |
| GET | /open/v1/services | 国际应用列表(可按关键词搜) |
| GET | /open/v1/countries | 国家 / 地区列表 |
| GET | /open/v1/offers | 某个应用在某国家的线路与价格 |
| GET | /open/v1/goods | 产品渠道(卡密商品)列表 |
| POST | /open/v1/orders | 下单(三种渠道共用一个入口) |
| GET | /open/v1/orders | 订单列表 |
| GET | /open/v1/orders/{订单号} | 订单详情(含验证码) |
| POST | /open/v1/orders/{订单号}/cancel | 取消并退款 |
| POST | /open/v1/orders/{订单号}/finish | 标记完成 |
GET /open/v1/balance
{ "ok": true, "data": { "balance": 104.18, "currency": "CNY", "email": "you@example.com" } }
GET /open/v1/services
参数:keyword(可选,搜名称/别名)、limit(默认 300,最大 500)。
返回每项含 slug(下单时用)、name、category、price(起价)、stock。
GET /open/v1/countries
参数同上。返回 slug、name、iso、prefix。
GET /open/v1/offers
参数:service(必填)、country(默认 all,只用于比价;下单必须给具体国家)。
{ "ok": true, "data": { "offers": [
{ "country_slug": "russia", "country_name": "俄罗斯", "operator": "any",
"operator_zh": "任意运营商", "price": 1.20, "count": 320, "available": true }
] } }
6. 下单与取码
POST /open/v1/orders
三种渠道共用一个入口,靠 channel 区分:
| channel | 必填参数 | 可选参数 |
|---|---|---|
international(默认) |
service、country |
operator(默认 any) |
domestic |
keyword(短信里【】中的词) |
card_type(全部/实卡/虚卡)、province、phone(指定号码) |
product |
goods_id |
quantity(默认 1) |
// 国际:Telegram + 俄罗斯
{ "channel": "international", "service": "telegram", "country": "russia" }
// 国内:关键词取号(可指定号码)
{ "channel": "domestic", "keyword": "抖音", "card_type": "全部", "phone": "13800138000" }
// 产品:卡密商品
{ "channel": "product", "goods_id": 12, "quantity": 1 }
返回:
{ "ok": true, "data": { "order": {
"order_no": "HY26110286682455593471",
"channel": "domestic",
"product_name": "抖音",
"country_name": "中国",
"phone": "13800138000",
"price": 1.50,
"status": "PENDING",
"status_text": "等待短信",
"sms_code": null,
"expires_at": "2026-11-02 17:20:04",
"created_at": "2026-11-02 17:17:04"
} } }
GET /open/v1/orders/{订单号}
参数:sync=1 表示顺手去上游拉一次最新短信(会慢 1–20 秒,轮询时建议带上)。
收到短信后:
{ "ok": true, "data": { "order": {
"order_no": "HY26110286682455593471",
"status": "RECEIVED",
"status_text": "已收到短信",
"sms_code": "317413",
"sms_text": "【抖音】验证码 317413,5分钟内有效",
"sms_sender": "抖音",
"sms_at": "2026-11-02 17:18:22"
} } }
order_no → 每 3–5 秒 GET /open/v1/orders/{no}?sync=1 →
拿到 status=RECEIVED 就把 sms_code 交给业务 → 用完调 finish 释放号码。
超时(TIMEOUT)会自动退款,不用你管;想提前结束就调 cancel。
订单状态
| status | 含义 | 下一步 |
|---|---|---|
PENDING | 等待短信 | 继续轮询 |
PROVISIONING | 正在出号 | 继续轮询 |
RECEIVED | 已收到短信 | 取 sms_code,然后 finish |
FINISHED | 已完成 | 结束 |
TIMEOUT | 超时,已退款 | 重新下单 |
CANCELED | 已取消,已退款 | 结束 |
FAILED | 出号失败,已退款 | 换线路重试 |
BANNED | 号码被封 | 换线路重试 |
产品订单(卡密)
产品订单没有「等短信」,下单后状态是 PENDING(发货中),发货完成后变成 FINISHED,
卡密在 cards 数组里:
{ "ok": true, "data": { "order": {
"order_no": "HY...", "status": "FINISHED", "status_text": "已发货",
"cards": ["账号----密码----备注"]
} } }
7. 错误码
| code | HTTP | 说明 / 怎么处理 |
|---|---|---|
unauthorized | 401 | 少了认证头 |
invalid_key | 401 | Key 不存在或已删除 |
key_disabled | 403 | Key 被停用,去后台开启 |
ip_not_allowed | 403 | IP 不在白名单里 |
bad_signature | 401 | 签名不对,对照第 3 节重拼 |
timestamp_expired | 401 | 时间偏差超过 5 分钟 |
nonce_reused | 409 | nonce 重复,重试要用新随机值 |
rate_limited | 429 | 超过每分钟上限,等一会儿 |
insufficient_balance | 402 | 余额不足,先充值 |
sold_out / no_offers | 409 | 线路售罄,换国家或运营商 |
keyword_required | 422 | 国内通道必须传 keyword |
invalid_phone | 422 | 指定号码不是合法 11 位手机号 |
bad_status | 409 | 当前状态不能做这个操作(比如已收码还想取消) |
not_found | 404 | 订单号不存在,或不是你的订单 |
maintenance | 503 | 站点维护中,稍后重试 |
8. 限流与安全
- 限流:每个 Key 默认 120 次/分钟(创建时可改,10–3000)。超了返回
429 rate_limited。 - 防重放:时间戳 ±5 分钟 + nonce 唯一,抓包重发也没用。
- IP 白名单:强烈建议填你服务器的出口 IP,Key 泄露了别人也用不了。
- Key 数量:每个账号最多 10 个,可以按业务分开建(比如一个查价、一个下单)。
- 调用日志:最近 30 条在「活动 → 开放 API」里能看,包括状态码、耗时、IP。
- secret 存储:服务器只保存加密后的值,任何人(包括我们)都看不到明文,丢了只能重建。
9. 常见问题
Q:能不能用回调(webhook)通知我收到短信?
当前版本请用轮询:GET /open/v1/orders/{no}?sync=1,间隔 3–5 秒。回调后续会加。
Q:一次能下多少单?
接口本身不限单量,但同一个人 1 分钟内最多下 10 单(防脚本刷单),超了返回 too_many_orders。
Q:价格在哪看?会不会和网页不一样?
完全一样,都走同一套计价。/offers 给的是实时价格,下单时按当时价格扣费。
如果你在号屿有会员等级,接口返回的价格和实际扣款都已经按你的等级折扣算过,
不需要自己再乘折扣;/offers 里的 price_original 是折扣前的原价,
方便你对照。等级按累计充值自动升级,也可以联系站长单独设置。
Q:取消一定退款吗?
没收到短信的订单取消全额退款(立即到余额);已经收到短信的不能取消。产品类卡密订单发货后不支持自助取消。
Q:国内通道的 keyword 填什么?
短信里【】中间那个词,比如收到「【抖音】验证码 123456」就填 抖音。填错收不到码,超时会自动退款。
号屿 HAOYU · 开放 API v1 · 接口如有调整会提前在站点公告里通知