opencli-plugin-12306 是一个面向 OpenCLI 的 12306 查询插件,支持站点编码查询、直达余票查询、中转余票查询、车次经停站查询。
来源说明:本插件的核心业务思路与 12306 接口对接逻辑,参考并迁移自项目: https://github.com/Joooook/12306-mcp
opencli plugin install github:Hwenyi/opencli-plugin-12306或:
opencli plugin install https://github.com/Hwenyi/opencli-plugin-12306安装后建议重新打开一个终端,或者重新执行一次 opencli 命令,确保插件被重新发现。
将本仓库放到:
~/.opencli/plugins/12306/然后直接执行命令进行调试。
所有命令都支持输出格式:
-f table(默认)-f json-f yaml-f md-f csv
opencli 12306 station-code --query "北京|上海虹桥|BJP"用途:把城市名 / 站名 / 站点编码统一解析成标准站点信息。
参数:
--query:必填;支持|分隔多个查询词。
返回字段:query, station_name, station_code, city
opencli 12306 stations-code-in-city --city 北京 -f json用途:查询“一个城市下所有车站”。
参数:
--city:必填;中文城市名,例如北京、上海。
返回字段:city, station_name, station_code
opencli 12306 station-code-of-citys --citys "北京|上海|杭州" -f json用途:为城市名快速匹配代表站(如北京 -> BJP)。
参数:
--citys:必填;多个城市用|分隔。
返回字段:query, city, station_name, station_code, error
opencli 12306 station-code-by-names --names "北京南|上海虹桥|杭州东" -f json用途:输入具体车站名,获取标准站点编码。
参数:
--names:必填;多个站名用|分隔。
返回字段:query, city, station_name, station_code, error
opencli 12306 station-by-telecode --telecode BJP -f yaml用途:已知 3 位编码时,获取完整站点信息。
参数:
--telecode:必填;站点编码,如BJP。
返回字段(示例):station_name, station_code, city, station_pinyin, station_short, station_id 等。
opencli 12306 tickets \
--date 2026-03-21 \
--from 北京 \
--to 上海 \
--train_filter_flags G \
--earliest_start_time 6 \
--latest_start_time 12 \
--sort_flag duration \
--limit 5 \
-f json用途:查询 A 到 B 的直达车次余票。
核心参数:
--date:必填,格式YYYY-MM-DD--from:必填,出发站/城市/编码--to:必填,到达站/城市/编码--limit:返回数量上限,0表示不限制--train_type:单前缀过滤(如G)--train_filter_flags:多标志过滤,支持GDZTKOFS--earliest_start_time/--latest_start_time:出发小时窗口(0-24)--sort_flag:startTime | arriveTime | duration--sort_reverse:是否反向排序
返回字段:train_code, from, to, start_date, start_time, arrive_date, arrive_time, duration, swz, zy, ze, rw, yw, yz, wz
opencli 12306 interline-tickets \
--date 2026-03-21 \
--from 北京 \
--to 杭州 \
--middle 南京南 \
--show_wz true \
--sort_flag duration \
--limit 5 \
-f json用途:查询 A -> 中转 -> B 的换乘方案。
核心参数:
--date:必填,YYYY-MM-DD--from/--to:必填--middle:可选,指定中转站--show_wz:是否显示无座方案--train_filter_flags:GDZTKOFS--earliest_start_time/--latest_start_time--sort_flag/--sort_reverse--limit
返回字段:start_time, arrive_time, duration, route, transfer, wait_time, first_train, second_train
opencli 12306 train-route-stations --train_code G1 --depart_date 2026-03-21 -f json用途:查询某一车次在指定日期的经停站序列。
参数:
--train_code:必填,例如G1、G1033--depart_date:必填,YYYY-MM-DD
返回字段:station_name, station_train_code, arrive_time, start_time, duration, arrive_day(首站可能额外返回车次基础信息)
- 参考项目:
Joooook/12306-mcp,本插件为该 MCP 的迁移