client = $client; } public function init() { parent::init(); $this->component = Instance::ensure($this->component, Component::class); } /** * @inheritdoc */ protected function validateValue($value) { if (empty($value)) { return [$this->requiredMessage, []]; } $response = $this->client->request('POST', self::SITE_VERIFY_URL, [ 'form_params' => [ 'secret' => $this->component->secret, 'response' => $value, 'remoteip' => Yii::$app->getRequest()->getUserIP(), ], ]); $data = json_decode($response->getBody(), true); if (!isset($data['success'])) { throw new Exception('Invalid recaptcha verify response.'); } return $data['success'] ? null : [$this->message, []]; } }