Skip to content

Commit

Permalink
fix: 纠正验证码错误行为
Browse files Browse the repository at this point in the history
  • Loading branch information
Night-stars-1 committed Oct 25, 2024
1 parent b813782 commit a466062
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
11 changes: 7 additions & 4 deletions src/nonebot_plugin_mystool/command/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,13 @@ async def perform_game_sign(
sign_status, mmt_data = await signer.sign(account.platform)
if sign_status.need_verify:
if plugin_config.preference.geetest_url or user.geetest_url:
if matcher:
msgs_list.append("⏳正在尝试完成人机验证,请稍后...")
geetest_result = await get_validate(user, mmt_data.gt, mmt_data.challenge)
sign_status, _ = await signer.sign(account.platform, mmt_data, geetest_result)
for i in range(3):
if matcher:
msgs_list.append(f"⏳[验证码{i}] 正在尝试完成人机验证,请稍后...")
geetest_result = await get_validate(user, mmt_data.gt, mmt_data.challenge)
sign_status, mmt_data = await signer.sign(account.platform, mmt_data, geetest_result)
if sign_status:
break

if not sign_status and (user.enable_notice or matcher):
if sign_status.login_expired:
Expand Down
28 changes: 13 additions & 15 deletions src/nonebot_plugin_mystool/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,21 +261,19 @@ async def get_validate(user: UserData, gt: str = None, challenge: str = None, re
debug_log = {"geetest_url": geetest_url, "params": params, "content": content}
logger.debug(f"{plugin_config.preference.log_head}get_validate: {debug_log}")
try:
async for attempt in get_async_retry(retry):
with attempt:
async with httpx.AsyncClient() as client:
res = await client.post(
geetest_url,
params=params,
json=content,
timeout=60
)
geetest_data = res.json()
logger.debug(f"{plugin_config.preference.log_head}人机验证结果:{geetest_data}")
validate = geetest_data['data']['validate']
seccode = geetest_data['data'].get('seccode') or f"{validate}|jordan"
return GeetestResult(validate=validate, seccode=seccode)
except tenacity.RetryError:
async with httpx.AsyncClient() as client:
res = await client.post(
geetest_url,
params=params,
json=content,
timeout=60
)
geetest_data = res.json()
logger.debug(f"{plugin_config.preference.log_head}人机验证结果:{geetest_data}")
validate = geetest_data['data']['validate']
seccode = geetest_data['data'].get('seccode') or f"{validate}|jordan"
return GeetestResult(validate=validate, seccode=seccode)
except Exception:
logger.exception(f"{plugin_config.preference.log_head}获取人机验证validate失败")


Expand Down

0 comments on commit a466062

Please sign in to comment.