refactor: 删除登录表单里没有引用的字段和正则
This commit is contained in:
@@ -10,7 +10,7 @@ import re
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from collections.abc import AsyncIterator
|
from collections.abc import AsyncIterator
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from urllib.parse import quote, urlencode, urljoin
|
from urllib.parse import quote, urlencode
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from cryptography.hazmat.primitives import serialization
|
from cryptography.hazmat.primitives import serialization
|
||||||
@@ -36,9 +36,6 @@ from app.platform.sign import build_sign, wfs_sig
|
|||||||
|
|
||||||
_EXECUTION = re.compile(r'name="execution"\s+value="([^"]+)"', re.I)
|
_EXECUTION = re.compile(r'name="execution"\s+value="([^"]+)"', re.I)
|
||||||
_PUBLIC_KEY = re.compile(r'setPublicKey\("([^"]+)"\)')
|
_PUBLIC_KEY = re.compile(r'setPublicKey\("([^"]+)"\)')
|
||||||
_FORM_ACTION = re.compile(r'<form[^>]*id="fm1"[^>]*action="([^"]*)"', re.I)
|
|
||||||
_FORM_ACTION_REV = re.compile(r'<form[^>]*action="([^"]*)"[^>]*id="fm1"', re.I)
|
|
||||||
_ERROR_TEXT = re.compile(r'id="errMsg"[^>]*>(.*?)</', re.S)
|
|
||||||
|
|
||||||
|
|
||||||
class NqiError(Exception):
|
class NqiError(Exception):
|
||||||
@@ -110,7 +107,6 @@ def _transport_error(exc: Exception) -> None:
|
|||||||
class LoginChallenge:
|
class LoginChallenge:
|
||||||
execution: str
|
execution: str
|
||||||
public_key: str
|
public_key: str
|
||||||
form_action: str
|
|
||||||
captcha_png: bytes
|
captcha_png: bytes
|
||||||
page_url: str
|
page_url: str
|
||||||
captcha_type: str = "image/jpeg"
|
captcha_type: str = "image/jpeg"
|
||||||
@@ -190,12 +186,6 @@ class NqiClient:
|
|||||||
if not execution or not public_key:
|
if not execution or not public_key:
|
||||||
raise NqiError("登录页没有返回加密参数,请稍后重试")
|
raise NqiError("登录页没有返回加密参数,请稍后重试")
|
||||||
page_url = login_page_url(str(response.url))
|
page_url = login_page_url(str(response.url))
|
||||||
action_match = _FORM_ACTION.search(html) or _FORM_ACTION_REV.search(html)
|
|
||||||
action = action_match.group(1) if action_match and action_match.group(1) else page_url
|
|
||||||
if action.startswith("/"):
|
|
||||||
action = ORIGIN + action
|
|
||||||
elif not action.startswith("http"):
|
|
||||||
action = urljoin(page_url, action)
|
|
||||||
try:
|
try:
|
||||||
captcha = await self.client.get(CAS_CAPTCHA, headers={"Referer": page_url})
|
captcha = await self.client.get(CAS_CAPTCHA, headers={"Referer": page_url})
|
||||||
except (httpx.TimeoutException, httpx.RequestError) as exc:
|
except (httpx.TimeoutException, httpx.RequestError) as exc:
|
||||||
@@ -205,7 +195,6 @@ class NqiClient:
|
|||||||
return LoginChallenge(
|
return LoginChallenge(
|
||||||
execution=execution.group(1),
|
execution=execution.group(1),
|
||||||
public_key=public_key.group(1),
|
public_key=public_key.group(1),
|
||||||
form_action=action,
|
|
||||||
captcha_png=captcha.content,
|
captcha_png=captcha.content,
|
||||||
page_url=page_url,
|
page_url=page_url,
|
||||||
captcha_type=_media_type(captcha),
|
captcha_type=_media_type(captcha),
|
||||||
|
|||||||
Reference in New Issue
Block a user