Files
baiyue-firstleg/docs/lingxing-browser-dev-test.md
T

51 lines
1.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.
# 领星浏览器登录态开发测试
开发服务器为 Ubuntu 22.04.5 LTS。开发阶段先验证持久化 Chromium/Chrome + CDP,不调用领星新品测量接口。
## 1. 启动持久化 Chromium(Ubuntu 22.04)
服务器上使用专用浏览器 profile,不复用系统默认用户目录:
```bash
sudo apt-get update
sudo apt-get install -y chromium-browser xvfb
sudo mkdir -p /opt/lingxing/browser-profile
sudo chown -R "$USER":"$USER" /opt/lingxing
nohup xvfb-run --server-num=99 --server-args='-screen 0 1920x1080x24' \
chromium-browser \
--no-sandbox \
--disable-dev-shm-usage \
--remote-debugging-address=127.0.0.1 \
--remote-debugging-port=9222 \
--user-data-dir=/opt/lingxing/browser-profile \
--window-size=1920,1080 \
https://oms.xlwms.com \
>/var/log/lingxing-chromium.log 2>&1 &
```
若系统命令名是 `chromium` 而非 `chromium-browser`,替换命令名即可。通过临时 VNC/远程桌面完成人工登录和二次验证码;后续复用该 profile。不要把真实账号、密码、验证码或 profile 目录提交到仓库。
建议通过 SSH 隧道访问 CDP,不要把 9222 暴露到公网:
```bash
ssh -N -L 9222:127.0.0.1:9222 <dev-user>@<dev-server>
```
## 2. 验证 CDP 页面
```bash
curl http://127.0.0.1:9222/json/version
curl http://127.0.0.1:9222/json/list
```
必须能看到 `https://oms.xlwms.com` 页面和 `webSocketDebuggerUrl`。页面仍在 `/login` 时先完成人工二次验证,读取器不会绕过验证码。Java 读取入口是:
```java
new LingxingBrowserSessionReader(objectMapper).read(
new LingxingProviderConfig("LINGXING_01", "http://127.0.0.1:9222", true, 172800, 300),
"https://oms.xlwms.com");
```
成功时只在内存返回 Token、Cookie 和过期时间;日志不得输出完整凭证。页面回到 `/login`、没有 `oms-token` 或没有 OMS Cookie 时,应判定为需要人工登录。