vintage/yii2-invisible-recaptcha

Google 无痕 reCAPTCHA 的 Yii2 框架封装

v1.0.1 2019-10-25 12:49 UTC

This package is not auto-updated.

Last update: 2024-09-15 05:34:02 UTC


README

无痕 reCAPTCHA


为 Yii2 框架提供的 Google 无痕 reCAPTCHA 封装。更多详情请参阅官方文档

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version Latest Unstable Version

安装

安装包

运行命令

$ composer require vintage/yii2-invisible-recaptcha

或者

"vintage/yii2-invisible-recaptcha": "~1.0"

添加到你的 composer.json 文件的 require 部分。

使用方法

  1. 在您的 Google 账户 中创建 API 密钥

  2. frontend/config/params-local.php 中配置 API 密钥

<?php

use vintage\recaptcha\helpers\RecaptchaConfig;

return [
    RecaptchaConfig::SITE_KEY => 'your_site_key',
    RecaptchaConfig::PRIVATE_KEY => 'your_private_key',
];
  1. 在表单中调用小部件
<form id="send-feedbacl-js" method="post">
<?= \vintage\recaptcha\widgets\InvisibleRecaptcha::widget([
    'formSelector' => '#send-feedback-js',
]) ?>
<button type="submit">Send</button>
</form>
  1. 在后端进行验证
\vintage\recaptcha\validators\InvisibleRecaptchaValidator::validateInline(
    Yii::$app->getRequest()->post()
);

或者如果您想处理错误

$validator = new \vintage\recaptcha\validators\InvisibleRecaptchaValidator(
    Yii::$app->getRequest()->post()
);
if (!$validator->validate()) {
    return $validator->getErrors();
}

配置

小部件配置选项。

许可证

License

该项目在 BSD-3-Clause 许可证下发布。查看许可证

版权 (c) 2017, Vintage Web Production