nocvp / zf3-php7-recaptcha-v2
Zend Framework 3 (ZF3) 和 Php7 的 ReCaptcha v2.0 模块
1.4.3
2016-05-29 18:51 UTC
Requires
- php: >=7.0
- zendframework/zend-captcha: ^2.5
- zendframework/zend-form: ^2.8
- zendframework/zend-http: ^2.5
- zendframework/zend-servicemanager: ^3.0.3
- zendframework/zend-view: ^2.6
This package is not auto-updated.
Last update: 2024-09-14 19:31:07 UTC
README
Zf3Php7Recaptcha 从 zf2-recaptcha 特性分支而来。
安装
使用 composer
只需将以下行添加到您的需求中
"nocvp/zf3-php7-recaptcha-v2": "dev-master"
并运行
php composer.phar update
由于使用 Adapter\Socket 时存在 SSL-Cert 问题,请安装 php-curl!
然后在您的 application.config.php 中激活该模块
```php
return array(
'modules' => array(
// ...
'Zf3Php7Recaptcha',
),
// ...
);
```
获取您的私钥
要使用此服务,您必须使用您的 Google-Account 在 Google ReCaptcha 上注册。
用法
使用 Zend\From
此模块的工作方式与 ZendFrameworkService\ReCaptcha 类似。
只需将以下行添加到您的表单创建中
$element = new \Zend\Captcha\Captcha('g-recaptcha-response');
$element->setCaptcha(new Zf3Php7Recaptcha\ReCaptcha(array('private_key' => 'YOUR_SECRET FROM GOOGLE', 'public_key' => 'YOUR_PUBLIC_KEY', 'theme' => 'dark')));
$form->add($element);
注意:由于 Google 的 JS 创建了这个虚拟输入,元素必须命名为 g-recaptcha-response。
请记得将此元素添加到您的验证链中。
注意:主题参数不是必需的。默认使用浅色主题。
它与其他内置验证码解决方案的行为相同。
使用 ServiceManager
如果您想自己实现视图,只需使用 Service\ReCaptchaService。它处理您代码与 ReCaptcha API 之间的全部通信。
$recaptcha = $serviceLocator->get('Zf3Php7Recaptcha\Service\ReCaptcha');
其他
查看源代码!理解起来非常简单。
待办事项
- 缺少 PHPUnit 测试 -> 将在接下来的几天内完成
- 一些错误处理还有待完善
- 需要更好的文档
有问题吗?
如果您对我的代码有任何问题或疑问,请创建一个问题。由于我正在用此模块为我的项目工作,我感兴趣的是保持它的更新!