Commit 5831a8aa authored by Nguyen Van Anh's avatar Nguyen Van Anh Committed by GitHub

Merge pull request #55 from Dann-Forked/guzzle-implementation

implement Guzzle usage.
parents f00916fb 889a439b
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
......
......@@ -10,8 +10,9 @@
}
],
"require": {
"php": ">=5.4.0",
"illuminate/support": "5.0.*|5.1.*|5.2.*|5.3.*"
"php": ">=5.5.5",
"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