hyperf-ext / captcha
The Hyperf CAPTCHA package.
Installs: 5 906
Dependents: 0
Suggesters: 0
Security: 0
Stars: 7
Watchers: 2
Forks: 3
Open Issues: 2
Requires
- php: >=7.3
- ext-fileinfo: *
- ext-imagick: *
- ext-swoole: >=4.5
- hyperf-ext/encryption: ~2.2.0
- hyperf/cache: ~2.2.0
- hyperf/di: ~2.2.0
- hyperf/framework: ~2.2.0
- hyperf/validation: ~2.2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- hyperf/testing: ~2.2.0
- phpstan/phpstan: ^0.12
- swoole/ide-helper: dev-master
This package is auto-updated.
Last update: 2024-10-29 06:00:16 UTC
README
安装
composer require hyperf-ext/captcha
发布配置
php bin/hyperf.php vendor:publish hyperf-ext/captcha
字体文件默认发布到
<root>/storage/fonts
目录。
组件依赖 hyperf-ext/encryption
组件加解密 key
,依赖 hyperf/cache
组件暂存使用过的 key
,您需要发布这些组件的配置:
php bin/hyperf.php vendor:publish hyperf-ext/encryption php bin/hyperf.php vendor:publish hyperf/cache
使用
use Hyperf\Utils\ApplicationContext; use HyperfExt\Captcha\CaptchaFactory; $captchaFactory = ApplicationContext::getContainer()->get(CaptchaFactory::class); // 生成 $captcha = $captchaFactory->create(); $response = [ 'key' => $captcha->getKey(), 'blob' => $captcha->getBlob()->toDataUrl(), 'ttl' => $captcha->getTtl(), ]; // 验证 $captchaFactory->validate($key, $text);
验证器
您可将 key
与用户输入用逗号 ,
连接后传递给 captcha
验证规则来自动完成验证,验证成功的 key
将被自动暂存到缓存中直至该 key
过期。