PHP code example of 18y / think-jwt-captcha

1. Go to this page and download the library: Download 18y/think-jwt-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/ */

    

18y / think-jwt-captcha example snippets



namespace app\index\controller;

use JwtCaptcha\JwtCaptcha;

class Index
{
	// 验证码配置,详细文档看官方 https://www.kancloud.cn/manual/thinkphp5_1/354122
	private $config = [
	    // 验证码密钥
	    'seKey'    => 'xiadmin.com',
	    // 验证码图片高度
	    'imageH'   => 34,
	    // 验证码图片宽度
	    'imageW'   => 130,
	    // 验证码字体大小(px)
	    'fontSize' => 18,
	    // 验证码位数
	    'length'   => 3,
	    // 是否画混淆曲线  
	    'useCurve'   => false,
	    // 是否添加杂点
	    'useNoise'   => false,
	];

	// 生成验证码
    public function verify()
    {
		$captcha = new JwtCaptcha($this->config);
		return $captcha->getEntry();
    }

    // 验证输入验证码是否正确
    public function verify_check()
    {
    	// 验证码ID
    	$uniqid = '9a721d42b98946876bf6737f6bf89976';
    	// 用户输入验证码
    	$code = 'abb';
		$captcha = new JwtCaptcha($this->config);
	    $result = $captcha->checkCaptcha($uniqid, $code);
	    if(!$result)
	    {
	    	// 验证码错误
	    }
    }
}