5299c13c1a085b49951b7e4c3e67890240436af1
OneLink 挡板服务
基于《中移物联网物联卡能力开放调用参考文档 V26.01.1》实现的本地挡板服务。
功能
- Go 后端,兼容
/v5/ec/...和/ec/...两种路径。 - Vue3 管理台,管理多个
appid/password、SIM 卡基础信息、状态和固定流量参数。 - Token 有效期 3600 秒,支持
refresh=0/1。 - 不再连接 MySQL,也不再查询
t_sim_card_info。 - SIM 卡数据由后端一键生成,持久化到本地 SQLite 表
mock_t_sim_card。 - 月流量固定为
18432 KB,不再按时间自动增长。 - 支持按入库模板导出 Excel。
数据源
服务使用 SQLite 数据库作为唯一持久化数据源。默认数据库路径:
data/onelink_mock.db
可以通过环境变量覆盖:
BAFFLE_SQLITE_PATH=C:\sqlite\onelink_mock.db
后端通过 GoFrame SQLite 驱动直接访问数据库,不依赖本机安装 sqlite3 命令行工具。
Docker 镜像内会安装 sqlite 命令行工具。
一键生成
管理台顶部可输入生成数量,点击“一键生成”后追加新卡数据。
生成逻辑:
- 不删除旧卡。
- 不查询旧卡做重复对比。
- ICCID/MSISDN/IMSI/IMEI 与生成时间戳和序号相关,降低重复概率。
- 删除卡只在管理台删卡或业务删除逻辑触发时发生。
固定生成值:
chanKey=channel_yd_mock
cardType=1
upPkgCode=CMIOT-SD-500M-24M-D01
suppliersCode=SUP_CMCC
insertToPlugEnabled=true
carrierTrafficCutoffEnabled=false
hasTestPeriod=true
testPeriodDays=30
hasSilentPeriod=false
silentPeriodDays=
silentPeriodLatestExpiryDate=
流量固定值:
current_month_usage_kb=18432
monthly_usage_kb=18432
daily_usage_kb=614.4
pool_usage_bytes=18874368
growth_per_minute_kb=0
auto_growth_enabled=false
Excel 导出
管理台点击“导出 Excel”会下载当前卡数据,表头顺序为:
ICCID
MSISDN
IMSI
IMEI
通道编号
卡类型
上游套餐编码
供应商编码
上游激活时间
是否贴片转插拔
是否运营商达量断网
协议到期时间
是否有测试期
测试期天数
测试期最晚过期日期
是否有沉默期
沉默期天数
沉默期最晚过期日期
其中:
协议到期时间为激活日期后 1 年。测试期最晚过期日期为激活日期后 30 天。是否有沉默期=false时,沉默期天数和截止日期导出为空。
已实现接口
ec/get/tokenec/query/sim-basic-infoec/query/sim-sessionec/query/sim-statusec/query/sim-stop-reasonec/query/sim-frozen-state-infoec/query/sim-apn-session-infoec/query/sim-activated-features-infoec/query/sim-operating-statusec/query/sim-data-diagnosisec/query/sim-imeiec/query/sim-data-usage-inpoolec/query/sim-data-usageec/query/sim-data-usage-monthly/batchec/query/sim-data-usage-daily/batchec/query/apn-infoec/query/card-bind-statusec/query/on-off-statusec/query/region-limit-statusec/change/sim-statusec/operate/sim-apn-function
Chan-compatible unified APIs (GET and POST):
GET|POST /sim/query/sim-basic-infoGET|POST /sim/query/sim-sessionGET|POST /sim/query/sim-statusGET|POST /sim/query/sim-status-batchGET|POST /sim/query/sim-card-bind-statusGET|POST /sim/query/sim-device-statusGET|POST /sim/query/sim-region-limit-statusGET|POST /sim/query/sim-imeiGET|POST /sim/query/sim-datausageGET|POST /sim/query/sim-datausage-monthlyGET|POST /sim/query/sim-datausage-monthly-batchGET|POST /sim/query/sim-datausage-dailyGET|POST /sim/query/sim-datausage-daily-batchGET|POST /sim/query/sim-apn-infoGET|POST /sim/change/sim-statusGET|POST /sim/change/sim-apn
Chan requests use simKeys and reqData; responses are per-SIM arrays with
code, message, simKey, and resData. The chan endpoints reuse the same
SQLite SIM cards as the OneLink endpoints.
管理接口:
GET /api/statePOST /api/generateGET /api/cards/exportPOST /api/appidsPOST /api/cardsDELETE /api/cards
环境变量
| 变量 | 必填 | 说明 |
|---|---|---|
BAFFLE_ADDR |
否 | 监听地址,默认 :8080 |
BAFFLE_SQLITE_PATH |
否 | SQLite 数据库路径,默认 data/onelink_mock.db |
本地启动
1. 启动后端
PowerShell:
$env:BAFFLE_ADDR=":8080"
$env:BAFFLE_SQLITE_PATH="C:\sqlite\onelink_mock.db"
go run .
后端默认监听:
http://127.0.0.1:8080
2. 启动前端
cd frontend
pnpm install --frozen-lockfile
pnpm run dev
前端 dev server 默认监听:
http://127.0.0.1:5173/
Docker 启动
docker compose up -d --build
访问地址:
http://127.0.0.1:18080/onelink-mock/
停止:
docker compose down
默认测试认证
appid=demo_appid
password=demo_password
获取 Token:
http://localhost:8080/v5/ec/get/token?appid=demo_appid&password=demo_password&transid=demo_appid2026070209300000000001
Admin query APIs
GET /api/cards?keyword=<msisdn-or-iccid-or-imsi>&page=1&pageSize=20
GET /api/orders?page=1&pageSize=20
Orders are persisted in the SQLite mock_order table and retain all nine fields after a service restart. Existing mock_t_sim_card data is preserved.
Description
Languages
Go
69.4%
Vue
15.2%
TypeScript
12%
PLpgSQL
2.4%
JavaScript
0.4%
Other
0.3%