request = $request; } public function checkCaptcha(ReCaptchaCheckEvent $event) { $requestUrl = "https://www.google.com/recaptcha/api/siteverify"; $secretKey = ReCaptcha::getConfigValue('secret_key'); $requestUrl .= "?secret=$secretKey"; $captchaResponse = $event->getCaptchaResponse(); if (null == $captchaResponse) { $captchaResponse = $this->request->request->get('g-recaptcha-response'); } $requestUrl .= "&response=$captchaResponse"; $remoteIp = $event->getRemoteIp(); if (null == $remoteIp) { $remoteIp = $this->request->server->get('REMOTE_ADDR'); } $requestUrl .= "&remoteip=$remoteIp"; $result = json_decode(file_get_contents($requestUrl), true); if ($result['success'] == true) { $event->setHuman(true); } } public static function getSubscribedEvents() { return [ ReCaptchaEvents::CHECK_CAPTCHA_EVENT => ['checkCaptcha', 128], ]; } }