kilofox/hyperf-captcha

为 Hyperf 定制的验证码组件。

v1.0.1 2022-09-15 02:13 UTC

This package is auto-updated.

Last update: 2024-09-15 07:05:38 UTC


README

这是 Hyperf 2 的验证码组件。

Release Version Latest Release Download Total Download

安装

$ composer require kilofox/hyperf-captcha

发布

$ php bin/hyperf.php vendor:publish kilofox/hyperf-captcha

使用

实例化验证码工厂

use Hyperf\Utils\ApplicationContext;
use Kilofox\Captcha\CaptchaFactory;

$captchaFactory = ApplicationContext::getContainer()->get(CaptchaFactory::class);

渲染验证码

$key = $this->request->query('key');
$captcha = $captchaFactory->create($key);

return $captcha->render();

验证验证码

$key = $this->request->input('key', '');
$captcha = $this->request->input('captcha', '');

$captchaFactory->validate($key, $captcha);

支持的验证码样式

  • alpha
  • basic
  • black
  • math
  • riddle
  • word