combindma / recaptcha
为 Laravel 框架提供的简单易用的 Google reCAPTCHA V3 包
2.1.0
2023-03-18 16:11 UTC
Requires
- php: ^8.0
- ext-curl: *
- illuminate/contracts: ^8.0|^9.0|^10.0
- spatie/laravel-package-tools: ^1.4.3
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^6.13|^7.0|^8.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.6
README
为 Laravel 框架提供的简单易用的 Google reCAPTCHA V3 包。
灵感来源于: https://github.com/biscolab/laravel-recaptcha
安装
您可以通过 composer 安装此包
composer require combindma/recaptcha
您可以使用以下命令发布配置文件
php artisan vendor:publish --provider="Combindma\Recaptcha\RecaptchaServiceProvider" --tag="recaptcha-config"
这是已发布配置文件的内容
return [ //The name of the input used to send Google reCAPTCHA token to verify 'token_name' => env('RECAPTCHA_NAME', 'recaptcha_token'), /** * * The site key * get site key @ www.google.com/recaptcha/admin * */ 'api_site_key' => env('RECAPTCHA_SITE_KEY', ''), /** * * The secret key * get secret key @ www.google.com/recaptcha/admin * */ 'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''), /** * * The curl timout in seconds to validate a recaptcha token * */ 'curl_timeout' => 10, /** * * Set API domain. You can use "www.recaptcha.net" in case "www.google.com" is not accessible. * (no check will be made on the entered value) * @see https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally * @since v4.3.0 * Default 'www.google.com' (ReCaptchaBuilder::DEFAULT_RECAPTCHA_API_DOMAIN) * */ 'api_domain' => 'www.google.com', //you can disable the ReCaptcha when you test your application 'enabled' => env('RECAPTCHA_ENABLED', 'true'), ];
您可以使用以下命令发布翻译文件
php artisan vendor:publish --provider="Combindma\Recaptcha\RecaptchaServiceProvider" --tag="recaptcha-translations"
这是已发布翻译文件的内容
return [ 'invalid' => 'We could not verify if you are a robot or not. Please refresh the page.', ];
使用方法
嵌入到 Blade 中
在关闭标签前插入 htmlScriptTagJsApi($config) 辅助函数。
<!DOCTYPE html> <html> <head> {!! htmlScriptTagJsApi(['action' => 'homepage']) !!} </head>
在您的表单标签内插入 recaptchaInput() 辅助函数。
<form action="" method="POST"> @csrf {!! recaptchaInput() !!} <!-- More inputs --> </form>
验证令牌
在您的验证规则请求或控制器中添加规则 'recaptcha'。
$request->validate([ //... other rules //Add this to your validation rule config('recaptcha.token_name') => ['required','string', 'recaptcha'] ]);
如果验证失败,将返回错误。
测试
composer test
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全漏洞
请审查 我们的安全策略 了解如何报告安全漏洞。
致谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。