From 40d3c279e819c96d432a9f03acef1a7814e65780 Mon Sep 17 00:00:00 2001 From: Night-stars-1 <99261160+Night-stars-1@users.noreply.github.com> Date: Sat, 25 Jan 2025 12:57:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20geetest=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=BF=94=E5=9B=9E=E5=8F=82=E6=95=B0=20(#313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 更改geetest验证方式 * feat: geetest添加自定义返回参数 * feat: geetest添加自定义返回参数 * Update pyproject.toml * Update Dockerfile --- Dockerfile | 2 +- pyproject.toml | 4 +--- utils/captcha.py | 13 +++++++++---- utils/config.py | 3 +++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d66bf19..9990cac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ WORKDIR /srv COPY ./utils ./utils -COPY ./pyproject.toml ./pdm.lock ./miuitask.py ./docker_start.sh ./ +COPY ./pyproject.toml ./miuitask.py ./docker_start.sh ./ RUN pdm install --prod && \ echo '0 4 * * * /bin/sh -c "sleep $((RANDOM % 1800 + 1)); cd /srv && pdm run /srv/miuitask.py"' > /var/spool/cron/crontabs/root && \ diff --git a/pyproject.toml b/pyproject.toml index 8e9f8a9..5a31af1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,11 +4,9 @@ version = "" description = "" authors = [] dependencies = [ - "orjson>=3.9.10", "loguru>=0.7.2", - "pydantic>=2.4.2", "httpx>=0.25.1", - "cryptography>=41.0.5", + "cryptography=44.0.0", "pyyaml>=6.0.1", "tenacity>=8.2.3", "tzdata>=2023.3", diff --git a/utils/captcha.py b/utils/captcha.py index 5f33e3e..99a163b 100644 --- a/utils/captcha.py +++ b/utils/captcha.py @@ -28,7 +28,7 @@ def find_key(data: dict, key: str): def get_validate_other( - gt: str, challenge: str + gt: str, challenge: str, result: str ) -> GeetestResult: # pylint: disable=invalid-name """获取人机验证结果""" try: @@ -36,11 +36,11 @@ def get_validate_other( if _conf.preference.get_geetest_url: params = _conf.preference.get_geetest_params.copy() params = json.loads( - json.dumps(params).replace("{gt}", gt).replace("{challenge}", challenge) + json.dumps(params).replace("{gt}", gt).replace("{challenge}", challenge).replace("{result}", result) ) data = _conf.preference.get_geetest_data.copy() data = json.loads( - json.dumps(data).replace("{gt}", gt).replace("{challenge}", challenge) + json.dumps(data).replace("{gt}", gt).replace("{challenge}", challenge).replace("{result}", result) ) for i in range(10): log.info(f"第{i}次获取结果") @@ -81,6 +81,7 @@ def get_validate( """创建人机验证并结果""" try: validate = "" + result = "" if _conf.preference.geetest_url: params = _conf.preference.geetest_params.copy() params = json.loads( @@ -106,10 +107,14 @@ def get_validate( geetest_challenge_match = geetest_challenge_expr.find(result) if len(geetest_challenge_match) > 0: challenge = geetest_challenge_match[0].value + geetest_result_expr = parse(_conf.preference.geetest_result_path) + geetest_result_match = geetest_result_expr.find(result) + if len(geetest_result_match) > 0: + result = geetest_result_match[0].value if validate and challenge: return GeetestResult(challenge=challenge, validate=validate) else: - return get_validate_other(gt=gt, challenge=challenge) + return get_validate_other(gt=gt, challenge=challenge, result=result) else: return GeetestResult(challenge="", validate="") except Exception: # pylint: disable=broad-exception-caught diff --git a/utils/config.py b/utils/config.py index 2299c17..5c0fe8e 100644 --- a/utils/config.py +++ b/utils/config.py @@ -148,6 +148,7 @@ class Preference: geetest_data: Optional[dict] = None, geetest_validate_path="$.data.validate", geetest_challenge_path="$.data.challenge", + geetest_result_path="", get_geetest_url="", get_geetest_method: Literal["post", "get"] = "post", get_geetest_params: Optional[dict] = None, @@ -167,6 +168,8 @@ class Preference: """极验验证validate的路径""" self.geetest_challenge_path = geetest_challenge_path """极验验证challenge的路径""" + self.geetest_result_path = geetest_result_path + """极验验证返回参数的路径""" self.get_geetest_url = get_geetest_url """获取极验验证结果的URL""" self.get_geetest_method = get_geetest_method