1: The verification code package needs to be installed.
composer require topthink/think-captcha
2: need to import package
use think\captcha\facade\Captcha;
class Index
{
//输出验证码
public function verify()
{
return Captcha::create();
}
}
3: open session
Open the path: app/middleware.php; uncomment the session in it
4: Need to introduce session and start verification
if(!captcha_check($date['code'])){
// 验证失败
return json(['code'=>'1','msg'=>'验证码错误']);
}