brandstudio / recaptcha
BrandStudio Google reCAPTCHA v3 包
v2.1.2
2020-08-28 20:36 UTC
Requires
- guzzlehttp/guzzle: ^6.3
README
一个简单的 Laravel 包,用于处理 Google reCAPTCHA v3
入门
安装
1) 运行命令
composer require brandstudio/recaptcha
或者手动编辑 composer.json 文件
"brandstudio/recaptcha": "^1.0@dev"
2) 发布配置文件(可选)
php artisan vendor:publish --provider="BrandStudio\Recaptcha\RecaptchaServiceProvider" --tag=config
配置
brandstudio/recaptcha.php 文件
/**
* Enable/Disable reCAPTCHA
*/
'enabled' => env('BS_RECAPTCHA_ENABLED', true),
/**
* Middleware alias
*/
'middleware_name' => 'recaptcha',
/**
* Frontend integration
*/
'url' => 'https://www.google.com/recaptcha/api.js?render=',
/**
* Your sitekey
*/
'public_key' => env('BS_RECAPTCHA_PUBLIC', ''),
/**
* Response verification
*/
'verification_url' => 'https://www.google.com/recaptcha/api/siteverify',
/**
* Your secret key
*/
'private_key' => env('BS_RECAPTCHA_PRIVATE', ''),
用法
在你的 .blade 文件中
@include('brandstudio::recaptcha.scripts')
/// Or
@include('brandstudio::recaptcha.scripts', ['recaptcha_action' => 'your-action-name'])
详细信息请参阅 Google reCAPTCHA actions
在控制器中
public function __construct()
{
...
$this->middleware('recaptcha');
...
}
或者
public function __construct()
{
...
$this->middleware(config('backpack.recaptcha.middleware_name'));
...
}
在路由中
Route::method('/url', 'Controller@function')->middleware('recaptcha');
或者
Route::middleware([..., 'recaptcha'])->group(function() {
...
Route::method('/url', 'Controller@function');
...
);
隐藏 Google reCAPTCHA 徽章
在 CSS 中
.grecaptcha-badge {
display: none;
}
只要在用户流程中明显包含 reCAPTCHA 品牌,就可以隐藏徽章。请包含以下文本
<small>
This site is protected by reCAPTCHA and the Google
<a href="https://policies.google.com/privacy">Privacy Policy</a> and
<a href="https://policies.google.com/terms">Terms of Service</a> apply.
</small>
许可
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE.md 文件。