PHP code example of canon1014 / captcha-lumen

1. Go to this page and download the library: Download canon1014/captcha-lumen 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/ */

    

canon1014 / captcha-lumen example snippets


    $app->register(Canon\CaptchaLumen\CaptchaServiceProvider::class);
    class_alias('Canon\CaptchaLumen\Facades\Captcha','Captcha');

/**
 * captcha set
 */
config(['captcha'=>
    [
        'useful_time' => 5, //验证码有效时间(分钟)
        'captcha_characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ',
        'sensitive' => false, //验证码是否判断大小写
        'login'   => [ //验证码样式
            'length'    => 4, //验证码字数
            'width'     => 120, //图片宽度
            'height'    => 36, //字体大小和图片高度
            'angle'     => 10, //字体倾斜度
            'lines'     => 2, //横线数
            'quality'   => 90, //品质
            'invert'    =>false, //反相
            'bgImage'   =>true, //背景图
            'bgColor'   =>'#ffffff',
            'fontColors'=>['#339900','#ff3300','#9966ff','#3333ff'],//字体颜色
        ],
    ]
]);

# 原版验证
# 因为我修改了存储位置也没有使用该方法作为验证所以已失效,未来将会修改
public function checkCaptcha(Request $request, $type = 'default',$captchaUuid)
{
    $this->validate($request,[
        'captcha'=>'        return $apidoc->loginCaptchaError();
    }

    $sensitive = config('captcha.sensitive');
    if (!$sensitive){
        $captchaCode = strtolower($captchaCode);
        $userCode = strtolower($userCode);
    }

    if($captchaCode == $userCode){
        return $apidoc->loginCaptchaSuccess();
    }

    return $apidoc->loginCaptchaError();
}

{Domain}/captchaInfo/{type?}