PHP code example of hyperf-ext / captcha

1. Go to this page and download the library: Download hyperf-ext/captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hyperf-ext / captcha example snippets


use Hyperf\Utils\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);
shell
php bin/hyperf.php vendor:publish hyperf-ext/captcha
shell
php bin/hyperf.php vendor:publish hyperf-ext/encryption
php bin/hyperf.php vendor:publish hyperf/cache