rabdavinci/yii2-module-recaptcha-v3
这是为Yii2准备的reCAPTCHA v3。
1.0.6
2023-05-04 20:14 UTC
Requires
- ext-curl: *
- yiisoft/yii2: ~2.0.15
README
Yii2 reCAPTCHA v3
将recaptcha-v3添加到yii2项目中。在分支后修复了与AJAX的工作,并实现了全局注册
安装
安装此扩展的首选方式是通过composer。
运行以下命令
php composer.phar require --prefer-dist rabdavinci/yii2-module-recaptcha-v3 "*"
或者将以下内容添加到您的composer.json文件的require部分。
"rabdavinci/yii2-module-recaptcha-v3": "*"
使用
安装扩展后,只需在您的代码中使用它即可
将其添加到您的components/main.php
'components' => [ ... 'reCaptcha3' => [ 'class' => 'rabdavinci\recaptcha3\ReCaptcha', 'site_key' => 'site_key_###', 'secret_key' => 'secret_key_###', ],
在您的模型中
acceptance_score是该请求的最小分数(0.0 - 1.0)或null
public $reCaptcha; public function rules() { return [ ... [['reCaptcha'], \rabdavinci\recaptcha3\ReCaptchaValidator::className(), 'acceptance_score' => 0] ]; }
<?= $form->field($model, 'reCaptcha')->widget(\rabdavinci\recaptcha3\ReCaptchaWidget::class) ?>
对于测试
当在index-test.php中使用YII_ENV_TEST时,禁用recaptcha的验证
defined('YII_ENV') or define('YII_ENV', 'test');