diaojinlong / captcha
Hyperf3.0框架图片验证码
v3.0.2
2023-08-08 12:35 UTC
Requires
- php: >=8.0
- ext-fileinfo: *
- ext-imagick: *
- ext-swoole: >=4.5
- hyperf/cache: 3.0.*
- hyperf/di: 3.0.*
- hyperf/framework: 3.0.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- mockery/mockery: ^1.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: >=7.0
- swoole/ide-helper: ^4.5
Suggests
- swow/swow: Required to create swow components.
This package is auto-updated.
Last update: 2025-01-09 05:24:44 UTC
README
需要安装 imagick php扩展
安装
composer require diaojinlong/captcha
发布配置
php bin/hyperf.php vendor:publish diaojinlong/captcha
字体文件默认发布到
<root>/storage/fonts
目录。
组件使用 aes
加解密 key
,依赖 hyperf/cache
组件暂存使用过的 key
,您需要发布这些组件的配置:
#生成加密的key,请将key设置.env中的CAPTCHA_AES_KEY=xxxxxxx
php bin/hyperf.php gen:key
php bin/hyperf.php vendor:publish hyperf/cache
使用
use Hyperf\Utils\ApplicationContext; use Diaojinlong\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
过期。
Hyperf2.0请使用,下面组件
composer require hyperf-ext/captcha