mirror of
https://github.com/0-8-4/miui-auto-tasks.git
synced 2024-11-16 12:51:36 +00:00
ea361a0e04
* chore: captcha的参数拷贝,避免修改原参数 chore: 提升pylint分数,使代码更加规范 * fix: `@validator` cannot be applied to instance methods * deleted: .pylintrc * chore: no-else-return * chore: 优化代码,使其更符合PEP 8规范 * chore: 优化代码,使其更符合PEP 8规范 * chore: 优化代码,使其更符合PEP 8规范 * chore: 添加代码规范等级 * fix: fix dockerfile * modified: Dockerfile * chore: 更新docker ci
40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
'''
|
|
Date: 2023-11-13 19:55:22
|
|
LastEditors: Night-stars-1 nujj1042633805@gmail.com
|
|
LastEditTime: 2023-11-18 14:30:41
|
|
'''
|
|
|
|
from .request import post
|
|
from .logger import log
|
|
from .config import ConfigManager
|
|
from .data_model import ApiResultHandler, GeetestResult
|
|
|
|
_conf = ConfigManager.data_obj
|
|
|
|
async def get_validate(gt: str, challenge: str) -> GeetestResult: # pylint: disable=invalid-name
|
|
"""获取人机验证结果"""
|
|
try:
|
|
validate = ""
|
|
params = _conf.preference.geetest_params.copy()
|
|
for key, value in params.items():
|
|
if isinstance(value, str):
|
|
params[key] = value.format(gt=gt, challenge=challenge)
|
|
data = _conf.preference.geetest_data.copy()
|
|
for key, value in data.items():
|
|
if isinstance(value, str):
|
|
data[key] = value.format(gt=gt, challenge=challenge)
|
|
response = await post(
|
|
_conf.preference.geetest_url,
|
|
params=params,
|
|
json=data,
|
|
)
|
|
log.debug(response.text)
|
|
geetest_data = response.json()
|
|
geetest = ApiResultHandler(geetest_data)
|
|
challenge = geetest.data["challenge"]
|
|
validate = geetest.data["validate"]
|
|
return GeetestResult(challenge=challenge, validate=validate)
|
|
except Exception: # pylint: disable=broad-exception-caught
|
|
log.exception("获取人机验证结果异常")
|
|
return GeetestResult(challenge="", validate="")
|