Thinkphp原生验证码的使用

Thinkphp原生验证码的使用

一. 获取验证码

public function  verifyCode(){
        $captcha = new \think\captcha\Captcha();
        $captcha->fontSize = 15;
        $captcha->length   = 4;
        $captcha->useNoise = true;
        $captcha->codeSet = '0123456987789525';
        $src = $captcha->entry();
        return $src;
    }

二. 校验验证码

    public function checkVerifyCode(){
        $post = $this->input['data'];
        $yzm = isset($post['code'])?$post['code']:"";
        if(empty($yzm))return $this->returnJson('10002',[]);
        $captcha = new \think\captcha\Captcha();
        $result = $captcha->check($yzm);
        if ($result === false) return 0;
        return 1;
    }

 

posted @ 2018-12-13 16:37  tatasix  阅读(160)  评论(0编辑  收藏  举报