xyu / hyperf-captcha
A captcha componet for hyperf .
Installs: 1 306
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
- hyperf/session: ~2.2.0
- psr/container: ^1.0|^2.0
Requires (Dev)
- hyperf/di: ~2.2.0
- hyperf/utils: ~2.2.0
This package is auto-updated.
Last update: 2025-01-10 06:51:00 UTC
README
用于生产验证码,支持Hyperf框架,使用Composer安装,使用该组件需开启hyperf框架中的session组件
composer require xyu/hyperf-captcha
配置定义
组件本身提供了默认配置,即使不做任何设置也可以直接生成验证码,需要对验证码进行自定义配置可以在config/autoload中添加captcha.php进行配置
return [
'fontSize' => env('CAPTCHA_FONTSIZE', 25),
'useCurve' => env('CAPTCHA_USECURVE', true),
'useNoise' => env('CAPTCHA_USENOISE', true),
'imageH' => env('CAPTCHA_IMAGE_WIDTH', 0),
'imageW' => env('CAPTCHA_IMAGE_HEIGHT', 0),
'length' => env('CAPTCHA_LENGTH', 5),
'bg' => env('CAPTCHA_BG', [243, 251, 254]),
'reset' => env('CAPTCHA_RESET', true)
];
直接使用
/**
* @Inject
* @var ContainerInterface
*/
protected $container;
// 生产验证码
$captcha = new Captcha($this->container->get(ConfigInterface::class), $this->container->get(SessionInterface::class));
return $captcha->create();
// 验证
$captcha->check($code);
动态设置
$captcha->setFontSize(25);
$captcha->setImageWidth(100);
$captcha->setImageHeight(50);
$captcha->setLength(4);
$captcha->setUseCurve(true);
$captcha->setUseNoise(true);