Commit 6a235eae authored by Daniel Rubin's avatar Daniel Rubin

implement Guzzle usage.

parent f00916fb
......@@ -11,7 +11,8 @@
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*"
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*",
"guzzlehttp/guzzle": "^6.2"
},
"autoload": {
"psr-4": {
......
......@@ -3,6 +3,7 @@
namespace Anhskohbo\NoCaptcha;
use Symfony\Component\HttpFoundation\Request;
use GuzzleHttp\Client;
class NoCaptcha
{
......@@ -23,6 +24,11 @@ class NoCaptcha
*/
protected $sitekey;
/**
* @var \GuzzleHttp\Client
*/
protected $http;
/**
* NoCaptcha.
*
......@@ -33,6 +39,9 @@ class NoCaptcha
{
$this->secret = $secret;
$this->sitekey = $sitekey;
$this->http = new Client([
'timeout' => 2.0,
]);
}
/**
......@@ -107,22 +116,10 @@ class NoCaptcha
*/
protected function sendRequestVerify(array $query = [])
{
// This taken from: https://github.com/google/recaptcha/blob/master/src/ReCaptcha/RequestMethod/Post.php
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name';
$context = stream_context_create(array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($query, '', '&'),
'verify_peer' => true,
$peer_key => 'www.google.com',
),
));
$response = file_get_contents(static::VERIFY_URL, false, $context);
return json_decode($response, true);
$response = $this->http->request('POST', static::VERIFY_URL, [
'form_params' => $query,
]);
return json_decode($response->getBody(), true);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment