Files
SmsReceiver-go/README.md
2026-02-08 17:36:45 +08:00

166 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SmsReceiver-go
短信转发接收端 Go 版本 - 基于 Flask 版本的完整重写
## 功能特性
- ✅ 短信接收 API (支持 TranspondSms Android APP)
- ✅ 登录验证与会话管理
- ✅ 短信列表展示(分页、搜索、筛选)
- ✅ 统计信息(总数、今日、本周、签名验证)
- ✅ 接收日志查看
- ✅ 短信详情查看
- ✅ 时区转换Asia/Shanghai
- ✅ 签名验证HMAC-SHA256
- ✅ 多 Token 管理
## 技术栈
- **Web 框架**: Gorilla Mux
- **数据库**: SQLite3 (mattn/go-sqlite3)
- **模板引擎**: Go html/template
- **认证**: Cookie-based session
- **语言**: Go 1.23+
## 项目结构
```
SmsReceiver-go/
├── main.go # 入口文件
├── config.yaml # 配置文件
├── GO_REFACTOR_PROGRESS.md # 重构进度文档
├── auth/ # 认证模块
├── config/ # 配置加载
├── database/ # 数据库操作
├── handlers/ # HTTP 处理器
├── models/ # 数据模型
├── sign/ # 签名验证
├── static/ # 静态资源
└── templates/ # HTML 模板
```
## 快速开始
### 使用预编译二进制(推荐)
仓库已包含编译好的二进制文件 `sms-receiver-new`:
```bash
chmod +x sms-receiver-new
./sms-receiver-new
```
### 从源码编译
```bash
go build -o sms-receiver main.go
```
### 配置
编辑 `config.yaml`:
```yaml
server:
host: "0.0.0.0"
port: 28001
security:
enabled: true
username: "admin"
password: "admin123"
database:
path: "sms_receiver_go.db"
api_tokens:
- name: "默认配置"
token: "default_token"
secret: ""
enabled: true
```
### 运行
```bash
./sms-receiver
```
服务将运行在 `http://0.0.0.0:28001`
### 访问
- 短信列表: http://localhost:28001/
- 统计信息: http://localhost:28001/statistics
- 接收日志: http://localhost:28001/logs
默认登录账号:
- 用户名: `admin`
- 密码: `admin123`
## API 接口
### 接收短信
```bash
POST /api/receive
Content-Type: multipart/form-data
from=10086&content=测试短信&timestamp=1234567890&sign=xxx&token=your_token
```
### 获取消息列表
```bash
GET /api/messages?page=1&limit=20&from=&search=
```
需要登录认证
### 获取统计信息
```bash
GET /api/statistics
```
需要登录认证
## 数据库
独立使用 `sms_receiver_go.db`,包含以下表:
- `sms_messages`: 短信存储
- `receive_logs`: 接收日志
- `sqlite_sequence`: 自增序列
## 与 Python 版本对比
| 特性 | Python 版本 | Go 版本 |
|------|------------|---------|
| 运行方式 | Python 解释器 | 编译二进制 |
| 部署大小 | ~50KB (源码) | ~18MB (二进制, 已包含) |
| 启动速度 | ~100ms | ~10ms |
| 内存占用 | ~30MB | ~15MB |
| 并发处理 | GIL 限制 | 原生协程 |
| 数据库 | `sms_receiver.db` | `sms_receiver_go.db` |
## 重要说明
- 本版本与 Python 版本使用**独立的数据库文件**
- 数据不互通,属于完全独立的实现
- 功能已对齐 Python 版本所有核心特性
- 修复了模板渲染类型兼容性问题
## License
MIT License
## 更新日志
### v1.0.0 (2026-02-08)
- ✅ 初始版本发布
- ✅ 完整功能实现
- ✅ 修复模板类型兼容性问题
- ✅ 对齐 Python 版本功能