site_key = $site_key; $this->secret_key = $secret_key; $this->color = $options['color'] ?? 'normal'; $this->lang = $options['lang'] ?? 'lang'; $this->size = $options['size'] ?? 'normal'; $this->size = $options['theme'] ?? 'light'; $this->callback = $options['callback'] ?? ''; } /** * Verify Captcha challenge id * @param string $challenge_id * @return bool */ public function verify(string $challenge_id): bool { try { $response = $this->post($this->api_base_uri . 'siteverify', ['challenge_id' => $challenge_id, 'site_key' => $this->site_key, 'secret_key' => $this->secret_key]); } catch (Exception $e) { return false; } return $response['success'] ?? false; } /** * Get ArCaptcha Script * @return string */ public function getScript(): string { return sprintf('', $this->script_url); } /** * Get Arcaptcha Widget * @return string */ public function getWidget(): string { return sprintf( '
', $this->site_key, $this->color, $this->lang, $this->size, $this->theme, $this->callback ); } private function post($url, $body) { $options = array( 'http' => array( 'method' => 'POST', 'content' => json_encode($body), 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return json_decode($result, true); } }