在Laravel中,我正在设置Google ReCaptcha V3,它现在返回一个“分数”。我设法设置了一个验证规则以允许我的表单提交(所有工作),但这只是返回 true 或 false 以通过验证。
我如何根据分数来代替?
我正在使用这个作曲家包来帮助我 - https://github.com/google/recaptcha
这是在我的控制器中(我正在发送令牌以通过服务器验证):
// validation
$this->validate( $request, array(
'g_recaptcha_response' => ['required', 'string', new Captcha()]
));
这是规则:
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
use ReCaptcha\ReCaptcha;
class Captcha implements Rule
{
public function __construct()
{
//
}
public function passes($attribute, $value)
{
$recaptcha = new ReCaptcha('SECRET');
$response = $recaptcha->verify($value, $_SERVER['REMOTE_ADDR']);
return $response->isSuccess();
}
public function message()
{
return 'Are you a robot?';
}
}
我可以从控制器以某种方式访问该类吗?我可以在包中看到我需要使用->getScore()
但我不知道如何访问它?