hyperf-ljh / captcha
适用于hyperf的图形验证码
v1.0.2
2023-03-21 06:35 UTC
Requires
- php: >=8.0
- ext-fileinfo: *
- ext-imagick: *
- hyperf-ljh/encryption: ^1.0
- hyperf/cache: ^3.0
- hyperf/di: 3.0.*
- hyperf/framework: 3.0.*
- hyperf/validation: ^3.0
Suggests
- swow/swow: Required to create swow components.
This package is auto-updated.
Last update: 2025-03-21 11:03:13 UTC
README
安装
composer require hyperf-ljh/captcha
发布配置
php bin/hyperf.php vendor:publish hyperf-ljh/captcha
字体文件默认发布到
<root>/storage/fonts
目录。 组件依赖hyperf-ljh/encryption
组件加解密key
,依赖hyperf/cache
组件暂存使用过的key
,您需要发布这些组件的配置:
php bin/hyperf.php vendor:publish hyperf-ljh/encryption php bin/hyperf.php vendor:publish hyperf/cache
使用
use Hyperf\Utils\ApplicationContext; use HyperfLjh\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
过期。