z1bun / yii2-module-recaptcha-v3
这是为Yii2设计的reCAPTCHA v3。
2.0
2019-11-08 07:13 UTC
Requires
- ext-curl: *
- yiisoft/yii2: ~2.0.15
README
将recaptcha-v3添加到yii2项目中
安装
安装此扩展的首选方式是通过composer。
可以运行以下命令
php composer.phar require --prefer-dist z1bun/yii2-module-recaptcha-v3 "dev-master"
或者在您的composer.json
文件的require部分添加
"z1bun/yii2-module-recaptcha-v3": "dev-master"
到
使用
安装扩展后,只需在您的代码中按以下方式使用它
将以下内容添加到您的components/main.php
'components' => [ ... 'reCaptcha3' => [ 'class' => 'z1bun\recaptcha3\ReCaptcha', 'siteKey' => env('recaptcha_site_key'), 'secretKey' => env('recaptcha_secret_key'), ],
在您的模型中
acceptance_score是这个请求的最小分数(0.0 - 1.0)或null
public $reCaptcha; public function rules() { return [ ... [['reCaptcha'], \z1bun\recaptcha3\ReCaptchaValidator::class, 'acceptance_score' => 0] ]; }
<?= $form->field($model, 'reCaptcha')->widget(\z1bun\recaptcha3\ReCaptchaWidget::class) ?>
用于测试
当在index-test.php
中使用YII_ENV_TEST
时,禁用recaptcha的验证
defined('YII_ENV') or define('YII_ENV', 'test');
待办事项
选项:隐藏徽章并在表单中显示recaptcha使用条款的链接