request = $request; $this->captchaService = $captchaService; } /** * get CAPTCHA * * @param string $config * @return \Intervention\Image\ImageManager->response */ public function getCaptcha($config = 'default') { if ($this->request->isMethod('post')) { $captchaKey = $this->request->get('captcha_key', ''); $captcha = $this->request->get('captcha', ''); if (!$this->captchaService->check($captcha, $captchaKey)) { throw new NotAllowedException('验证码不正确'); } return res(true, '验证码正确'); } if (ob_get_contents()) { ob_clean(); } return $this->captchaService->create($config); } /** * get CAPTCHA api * * @param string $config * @return \Intervention\Image\ImageManager->response */ public function getCaptchaApi($config = 'default') { if ($this->request->isMethod('post')) { $captchaKey = $this->request->get('captcha_key', ''); $captcha = $this->request->get('captcha', ''); if (!$this->captchaService->check($captcha, $captchaKey)) { throw new NotAllowedException('验证码不正确'); } return res(true, '验证码正确', 201); } return res($this->captchaService->create($config, true), '获取验证码'); } }