Thinkphp原生验证码的使用
一. 获取验证码
public function verifyCode(){ $captcha = new hinkcaptchaCaptcha(); $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 hinkcaptchaCaptcha(); $result = $captcha->check($yzm); if ($result === false) return 0; return 1; }