Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.23 KB

captcha.md

File metadata and controls

67 lines (46 loc) · 1.23 KB

图形验证码

通过 后台->系统->系统设置->图像验证码 实现在线设置验证码的生成规则,以快速调整系统验证策略。

定义了一些常见用法方便使用,可以满足大部分常用场景。

\BusyPHP\Captcha // 验证码类
\BusyPHP\facade\Captcha // 验证码工厂类

输出验证码

use \BusyPHP\facade\Captcha;

class CaptchaController {
    
    public function index() {
        return Captcha::id('login')->width(100)->height(40)->response();
    }
}

在线验证码

use \BusyPHP\facade\Captcha;

class CaptchaController {

    public function index() {
        return '<img src="'. Captcha::id('login')->url() .'"/>';
    }
}

校验验证码

use \BusyPHP\facade\Captcha;
use \BusyPHP\exception\VerifyException;

try {
    Captcha::id('login')->check(input('post.code'));
} catch (VerifyException $e) {
    $e->getMessage();
    
    // 未输入验证码
    $e->getField() == Captcha::VERIFY_EMPTY_CODE;
    
    // 验证码错误
    $e->getField() == Captcha::VERIFY_ERROR;
    
    // 验证码过期
    $e->getField() == Captcha::VERIFY_EXPIRE;
}

清理验证码

use \BusyPHP\facade\Captcha;

Captcha::id('login')->clear();