fanzha-ai-proxy README

The project's README from github.com/lfzk550/fanzha-ai-proxy. As one markdown file: README.md.

🛡️ 国家反诈 AI 反向代理服务 (fanzha-ai-proxy)

将“国家反诈AI”智能助手转换为标准 OpenAI 兼容 API 接口 (/v1/chat/completions) 的高性能反向代理服务。

完美支持流式 (SSE) 输出与非流式响应,可直接无缝接入 NextChat、OneAPI / New API、LobeChat、Codex CLI 等主流 AI 客户端及开发框架。


🌟 项目特性


🔑 令牌 (Token) 获取教程

提示:“国家反诈AI”后端基于 JWT 进行身份验证。代理服务需要 Access Token 访问接口,配置 Refresh Token 可支持自动长效续期。

方法一:通过 ADB 提取本地数据库 (推荐 / 最稳定)

应用采用 Uni-App 静态打包架构,登录状态持久化保存在手机应用私有 SQLite 数据库中。

  1. 开启调试:手机开启开发者选项并启用 USB 调试,通过数据线连接电脑(终端运行 adb devices 确认设备已连接)。
  2. 定位数据库路径:应用本地 SQLite 数据库位于 /data/data/uni.app.UNIAD10B08/databases/DCStorage。
  3. 提取数据库文件并查询:
    # 导出数据库文件到 SD 卡并 pull 到电脑
    adb shell "su -c 'cp /data/data/uni.app.UNIAD10B08/databases/DCStorage /sdcard/DCStorage'"
    adb pull /sdcard/DCStorage ./DCStorage
    
    # 使用 sqlite3 查询 user 记录
    sqlite3 ./DCStorage "SELECT value FROM DC_AD10B08_storage WHERE key='user';"
    
  4. 提取字段:解密/解析返回的 JSON 内容,查找 accessToken(Access Token)与 refreshToken(Refresh Token)。

方法二:通过 Chrome Webview 调试 (免 Root)

  1. 手机连电脑并开启 USB 调试。
  2. 手机打开“国家反诈AI”App 并进入 AI 对话界面。
  3. 电脑端打开 Chrome 浏览器,访问地址:
    chrome://inspect/#devices
    
  4. 在页面列表中找到 uni.app.UNIAD10B08 对应的 Webview 目标,点击 inspect。
  5. 在弹出的开发者工具中切换到 Network (网络) 标签页。
  6. 在 App 中发送任意一条消息,观察抓到的网络请求。
  7. 点击请求路径形如 /api/ai/create_session 或 /api/ai/chat 的接口,在 Request Headers 中找到:
    Authorization: Bearer eyJhbGciOiJIUzI1...
    
  8. 复制 Bearer 后面的字符串,即为 Access Token。

方法三:使用抓包工具 (Fiddler / Charles / Reqable / HTTPCanary)

  1. 开启抓包工具并配置目标域名过滤:xzfzznt.gaj.sh.gov.cn。
  2. 触发 AI 对话,截获 HTTP POST 请求。
  3. 复制 Header 中的 Authorization 字段。

🚀 快速启动

1. 安装依赖

环境要求:Python 3.9+

git clone https://github.com/Mai-xiyu/fanzha-ai-proxy.git
cd fanzha-ai-proxy
pip install -r requirements.txt

2. 配置环境变量

复制环境变量模板:

cp .env.example .env

编辑 .env 文件或直接在终端导出环境变量:

PowerShell (Windows):

$env:FANZHA_ACCESS_TOKEN="你的Access_Token"
$env:FANZHA_REFRESH_TOKEN="你的Refresh_Token" # 可选

Bash / Zsh (Linux / macOS):

export FANZHA_ACCESS_TOKEN="你的Access_Token"
export FANZHA_REFRESH_TOKEN="你的Refresh_Token" # 可选

3. 运行服务

python main.py

服务默认运行在 http://127.0.0.1:8088。


💻 客户端调用示例

cURL

curl http://127.0.0.1:8088/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer 你的Access_Token" \
  -d '{
    "model": "国家反诈AI",
    "messages": [
      {"role": "user", "content": "收到自称公检法的电话要求转账,应该怎么做?"}
    ],
    "stream": true
  }'

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8088/v1",
    api_key="你的Access_Token"  # 若已在服务端配置环境变量,此处可填任意非空字符串
)

response = client.chat.completions.create(
    model="国家反诈AI",
    messages=[{"role": "user", "content": "请简要说明常见的电信网络诈骗手段有哪些?"}],
    stream=True
)

for chunk in response:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

📄 开源协议与声明

fanzha-ai-proxy (lfzk550/fanzha-ai-proxy)

Searching Database…

What is this?A reverse proxy that turns China's government 'National Anti-Fraud AI' (国家反诈AI) mobile assistant into an OpenAI-compatible API (/v1/chat/completions), so it can be plugged into normal AI chat clients.
Is this a standalone server I run, or a library I import?It's a standalone Python server process you run yourself; it exposes OpenAI-style HTTP endpoints and forwards the calls to the anti-fraud AI backend using your extracted login token.
How do I get it running?Install the Python 3.9+ dependencies, copy the .env template and fill in your Access/Refresh Token, then start the service - it serves OpenAI-compatible routes like /v1/chat/completions and /v1/models.
Do I need an account or token from the actual app first?Yes - you need a valid Access Token (ideally with a Refresh Token) from the official '国家反诈AI' app's JWT login, which you extract via ADB, Chrome webview debugging, or a packet-capture tool like Fiddler/Charles/Reqable.
Is this officially supported, or could it break anytime?It's unofficial and explicitly disclaims any affiliation with the real app; the author states it's only for technical exchange, academic research and personal learning, and since it relies on reverse-engineered tokens, the extraction methods could stop working if the app changes.
Does it run only on Linux, or on Windows and macOS too?It runs cross-platform - the README gives separate setup commands for PowerShell on Windows and Bash/Zsh on Linux/macOS.
How long does the access token stay valid before I need to re-login?With a Refresh Token configured, the service auto-renews the session for up to about 90 days without needing to log in again.
Which chat clients can I point at this proxy?It's built to work out of the box with NextChat, OneAPI/New API, LobeChat, Codex CLI, or any other tool that speaks the OpenAI chat-completions API.
What is the '国家反诈AI' app this project proxies?It's China's official 'National Anti-Fraud AI' mobile app, built on the Uni-App framework, which stores its login session in a local SQLite database on the phone.
Does streaming output actually work correctly?Yes - SSE streaming was specifically fixed to send the first chunk's role, incremental delta content, and a proper finish_reason: stop signal.
Creator
lfzk550
Size
0 MB
Stars
613
Updated
CommitSep 07
Age
1mo
Commits · 90 Days