feat: geetest添加自定义返回参数 (#313)

* feat: 更改geetest验证方式

* feat: geetest添加自定义返回参数

* feat: geetest添加自定义返回参数

* Update pyproject.toml

* Update Dockerfile
This commit is contained in:
Night-stars-1 2025-01-25 12:57:23 +08:00 committed by GitHub
parent cbef91d4f5
commit 40d3c279e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 8 deletions

View File

@ -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 && \

View File

@ -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",

View File

@ -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

View File

@ -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