为什么会有这篇文章
刚开始一直在用SmsFordarder在安卓手机上进行短信转发,长期占用安卓手机,老化的电池也不放心,咸鱼发现有便宜可用的支持短信的4g模块,顺带研究一下相关的内容,就自己用golang写了相关服务。
我自己的硬件配置
主板 | orange pi5 max | 很不错的板子,我在上面跑frigate、jellyfin 能解码,能跑图像识别。 |
cpu | rk3588 | x86和arm64都可以 |
系统 | ubuntu server22.04 | 因为还在跑redroid,需要5.10内核,所有没用24.04系统 |
4g模块 | 移远的EC200T-CN | 咸鱼10块钱,cat4速率,但是我不需要用它上网,便宜,有短信,有通话接口就行。 |
usb转4g板子 | 咸鱼搜 mini pcie转4g模块 | 20块钱 |
天线 | 2根 | IPEX一代接口 |
sim卡信息 | 中国联通 | 没其他卡,没测试移动和电信 |
软件配置
- docker就行了。
- 相关代码:
- 我用golang写的一份读取短信和来电的服务gammu-web
- 配合golang的通知服务ForwardSMS
准备转发配置文件forward.yaml
# 如果有all这个配置,就是默认所有短信都会转发给这个企业微信机器人,建议发送给管理员,或者直接删除关闭
all:
rule: all
type: all
notify: wechat
url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx
# 从上到下依次为 项目名称、规则(使用关键字匹配)
测试:
rule: 测试DDD
type: keyword
notify: wechat
url: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx
# 正则匹配规则
工单号:
rule: "\\d{8}" # 匹配8位数字
type: regex
notify: gotify
url: https://gotify.example.com
token: your_app_token
# 转发给ios用它。
bark:
notify: bark
type: all
rule: all
url: "https://api.day.app/xxxx"
# 转发给安卓用它。
gtify:
notify: gotify
type: all
rule: all
url: "https://gotify.example.com"
token: "your_app_token"
# emm邮箱转发
email:
notify: email
type: all
rule: all
smtp_host: "smtp.qq.com"
smtp_port: "587"
username: "[email protected]"
password: "授权码"
from: "[email protected]"
to: "[email protected]"
配置docker-compose.yaml (支持x86和arm64)
version: "3"
services:
# https://github.com/scjtqs2/ForwardSMS
forwardsms:
image: ghcr.io/scjtqs2/forwardsms/forwardsms:latest
environment:
- FORWARD_SECRET=your_shared_secret_here
- TZ=Asia/Shanghai
- HTTP_PORT=8080
volumes:
# 挂载上面配置的推送文件
- ./forward.yaml:/data/config/forward.yaml
restart: always
expose:
- 8080
# https://github.com/scjtqs2/gammu-web
gammu-web:
image: ghcr.io/scjtqs2/gammu-web:latest
environment:
- FORWARD_ENABLED=1
# 写死
- FORWARD_URL=http://forwardsms:8080/api/v1/sms/receive
# 和forwardsms里面的要一致。
- FORWARD_SECRET=your_shared_secret_here
- TZ=Asia/Shanghai
# 转发通知携带的标识。
- PHONE_ID=SMS1_186xxxxxxxx
- ATCONNECTION=at9600
# ec200t-cn 默认的管理接口就是/dev/ttyUSB1(能同时收发短信,还能读取来电显示数据用来达到转发来电通知)。根据实际情况自行调整。
- USB_PORT=/dev/ttyUSB1
- API_PORT=21234
# web网页访问用到。
- API_TOKEN=your_shared_token_here
- GAMMU_DEBUG=false
- DEBUG=0
- CALL_FORWARD_ENABLED=true
- CALL_FORWARD_URL=http://forwardsms:8080/api/v1/call/receive
volumes:
- ./data:/data
# 加了这个,就不用挨个去映射 /dev/ttyUSBx了
privileged: true
restart: always
ports:
- 21234:21234