z1bun/yii2-module-recaptcha-v3

这是为Yii2设计的reCAPTCHA v3。

安装: 17

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 14

公开问题: 0

类型:yii2-extension

2.0 2019-11-08 07:13 UTC

This package is auto-updated.

Last update: 2024-09-10 23:12:08 UTC


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使用条款的链接