PHP code example of hyperf-ljh / captcha

1. Go to this page and download the library: Download hyperf-ljh/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-ljh / captcha example snippets


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);
shell
php bin/hyperf.php vendor:publish hyperf-ljh/captcha
shell
php bin/hyperf.php vendor:publish hyperf-ljh/encryption
php bin/hyperf.php vendor:publish hyperf/cache