feat: 初始化Node.js 4G短信网关项目
- 实现AT指令通信和4G模组管理 - 支持PDU模式短信接收和发送 - 长短信自动合并功能 - 多通道推送支持(钉钉/飞书/Telegram等) - 管理员短信远程控制 - RESTful API接口 - 完整的日志系统
This commit is contained in:
@@ -0,0 +1,211 @@
|
||||
# Node.js 4G SMS Gateway
|
||||
|
||||
基于Node.js的4G短信网关,通过串口与4G模块通信,接收短信并转发到多种推送渠道。
|
||||
|
||||
## 功能特性
|
||||
|
||||
- ✅ 4G模块AT指令交互
|
||||
- ✅ 自动接收短信(PDU模式)
|
||||
- ✅ 长短信自动合并
|
||||
- ✅ 多通道推送(邮件/钉钉/飞书/Telegram等)
|
||||
- ✅ 短信发送功能
|
||||
- ✅ 号码黑名单
|
||||
- ✅ 管理员远程命令
|
||||
- ✅ RESTful API接口
|
||||
- ✅ Web管理界面
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Node.js >= 18.x
|
||||
- 4G模块通过USB转串口连接到服务器
|
||||
- 支持的4G模块:ML307R-DC、SIM7600等AT指令兼容模块
|
||||
|
||||
## 安装
|
||||
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
## 配置
|
||||
|
||||
复制配置模板:
|
||||
```bash
|
||||
cp config.example.json config.json
|
||||
```
|
||||
|
||||
编辑 `config.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"serial": {
|
||||
"path": "/dev/ttyUSB0",
|
||||
"baudRate": 115200
|
||||
},
|
||||
"smtp": {
|
||||
"server": "smtp.qq.com",
|
||||
"port": 465,
|
||||
"user": "your@qq.com",
|
||||
"pass": "your_auth_code",
|
||||
"sendTo": "recipient@example.com"
|
||||
},
|
||||
"adminPhone": "13800138000",
|
||||
"numberBlackList": [],
|
||||
"pushChannels": [
|
||||
{
|
||||
"enabled": true,
|
||||
"type": "dingtalk",
|
||||
"name": "钉钉通知",
|
||||
"url": "https://oapi.dingtalk.com/robot/send?access_token=xxx",
|
||||
"secret": "SECxxx"
|
||||
}
|
||||
],
|
||||
"api": {
|
||||
"port": 3000,
|
||||
"auth": {
|
||||
"username": "admin",
|
||||
"password": "admin123"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 运行
|
||||
|
||||
### 开发模式
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
|
||||
### 生产模式
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
### 使用PM2(推荐)
|
||||
```bash
|
||||
pm2 start ecosystem.config.js
|
||||
pm2 save
|
||||
pm2 startup
|
||||
```
|
||||
|
||||
## API接口
|
||||
|
||||
### 查询状态
|
||||
```bash
|
||||
GET /api/status
|
||||
```
|
||||
|
||||
### 发送短信
|
||||
```bash
|
||||
POST /api/sms/send
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"phone": "13800138000",
|
||||
"message": "测试短信"
|
||||
}
|
||||
```
|
||||
|
||||
### 查询信号强度
|
||||
```bash
|
||||
GET /api/modem/signal
|
||||
```
|
||||
|
||||
### 查询模组信息
|
||||
```bash
|
||||
GET /api/modem/info
|
||||
```
|
||||
|
||||
### 发送AT命令
|
||||
```bash
|
||||
POST /api/modem/at
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"command": "AT+CSQ"
|
||||
}
|
||||
```
|
||||
|
||||
### 获取日志
|
||||
```bash
|
||||
GET /api/logs
|
||||
```
|
||||
|
||||
所有API均需要HTTP Basic认证。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
.
|
||||
├── src/
|
||||
│ ├── index.js # 入口文件
|
||||
│ ├── modem.js # 4G模块通信
|
||||
│ ├── sms.js # 短信处理
|
||||
│ ├── push.js # 推送通道
|
||||
│ ├── concat.js # 长短信合并
|
||||
│ ├── api.js # REST API
|
||||
│ └── logger.js # 日志系统
|
||||
├── config.json # 配置文件
|
||||
├── package.json
|
||||
└── README.md
|
||||
```
|
||||
|
||||
## 推送通道类型
|
||||
|
||||
| 类型 | type值 | 配置项 |
|
||||
|------|--------|--------|
|
||||
| 钉钉机器人 | `dingtalk` | url, secret(可选) |
|
||||
| 飞书机器人 | `feishu` | url, secret(可选) |
|
||||
| Telegram Bot | `telegram` | url(bot token), key1(chat_id) |
|
||||
| PushPlus | `pushplus` | key1(token) |
|
||||
| Server酱 | `serverchan` | key1(sendkey) |
|
||||
| Bark | `bark` | url(bark服务器) |
|
||||
| POST JSON | `post_json` | url |
|
||||
| GET请求 | `get` | url |
|
||||
| 自定义模板 | `custom` | url, customBody |
|
||||
|
||||
## 管理员命令
|
||||
|
||||
通过短信发送命令(仅管理员号码):
|
||||
|
||||
### 远程发送短信
|
||||
```
|
||||
SMS:目标号码:短信内容
|
||||
```
|
||||
示例:`SMS:13800138000:测试消息`
|
||||
|
||||
### 重启系统
|
||||
```
|
||||
RESET
|
||||
```
|
||||
|
||||
## 长短信处理
|
||||
|
||||
- 自动检测长短信(分段数 > 1)
|
||||
- 使用参考号和发送者号码标识同一条长短信
|
||||
- 收齐所有分段后自动合并
|
||||
- 30秒超时保护(未收齐也转发)
|
||||
|
||||
## 故障排查
|
||||
|
||||
### 串口打不开
|
||||
```bash
|
||||
# Linux检查串口设备
|
||||
ls -l /dev/ttyUSB*
|
||||
# 添加用户到dialout组
|
||||
sudo usermod -a -G dialout $USER
|
||||
```
|
||||
|
||||
### 模块不响应
|
||||
- 检查串口路径和波特率
|
||||
- 检查USB连接
|
||||
- 检查SIM卡是否插好
|
||||
|
||||
### 收不到短信
|
||||
- 检查AT+CEREG?网络注册状态
|
||||
- 检查AT+CNMI配置是否正确
|
||||
- 检查SIM卡余额和服务状态
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT
|
||||
Reference in New Issue
Block a user