# hyperf-captcha **Repository Path**: ZedLam/hyperf-captcha ## Basic Information - **Project Name**: hyperf-captcha - **Description**: hyperf3.1的验证码 鸣谢:https://gitee.com/php-lib/hyperf-captcha - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-15 - **Last Updated**: 2024-04-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Hyperf CAPTCHA 组件 ## 安装 ```shell composer require zed-lam/captcha ``` ## 发布配置 ```shell php bin/hyperf.php vendor:publish hyperf-ext/captcha ``` > 字体文件默认发布到 `/storage/fonts` 目录。 组件依赖 `hyperf-ext/encryption` 组件加解密 `key`,依赖 `hyperf/cache` 组件暂存使用过的 `key`,您需要发布这些组件的配置: ```shell php bin/hyperf.php vendor:publish hyperf-ext/encryption php bin/hyperf.php vendor:publish hyperf/cache ``` ## 使用 ```php use Hyperf\Context\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` 过期。 ### 项目使用原地址:https://gitee.com/php-lib/hyperf-captcha