alexleonnovak / yii2-module-recaptcha-v3
这是为 Yii2 定制的 reCAPTCHA v3。源自 kekaadrenalin/yii2-module-recaptcha-v3
1.4.1
2020-07-15 12:05 UTC
Requires
- ext-curl: *
- yiisoft/yii2: ~2.0.15
This package is auto-updated.
Last update: 2024-09-17 12:59:59 UTC
README
注意
这是从 kekaadrenalin/yii2-module-recaptcha-v3 分支出来的
Yii2 reCAPTCHA v3
将 recaptcha-v3 添加到 yii2 项目中
安装
推荐通过 composer 安装此扩展。
运行以下命令之一
php composer.phar require --prefer-dist alexleonnovak/yii2-module-recaptcha-v3 "*"
或
"alexleonnovak/yii2-module-recaptcha-v3": "*"
将以下内容添加到您的 composer.json
文件的 require 部分。
使用方法
扩展安装完成后,只需在代码中使用它即可
将以下内容添加到您的 components/main.php
'components' => [ ... 'reCaptcha3' => [ 'class' => 'alexleonnovak\recaptcha3\ReCaptcha', 'site_key' => 'site_key_###', 'secret_key' => 'secret_key_###', ],
并在您的模型中
acceptance_score 为此请求的最小分数(0.0 - 1.0)或 null
public $reCaptcha; public function rules() { return [ ... [['reCaptcha'], \alexleonnovak\recaptcha3\ReCaptchaValidator::className(), 'acceptance_score' => 0] ]; }
<?= $form->field($model, 'reCaptcha')->widget(\alexleonnovak\recaptcha3\ReCaptchaWidget::class) ?>
对于测试
当在 index-test.php
中使用 YII_ENV_TEST
时,禁用 recaptcha 的验证
defined('YII_ENV') or define('YII_ENV', 'test');