基本完成

This commit is contained in:
2026-08-25 22:53:57 +08:00
parent 05fa686749
commit 252d5b53ac
39 changed files with 3853 additions and 447 deletions
+45 -21
View File
@@ -112,6 +112,8 @@ class StartApplyReq(BaseModel):
min_score: int = 65
delay_min: int = 3
delay_max: int = 8
boss_online_only: bool = False
daily_limit: int = 0
# =======================================================
@@ -147,7 +149,7 @@ def get_status():
"server_connected": state.connected,
"server_reachable": state.server_api.ping(),
"rpa_online": me.get("is_online", False) if me else False,
"adspower_running": state.browser.is_adspower_running(),
"browser_running": state.browser.is_browser_running(),
"ai_configured": state.ai.available(),
"login_status": me.get("login_status", "unknown") if me else "unknown",
"boss_account": me.get("boss_account") if me else None,
@@ -221,14 +223,23 @@ def logout():
# =======================================================
@app.post("/api/start-login")
def start_login():
"""打开 AdsPower 浏览器并跳转到 Boss直聘,等待用户手动登录"""
"""拉起浏览器引导登录 Boss直聘,等待用户手动登录。
首次启动时浏览器自带 Boss直聘 首启标签页(由 Chrome 自己创建,程序不碰);
浏览器已在运行但首启页被关掉了,才补开一个用户标签页。"""
_require_auth()
try:
state.server_api.update_login_status("logging_in")
page = state.browser.connect()
page.goto("https://www.zhipin.com/", wait_until="domcontentloaded", timeout=30000)
# 启动后台轮询检测登录
threading.Thread(target=_poll_login, daemon=True).start()
already_running = state.browser.is_browser_running()
if not already_running:
# 首次启动:拉起浏览器(启动参数自带目标网址,由 Chrome 自己打开)
state.browser.ensure_browser_started()
else:
# 浏览器已在运行:无法确定用户是否还留着登录页,补开一个
# (原生 DevTools 协议开页,无自动化痕迹,风控不拦截)
state.browser.open_user_tab("https://www.zhipin.com/")
# 启动后台轮询检测登录(防止重复点击叠加多个轮询线程)
if not state.login_polling:
threading.Thread(target=_poll_login, daemon=True).start()
return {"ok": True, "msg": "浏览器已打开,请在浏览器中完成登录"}
except Exception as e:
state.server_api.update_login_status("not_login")
@@ -236,26 +247,33 @@ def start_login():
def _poll_login():
"""后台轮询检测登录状态,最长等待 5 分钟"""
"""后台轮询检测登录状态,最长等待 5 分钟。
检测仅读 Cookie(低痕迹通道,零刷新零开页),不打扰用户标签页。"""
state.login_polling = True
import time
for _ in range(150): # 150 * 2s = 5 分钟
time.sleep(2)
try:
if state.browser.check_boss_login():
account = state.browser.get_boss_account_name()
state.server_api.update_login_status("logged_in", account)
logger.success(f"登录成功:{account}")
break
except Exception as e:
logger.debug(f"登录轮询异常:{e}")
state.login_polling = False
try:
for _ in range(150): # 150 * 2s = 5 分钟
time.sleep(2)
try:
if state.browser.check_boss_login():
account = state.browser.get_boss_account_name()
state.server_api.update_login_status("logged_in", account)
logger.success(f"登录成功:{account}")
break
except Exception as e:
logger.debug(f"登录轮询异常:{e}")
finally:
state.login_polling = False
@app.post("/api/detect-login")
def detect_login():
"""活体检测 Boss直聘 登录状态(进入登录步骤时自动调用)"""
"""活体检测 Boss直聘 登录状态(进入登录步骤时自动调用;仅读 Cookie + 一次性后台复核)"""
_require_auth()
# 浏览器未运行时直接判未登录,检测行为不应负责拉起浏览器
if not state.browser.is_browser_running():
state.server_api.update_login_status("not_login")
return {"logged_in": False}
try:
logged_in = state.browser.check_boss_login()
except Exception as e:
@@ -292,6 +310,7 @@ def scrape_resumes():
"""AI 抓取账号内所有简历并上传到云端"""
_require_auth()
try:
# 抓取走低痕迹 CDP 通道(无 Playwright attach,风控不拦截)
scraper = ResumeScraper(state.browser, state.ai)
resumes = scraper.scrape_all()
if not resumes:
@@ -325,8 +344,11 @@ def start_apply(req: StartApplyReq):
_require_rpa_online() # 在线预检:与服务端 require_online_user 前置校验呼应
if not state.server_api.get_primary_resume():
raise HTTPException(status_code=400, detail="请先设置主简历")
if not state.browser.is_adspower_running():
raise HTTPException(status_code=400, detail="AdsPower 未运行")
try:
# 浏览器可能被用户手动关闭,投递前确保已拉起(复用登录态 profile)
state.browser.ensure_browser_started()
except RuntimeError as e:
raise HTTPException(status_code=400, detail=str(e))
applicant = state.ensure_applicant()
if applicant.is_running:
@@ -340,6 +362,8 @@ def start_apply(req: StartApplyReq):
greeting=req.greeting,
min_score=req.min_score,
delay_range=(req.delay_min, req.delay_max),
boss_online_only=req.boss_online_only,
daily_limit=req.daily_limit,
)
return {"ok": True, "session_id": applicant.session_id}