验证码安装命令行
composer require topthink/think-captcha
如果是做api接口,验证码安装好后要配置路由,配置规则如下:
//验证码路由
Route::get('captcha','Login/captcha');
多应用路由
//多应用路由
Route::get('captcha/[:config]','\think\captcha\CaptchaController@index');
验证码需要开启全局session
打开app/middleware.php文件,将thinkmiddlewareSessionInit::class 注释去掉就可以了
自定义验证码需引用门面模式下的Captcha中的create()创建验证码
use thinkcaptchafacadeCaptcha; class Login extends Common { public function captcha() { //生成验证码 $captcha = Captcha::create(); //生成验证码路径 $url = Request::url(true); //生成数据集 $data = [$url,$captcha]; //返回api接口 return $this->ReturnApi($data,'验证码请求成功!',200,'json'); }



