feat: 登录有效期24小时 + Cloudflare Turnstile 人机验证
- jwt_ttl 7200 → 86400 (24h) - 管理登录/代理登录/代理注册 接入 Turnstile - 前端 TurnstileWidget 组件, 未完成验证不可提交 - 密钥通过 env TURNSTILE_SITE_KEY/SECRET_KEY 配置
This commit is contained in:
1 parent
5b73d0921d
commit
e90ade2ba0
10 files changed
+230
-12
No files matched your search
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
namespace App\Services;
|
||||
|
||||
/**
|
||||
* Cloudflare Turnstile 人机验证
|
||||
*/
|
||||
class TurnstileService
|
||||
{
|
||||
/**
|
||||
* 校验 Turnstile token
|
||||
* 未配置 secret 时跳过校验(便于本地开发)
|
||||
*/
|
||||
public static function verify(?string $token, ?string $remoteIp = null): bool
|
||||
{
|
||||
$secret = (string) config('app.turnstile.secret_key', '');
|
||||
if ($secret === '') {
|
||||
return true;
|
||||
}
|
||||
if ($token === null || $token === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'secret' => $secret,
|
||||
'response' => $token,
|
||||
];
|
||||
if ($remoteIp) {
|
||||
$payload['remoteip'] = $remoteIp;
|
||||
}
|
||||
|
||||
$ch = curl_init('https://challenges.cloudflare.com/turnstile/v0/siteverify');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_POST => true,
|
||||
CURLOPT_POSTFIELDS => http_build_query($payload),
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 10,
|
||||
CURLOPT_HTTPHEADER => ['Content-Type: application/x-www-form-urlencoded'],
|
||||
]);
|
||||
$body = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($body === false) {
|
||||
return false;
|
||||
}
|
||||
$json = json_decode($body, true);
|
||||
return !empty($json['success']);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user