2023-11-15 13:07:29 +00:00
|
|
|
'''
|
2023-11-13 13:18:59 +00:00
|
|
|
Date: 2023-11-13 19:55:22
|
|
|
|
LastEditors: Night-stars-1 nujj1042633805@gmail.com
|
2023-11-15 13:07:29 +00:00
|
|
|
LastEditTime: 2023-11-14 21:30:31
|
|
|
|
'''
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
from .request import get, post
|
|
|
|
from .logger import log
|
2023-11-15 13:07:29 +00:00
|
|
|
from .config import ConfigManager
|
2023-11-13 13:18:59 +00:00
|
|
|
from .data_model import ApiResultHandler, GeetestResult
|
|
|
|
|
2023-11-15 13:07:29 +00:00
|
|
|
_conf = ConfigManager.data_obj
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
async def get_validate(gt: str, challenge: str) -> GeetestResult:
|
|
|
|
try:
|
2023-11-15 13:07:29 +00:00
|
|
|
validate = ""
|
2023-11-17 04:46:00 +00:00
|
|
|
if not _conf.preference.geetest_url:
|
|
|
|
return GeetestResult(challenge="", validate="")
|
2023-11-15 13:07:29 +00:00
|
|
|
params = _conf.preference.geetest_params
|
|
|
|
for key, value in params.items():
|
|
|
|
if isinstance(value, str):
|
|
|
|
params[key] = value.format(gt=gt, challenge=challenge)
|
|
|
|
data = _conf.preference.geetest_data
|
|
|
|
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"]
|
2023-11-13 13:18:59 +00:00
|
|
|
return GeetestResult(challenge=challenge, validate=validate)
|
|
|
|
except Exception:
|
|
|
|
log.exception("获取人机验证结果异常")
|
|
|
|
return GeetestResult(challenge="", validate="")
|