网关 API
WeAppDev 在设备上启动一个本地网关(默认 0.0.0.0:9400),同时提供:
- CDP:Chrome DevTools 直接接逻辑层/渲染层
- REST:小程序、网络、重写、Native、插件、调试器、渲染、配置
- WebSocket:插件总线、CDP、实时事件
同一个端口既能给浏览器 DevTools 用,也能给脚本/自动化/插件用。
连接与约定
bash
# USB 转发(推荐)
adb forward tcp:9400 tcp:9400
curl http://127.0.0.1:9400/v1/status- 默认绑定
0.0.0.0,同局域网可直接访问http://<设备IP>:9400;只想本机访问可在设置里改为127.0.0.1 - 请求/响应均为 UTF-8 JSON
- 成功:
{"ok":true, ...};失败:{"ok":false,"error":"<code>","message":"<可读>"} - 常用错误码:
bad_request·not_found·logic_unavailable·render_unavailable·not_implemented·E_HASH
1. 发现与 CDP
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/status | 运行状态、钩子健康度、进程信息 |
| GET | /v1/hooks | 各调试钩子是否就绪 |
| GET | /v1/routes | 网关自描述接口目录 |
| GET | /json/version | CDP 协议版本 |
| GET | /json/list | 当前 target(逻辑层 + 渲染层) |
| WS | /devtools/appservice | 逻辑层 CDP |
| WS | /devtools/page/<id> | 渲染层 CDP |
bash
curl http://127.0.0.1:9400/json/listtext
devtools://devtools/bundled/js_app.html?ws=127.0.0.1:9400/devtools/appservice2. 小程序生命周期
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/apps | 当前进程内的小程序 |
| POST | /v1/apps/open | 打开小程序 {appId, username?, path?} |
| GET | /v1/recent | 最近使用列表 |
| POST | /v1/apps/{id}:close | 关闭 |
| POST | /v1/apps/{id}:restart | 重启 |
| POST | /v1/apps/{id}/eval | 逻辑层执行 JS {expression} |
| GET | /v1/apps/{id}/storage | 读 storage |
| POST | /v1/apps/{id}/storage | 写 storage {key,value} |
| GET | /v1/apps/{id}/info | 当前页面/路由等运行信息 |
bash
curl -X POST http://127.0.0.1:9400/v1/apps/open \
-H 'content-type: application/json' \
-d '{"appId":"wx…","path":"pages/index/index"}'
curl -X POST http://127.0.0.1:9400/v1/apps/wx…/eval \
-H 'content-type: application/json' \
-d '{"expression":"getCurrentPages().length"}'3. 网络捕获
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/net/store?tail=N | 逻辑层 wx.request 记录 |
| GET | /v1/net/body?id= | 取单条请求/响应体 |
| POST | /v1/net/replay | 重放请求 |
| GET | /v1/hook/store?tail=N | Cronet 边界记录(含 WebSocket) |
| GET | /v1/hook/body?id= | 取 hook 记录体 |
| POST | /v1/hook/clear | 清空 hook 记录 |
bash
curl 'http://127.0.0.1:9400/v1/hook/store?tail=20'记录字段通常包含 id / url / method / status / headers / body / at;二进制体以 Base64 + *B64 标记。
4. 网络重写与脚本
声明式规则
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/rewrite/rules | 规则列表 |
| POST | /v1/rewrite/rules | 新增/更新规则 |
| DELETE | /v1/rewrite/rules?id= | 删除规则 |
| POST | /v1/rewrite/clear | 清空规则 |
bash
curl -X POST http://127.0.0.1:9400/v1/rewrite/rules \
-H 'content-type: application/json' \
-d '{
"name":"mock vip",
"match":{"url":"contains:/api/vip/check","method":"GET"},
"response":{"setStatus":200,"setBody":"{\"code\":0,\"vip\":true}"}
}'JS 脚本
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/rewrite/scripts | 脚本列表 |
| POST | /v1/rewrite/scripts | 新增/更新脚本 |
| DELETE | /v1/rewrite/scripts?id= | 删除脚本 |
脚本契约为 onRequest(req) / onResponse(resp),详见 免插件 · 网络脚本。
5. Native(mmtls / ilink)
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/native/store?tail=N&api= | Native 记录(请求/响应/凭据) |
| GET | /v1/native/creds | 已捕获的云网关 key/token(APP 内存,30 分钟过期) |
| POST | /v1/native/clear | 清空记录 |
| GET/POST | /v1/native/capture | 捕获开关(只影响 UI,不影响插件回调) |
bash
curl 'http://127.0.0.1:9400/v1/native/store?tail=50'
curl http://127.0.0.1:9400/v1/native/credsNative 记录覆盖云网关、云托管、云容器等不走 HTTP 的 mmtls/ilink 交互;单条 body 上限 96KB,超出会带 truncated:true。
6. 插件
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/plugins | 已安装插件列表 |
| POST | /v1/plugins/install | 安装 HTML / zip |
| POST | /v1/plugins/install-url | 从 URL 安装 {url,sha256,exportable,market} |
| GET | /v1/plugins/{id} | 插件详情 |
| POST | /v1/plugins/{id}/enable / disable | 启停 |
| POST | /v1/plugins/{id}/appids | 限定生效的 appid |
| GET | /v1/plugins/{id}/export | 导出分享(非加密) |
| DELETE | /v1/plugins/{id} | 卸载 |
| GET/POST | /v1/plugins/global | 插件功能总开关 |
| GET | /v1/plugins/market | 市场列表 |
| GET | /v1/plugins/state | 泵/注入/上下文诊断 |
| WS | /v1/plugins/bus?plugin=&appid= | 插件面板总线 RPC |
bash
curl http://127.0.0.1:9400/v1/plugins
curl -X POST http://127.0.0.1:9400/v1/plugins/global \
-H 'content-type: application/json' -d '{"enabled":true}'7. 调试器
| Method | Path | 说明 |
|---|---|---|
| POST | /v1/debugger/enable | 开启调试 |
| GET | /v1/debugger/status | 状态 |
| POST | /v1/debugger/break | 行断点 {url,line,column,condition,action,maxHits} |
| POST | /v1/debugger/break-script | 按 scriptId 下断点 |
| POST | /v1/debugger/break-fn | 函数断点 |
| POST | /v1/debugger/unbreak | 删除断点 |
| POST | /v1/debugger/clear-breaks | 清空断点 |
| POST | /v1/debugger/paused | 等待/查询暂停 {wait} |
| POST | /v1/debugger/eval | 帧内求值 {frameId,expression} |
| POST | /v1/debugger/eval-global | 全局求值 |
| POST | /v1/debugger/step | over/into/out/resume |
| GET | /v1/debugger/scope | 作用域变量 |
| GET | /v1/debugger/scripts | 脚本列表 |
| POST | /v1/debugger/source | 源码 |
| GET | /v1/debugger/action-log | 动作断点执行记录 |
| POST | /v1/debugger/netbreak | 网络断点 |
| GET | /v1/debugger/net-hit | 网络断点命中 |
| POST | /v1/debugger/netbreak-clear | 清空网络断点 |
| POST | /v1/debugger/cdp | 直接转发任意 CDP 方法 |
bash
curl -X POST http://127.0.0.1:9400/v1/debugger/break \
-H 'content-type: application/json' \
-d '{"url":"usr/app.js","line":100,"action":"this.debug=1"}'8. 渲染层
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/render/targets?appid= | 渲染层 target |
| POST | /v1/render/eval | 页面内求值 {appid,expression} |
| POST | /v1/render/screenshot | 截图 {appid,upload?} |
| POST | /v1/render/dom | DOM 快照 {appid,tree?,upload?} |
bash
curl -X POST http://127.0.0.1:9400/v1/render/eval \
-H 'content-type: application/json' \
-d '{"expression":"document.title"}'9. 配置、日志与上传
| Method | Path | 说明 |
|---|---|---|
| GET | /v1/config | 网关配置与开关 |
| POST | /v1/config | 修改配置 |
| GET | /v1/logs?tail=N | 宿主日志 |
| POST | /v1/logs/clear | 清空日志 |
| POST | /v1/upload | 宿主直传文件到外部 URL |
| POST | /v1/ui/theme | 切换主题 |
| GET | /v1/ui/panel-pending | 取走深链面板目标 |
bash
curl -X POST http://127.0.0.1:9400/v1/upload \
-H 'content-type: application/json' \
-d '{"url":"http://127.0.0.1:9000/shot","body":"...","contentType":"text/plain"}'安全边界
- 网关默认只应在可信网络使用;不需要局域网访问时改为
127.0.0.1 - 插件内部请求带
ignore_wmpf_network_debug=1,不会进入网络记录,也不会被自己的规则改写 - 导出只对非加密插件开放;市场加密插件不落明文