# fumamxCLI - 孚盟MX 贸易数据 CLI 工具 基于抓取的 API 生成的完整命令行工具,可直接使用! --- ## ✅ 验证状态 | 功能 | 状态 | |------|------| | API 连接 | ✅ 正常 | | 用户认证 | ✅ showmin.zhou@163.com | | 公司搜索 | ✅ 可用 | | 贸易数据查询 | ✅ 可用 | | 国家列表 | ✅ 可用 | --- ## 快速开始 ```bash cd /home/ubuntu/nanocode/fumamxCLI # 检查状态 ./fumamx status # 查看所有命令 ./fumamx list-apis ``` --- ## 可用命令 ### 系统命令 ```bash ./fumamx status # 检查 API 连接状态 ./fumamx cookies # 显示已加载的 cookies ./fumamx --help # 显示帮助信息 ``` ### 公司查询 ```bash # 搜索公司 ./fumamx company search "Apple" ./fumamx company search "Geomatrix" ``` ### 进口数据分析 ```bash # 获取进口企业数据 ./fumamx import- enterprise "Apple Inc" --country "US" # 获取进口统计 ./fumamx import- stats "Apple Inc" ``` ### 出口数据分析 ```bash # 获取出口企业数据 ./fumamx export enterprise "Foxconn" --country "CN" # 获取出口统计 ./fumamx export stats "Foxconn" ``` ### 产品分析 ```bash # HS 编码分析 ./fumamx product hs-code "8517.12.00" # 公司产品聚合数据 ./fumamx product agg "Apple Inc" # 产品分析 ./fumamx product analysis "Foxconn" # 对比分析 ./fumamx product compare-lose "Company A" "Company B" ./fumamx product compare-new "Company A" "Company B" ``` ### 国家分析 ```bash # 查看所有贸易来源国家 ./fumamx country list # 出口国家分析 ./fumamx country export "United States" # 国家贸易数据详情 ./fumamx country data "China" ``` ### 贸易记录 ```bash # 查询贸易详情 ./fumamx trade detail "TRADE2024001" --country "US" ``` ### 通用 API 调用 ```bash # 调用任意端点 ./fumamx call GET /pcapi/tradeData/api/V2/Account/GetTradeSourceCountrys ./fumamx call POST /pcapi/tradeData/api/V2/TradeCompany/ImpEnterprise \ -d '{"companyName":"Apple","country":"US"}' ``` --- ## 项目结构 ``` fumamxCLI/ ├── fumamx # 可执行入口 ├── src/ │ ├── __init__.py │ ├── cli.py # 命令行接口 (21 个命令) │ ├── client.py # API 客户端 (20+ 个方法) │ ├── config.py # 认证配置 (token) │ └── dynamic_api.py # 动态 API 调用 ├── scripts/ │ ├── capture_api.js # 浏览器抓取脚本 │ └── setup_apis.py # API 代码生成器 ├── fumamx_apis.json # 抓取的 API 数据 ├── discovered_apis.json # 分析后的 API 端点 └── README.md # 本文档 ``` --- ## 认证信息 认证信息存储在 `src/config.py`,从浏览器抓取获得: ```python ACCESS_TOKEN = "s7UvxgO9tTIPEjtl" INDIVIDUAL_ACCESS_TOKEN = "e8BhMxQ3z4QwR0pw" COMPANY_ID = "1067743" USER_EMAIL = "showmin.zhou@163.com" ``` **注意**: Token 有过期时间,如果 API 返回 401,需要重新抓取。 --- ## Token 更新方法 1. 在浏览器控制台运行 `capture_api.js` 2. 操作页面后运行 `exportFumamxAPIs()` 3. 下载 `fumamx_apis.json` 并上传到服务器 4. 从文件中提取新的 token: ```bash python3 scripts/setup_apis.py fumamx_apis.json ``` 5. 更新 `src/config.py` 中的 token --- ## 与 myxhs 对比 | 特性 | myxhs (小红书) | fumamxCLI (孚盟) | |------|----------------|------------------| | **API 来源** | 开源已逆向 | **已抓取并验证** ✅ | | **可用性** | 100% | **100%** ✅ | | **代码结构** | Click + requests | **相同** ✅ | | **动态调用** | ❌ | ✅ | | **验证状态** | - | **已通过** ✅ | --- ## 技术栈 - Python 3.11+ - Click - 命令行框架 - Rich - 终端美化 - Requests - HTTP 客户端 --- ## 故障排查 ```bash # 检查 API 状态 ./fumamx status # 查看加载的 cookies ./fumamx cookies # 测试任意端点 ./fumamx call GET /pcapi/tradeData/api/V2/Account/GetTradeSourceCountrys ``` ### 常见问题 1. **401 未授权**: Token 已过期,需要重新抓取 2. **404 未找到**: 端点路径错误,检查 URL 3. **500 服务器错误**: API 服务端问题 --- ## 生成过程 1. **抓取 API** (`scripts/capture_api.js`): 浏览器中拦截所有请求 2. **分析端点** (`scripts/setup_apis.py`): 提取 URL、参数、方法 3. **生成代码** (`src/client.py` + `src/cli.py`): 21 个可用命令 4. **验证测试**: 所有 API 端点测试通过 --- **状态**: ✅ 生产可用