Files
iotlcm/README.md
T
MiFaZhan 4e2cd43a55 chore: 初始开源发布
iotlcm-onelink-mock:OneLink 挡板服务(本地测试替身)。

- Go module 迁移至 git.5iot.com/iotlcm-public/iotlcm-onelink-mock
- 修复同毫秒内多次生成卡导致 ICCID/IMSI 唯一约束冲突
- 补 Apache-2.0 LICENSE,README 重写并新增 docs/deploy.md
- 移除内部部署资产(CI 触发器 / 镜像推送脚本 / 指定环境部署文档)
- 测试凭据改为 demo_appid / demo_password,真实手机号与内网 IP 脱敏
- 统一 LF 行尾并加 .gitattributes
2026-10-22 15:08:27 +08:00

249 lines
5.9 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.
# iotlcm-onelink-mock
OneLink 挡板服务 —— 基于《中移物联网物联卡能力开放调用参考文档 V26.01.1》实现的本地测试替身。
用于在没有真实运营商环境时,模拟中国移动 OneLink 的鉴权与卡查询接口,支撑联调、自测与 CI。
## 功能
- 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 数据库作为唯一持久化数据源。默认数据库路径:
```text
data/onelink_mock.db
```
可以通过环境变量覆盖:
```text
BAFFLE_SQLITE_PATH=C:\sqlite\onelink_mock.db
```
后端通过 GoFrame SQLite 驱动直接访问数据库,不依赖本机安装 `sqlite3` 命令行工具。
Docker 镜像内会安装 `sqlite` 命令行工具。
## 一键生成
管理台顶部可输入生成数量,点击“一键生成”后追加新卡数据。
生成逻辑:
- 不删除旧卡。
- 不查询旧卡做重复对比。
- ICCID/MSISDN/IMSI/IMEI 与生成时间戳和序号相关,降低重复概率。
- 删除卡只在管理台删卡或业务删除逻辑触发时发生。
固定生成值:
```text
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=
```
流量固定值:
```text
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”会下载当前卡数据,表头顺序为:
```text
ICCID
MSISDN
IMSI
IMEI
通道编号
卡类型
上游套餐编码
供应商编码
上游激活时间
是否贴片转插拔
是否运营商达量断网
协议到期时间
是否有测试期
测试期天数
测试期最晚过期日期
是否有沉默期
沉默期天数
沉默期最晚过期日期
```
其中:
- `协议到期时间` 为激活日期后 1 年。
- `测试期最晚过期日期` 为激活日期后 30 天。
- `是否有沉默期=false` 时,沉默期天数和截止日期导出为空。
## 已实现接口
- `ec/get/token`
- `ec/query/sim-basic-info`
- `ec/query/sim-session`
- `ec/query/sim-status`
- `ec/query/sim-stop-reason`
- `ec/query/sim-frozen-state-info`
- `ec/query/sim-apn-session-info`
- `ec/query/sim-activated-features-info`
- `ec/query/sim-operating-status`
- `ec/query/sim-data-diagnosis`
- `ec/query/sim-imei`
- `ec/query/sim-data-usage-inpool`
- `ec/query/sim-data-usage`
- `ec/query/sim-data-usage-monthly/batch`
- `ec/query/sim-data-usage-daily/batch`
- `ec/query/apn-info`
- `ec/query/card-bind-status`
- `ec/query/on-off-status`
- `ec/query/region-limit-status`
- `ec/change/sim-status`
- `ec/operate/sim-apn-function`
Chan-compatible unified APIs (GET and POST):
- `GET|POST /sim/query/sim-basic-info`
- `GET|POST /sim/query/sim-session`
- `GET|POST /sim/query/sim-status`
- `GET|POST /sim/query/sim-status-batch`
- `GET|POST /sim/query/sim-card-bind-status`
- `GET|POST /sim/query/sim-device-status`
- `GET|POST /sim/query/sim-region-limit-status`
- `GET|POST /sim/query/sim-imei`
- `GET|POST /sim/query/sim-datausage`
- `GET|POST /sim/query/sim-datausage-monthly`
- `GET|POST /sim/query/sim-datausage-monthly-batch`
- `GET|POST /sim/query/sim-datausage-daily`
- `GET|POST /sim/query/sim-datausage-daily-batch`
- `GET|POST /sim/query/sim-apn-info`
- `GET|POST /sim/change/sim-status`
- `GET|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/state`
- `POST /api/generate`
- `GET /api/cards/export`
- `POST /api/appids`
- `POST /api/cards`
- `DELETE /api/cards`
## 环境变量
| 变量 | 必填 | 说明 |
| --- | --- | --- |
| `BAFFLE_ADDR` | 否 | 监听地址,默认 `:8080` |
| `BAFFLE_SQLITE_PATH` | 否 | SQLite 数据库路径,默认 `data/onelink_mock.db` |
## 本地启动
### 1. 启动后端
PowerShell:
```powershell
$env:BAFFLE_ADDR=":8080"
$env:BAFFLE_SQLITE_PATH="C:\sqlite\onelink_mock.db"
go run .
```
后端默认监听:
```text
http://127.0.0.1:8080
```
### 2. 启动前端
```powershell
cd frontend
pnpm install --frozen-lockfile
pnpm run dev
```
前端 dev server 默认监听:
```text
http://127.0.0.1:5173/
```
## Docker 启动
```powershell
docker compose up -d --build
```
访问地址:
```text
http://127.0.0.1:18080/onelink-mock/
```
停止:
```powershell
docker compose down
```
## 默认测试认证
```text
appid=demo_appid
password=demo_password
```
获取 Token:
```text
http://localhost:8080/v5/ec/get/token?appid=demo_appid&password=demo_password&transid=demo_appid2026070209300000000001
```
## Admin query APIs
```text
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.
## 部署
本地开发用 `docker compose up -d --build` 即可(见上文「Docker 启动」)。若需要通过 Nginx 以子路径方式挂到已有站点,参考 [`docs/deploy.md`](./docs/deploy.md)。
## 相关项目
本服务是 [iotlcm](https://git.5iot.com/iotlcm-public) 物联网卡全生命周期管理平台的一部分,用于在没有真实运营商通道时提供可预期的上游替身。
## License
[Apache License 2.0](./LICENSE)