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 language: php
php: php:
- 5.4
- 5.5 - 5.5
- 5.6 - 5.6
- hhvm - hhvm
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
} }
], ],
"require": { "require": {
"php": ">=5.4.0", "php": ">=5.5.5",
"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": { "autoload": {
"psr-4": { "psr-4": {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace Anhskohbo\NoCaptcha; namespace Anhskohbo\NoCaptcha;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use GuzzleHttp\Client;
class NoCaptcha class NoCaptcha
{ {
...@@ -23,6 +24,11 @@ class NoCaptcha ...@@ -23,6 +24,11 @@ class NoCaptcha
*/ */
protected $sitekey; protected $sitekey;
/**
* @var \GuzzleHttp\Client
*/
protected $http;
/** /**
* NoCaptcha. * NoCaptcha.
* *
...@@ -33,6 +39,9 @@ class NoCaptcha ...@@ -33,6 +39,9 @@ class NoCaptcha
{ {
$this->secret = $secret; $this->secret = $secret;
$this->sitekey = $sitekey; $this->sitekey = $sitekey;
$this->http = new Client([
'timeout' => 2.0,
]);
} }
/** /**
...@@ -107,22 +116,10 @@ class NoCaptcha ...@@ -107,22 +116,10 @@ class NoCaptcha
*/ */
protected function sendRequestVerify(array $query = []) protected function sendRequestVerify(array $query = [])
{ {
// This taken from: https://github.com/google/recaptcha/blob/master/src/ReCaptcha/RequestMethod/Post.php $response = $this->http->request('POST', static::VERIFY_URL, [
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; 'form_params' => $query,
]);
$context = stream_context_create(array( return json_decode($response->getBody(), true);
'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);
} }
/** /**
......
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