一个运行在 Android 手机上的轻量级 HTTP 短信网关,通过 Termux 环境调用 termux-sms-send 发送短信,对外暴露 RESTful API。
- HTTP API:通过简单的 POST 请求即可发送短信
- API Key 认证:使用常数时间比较,防止时序攻击
- SIM 卡槽选择:支持双卡手机指定发送卡槽
- 频率限制:
- 单号码发送间隔(默认 30 秒)
- 单号码每日上限(默认 10 条/天)
- 全局每日上限(所有号码合计)
- 跨平台编译:提供 Linux/macOS/Windows 编译脚本
- Android 手机,已安装 Termux 及 Termux:API 插件
- Go 1.21+(用于编译)
- 已授予 Termux 短信权限
编辑 config.json:
{
"apikey": "your-api-key-here",
"port": "8080",
"slot": "0",
"rate_limit_sec": 30,
"rate_limit_daily": 10,
"global_daily_limit": 100
}配置项说明:
| 配置项 | 类型 | 说明 |
|---|---|---|
apikey |
string | API 密钥,用于验证请求 |
port |
string | 监听端口 |
slot |
string | SIM 卡槽号。从 0 开始:卡 1 = "0",卡 2 = "1"。留空 "" 表示使用系统默认 |
rate_limit_sec |
int | 同一号码两次发送间的最小间隔(秒) |
rate_limit_daily |
int | 同一号码每天最大发送条数 |
global_daily_limit |
int | 全局每天最大发送条数(所有号码合计),0 表示不限制 |
关于 slot(卡槽):slot 编号从 0 开始:
"0"— SIM 卡 1"1"— SIM 卡 2留空则使用系统默认 SIM 卡。
在 PC 上交叉编译为 Android 可执行文件:
# Linux / macOS
./build.sh
# Windows
build.bat编译产物为 hu60sms,目标平台为 android/arm64。
将编译好的 hu60sms 二进制文件和 config.json 通过任意方式传输到手机,config.json 需与 hu60sms 可执行文件放在同一目录。
在手机 Termux 中,cd 到 hu60sms 所在目录,然后执行:
chmod +x ./hu60sms
./hu60sms服务启动后默认监听 :8080 端口。
请求:
POST /sms
Content-Type: application/x-www-form-urlencoded参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
apikey |
string | 是 | API 密钥,需与 config.json 中一致 |
mobile |
string | 是 | 目标手机号 |
text |
string | 是 | 短信内容 |
卡槽由服务端配置文件
slot字段统一指定,无需在请求中传递。
示例:
curl -X POST http://172.23.0.1:8080/sms \
-d "apikey=your-api-key-here&mobile=13800138000&text=您的验证码是123456"响应:
{"code": 200, "message": "SMS sent successfully"}错误响应:
| HTTP 状态码 | code | 说明 |
|---|---|---|
| 403 | 403 | API Key 无效 |
| 400 | 400 | 缺少必填参数 |
| 429 | 429 | 触发频率限制 |
| 500 | 500 | 短信发送失败 |
hu60sms/
├── main.go # 主程序(HTTP 服务 + 短信发送逻辑)
├── config.json # 配置文件
├── go.mod # Go 模块定义
├── build.sh # Linux/macOS 编译脚本
└── build.bat # Windows 编译脚本
MIT License