Removed an old run configuration, added a new coverage XML report, and updated multiple source files including main.py, middleware, models, routers, services, tests, and utility modules. Also updated pyproject.toml and the lock file. These changes likely include code improvements, test coverage updates, and dependency adjustments.
21 lines
672 B
Python
21 lines
672 B
Python
import aiohttp
|
||
|
||
from . import CaptchaRequestBase
|
||
|
||
async def verify_captcha(request: CaptchaRequestBase) -> bool:
|
||
"""
|
||
验证 Turnstile 的 token 是否有效。
|
||
|
||
:return: 如果验证成功返回 True,否则返回 False
|
||
:rtype: bool
|
||
"""
|
||
verify_url = "https://challenges.cloudflare.com/turnstile/v0/siteverify"
|
||
payload = request.model_dump()
|
||
|
||
async with aiohttp.ClientSession() as session:
|
||
async with session.post(verify_url, data=payload) as response:
|
||
if response.status != 200:
|
||
return False
|
||
|
||
result = await response.json()
|
||
return result.get('success', False) |