thinkphp6 验证码使用

1:需要安装验证码包。

composer require topthink/think-captcha

2:需要引入包

use think\captcha\facade\Captcha;

class Index 
{
    //输出验证码
	public function verify()
    {
        return Captcha::create();    
    }
}

3:开启session

开启路径:app/middleware.php;将其中的session的注释取消

4:需要引入session然后开始验证

		if(!captcha_check($date['code'])){
		 // 验证失败	
			 return json(['code'=>'1','msg'=>'验证码错误']);
		}

猜你喜欢

转载自blog.csdn.net/munchmills/article/details/128460252