public function submit(RequestParameters $params) { $errno = 0; $errstr = ''; if ($this->socket->fsockopen('ssl://' . self::RECAPTCHA_HOST, 443, $errno, $errstr, 30) !== false) { $content = $params->toQueryString(); $request = "POST " . self::SITE_VERIFY_PATH . " HTTP/1.1\r\n"; $request .= "Host: " . self::RECAPTCHA_HOST . "\r\n"; $request .= "Content-Type: application/x-www-form-urlencoded\r\n"; $request .= "Content-length: " . strlen($content) . "\r\n"; $request .= "Connection: close\r\n\r\n"; $request .= $content . "\r\n\r\n"; $this->socket->fwrite($request); $response = ''; while (!$this->socket->feof()) { $response .= $this->socket->fgets(4096); } $this->socket->fclose(); if (0 === strpos($response, 'HTTP/1.1 200 OK')) { $parts = preg_split("#\n\\s*\n#Uis", $response); return $parts[1]; } return self::BAD_RESPONSE; } return self::BAD_REQUEST; }
public function submit(RequestParameters $params) { /* * * PHP 5.6.0 changed the way you specify the peer name for SSL context options. * Using "CN_name" will still work, but it will raise deprecated errors. */ $peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => $params->toQueryString(), 'verify_peer' => true, $peer_key => 'www.google.com')); $context = stream_context_create($options); return file_get_contents(self::SITE_VERIFY_URL, false, $context); }
/** * @param null|string $dataSourceParameters */ public function setParams($dataSourceParameters) { $this->params = new RequestParameters(); if ($dataSourceParameters !== null) { $this->params->set($dataSourceParameters); } $code = $this->params->getParameter(RequestParameters::OUTPUT_TYPE_PARAMETER); $this->outputType = new OutputType($code); }
/** * @dataProvider provideValidData */ public function testToQueryString($secret, $captchaId, $captchaValue, $expectedArray, $expectedQuery) { $params = new RequestParameters($secret, $captchaId, $captchaValue); $this->assertEquals($params->toQueryString(), $expectedQuery); }
/** * @dataProvider provideValidData */ public function testToQueryString($secret, $response, $remoteIp, $version, $expectedArray, $expectedQuery) { $params = new RequestParameters($secret, $response, $remoteIp, $version); $this->assertEquals($params->toQueryString(), $expectedQuery); }