-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Vidal
committed
Sep 7, 2016
0 parents
commit a591449
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "tecactus/reniec-php", | ||
"description": "RENIEC package for PHP", | ||
"keywords": [ | ||
"reniec", | ||
"php", | ||
"dni", | ||
"validar", | ||
"validate", | ||
"consultar", | ||
"consulta dni", | ||
"consulta dni sin codigo captcha", | ||
"captcha" | ||
], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Paul Vidal", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"require": { | ||
"php": ">=5.5.0", | ||
"guzzlehttp/guzzle": "^6.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Tecactus\\Reniec\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# RENIEC-PHP | ||
|
||
## Instalación | ||
|
||
Instalar usando composer: | ||
|
||
```bash | ||
composer require tecactus/reniec-php | ||
|
||
``` | ||
|
||
O agregar la siguiente línea a tu archivo composer.json: | ||
|
||
```json | ||
"require": { | ||
... | ||
"tecactus/reniec-php": "1.*" | ||
... | ||
} | ||
``` | ||
|
||
## Uso | ||
|
||
```php | ||
// incluir el autoloader de vendor | ||
require 'vendor/autoload.php'; | ||
|
||
//crea un objeto de la clase DNI | ||
$reniecDni = new Tecactus\Reniec\DNI('tu-token-de-acceso-personal'); | ||
|
||
print_r($reniecDni->get('12345678')); | ||
|
||
// para devolver el resultado como un array pasar 'true' como segundo argumento. | ||
print_r($reniecDni->get('20131312955', true)); | ||
|
||
``` | ||
|
||
## Token de Acceso Personal | ||
|
||
Para crear tokens de acceso personal debes de iniciar sesión en Tecactus: | ||
|
||
[https://tecactus.com/auth/login](https://tecactus.com/auth/login) | ||
|
||
Si no estas registrado aún, puedes hacerlo en: | ||
|
||
[https://tecactus.com/auth/register](https://tecactus.com/auth/register) | ||
|
||
Debes de activar tu cuenta si aún no lo has hecho. | ||
Luego ver el panel de gestión de Tokens de acceso en: | ||
|
||
[https://tecactus.com/developers/configuracion/tokens](https://tecactus.com/developers/configuracion/tokens) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Tecactus\Reniec; | ||
|
||
|
||
use GuzzleHttp\Client; | ||
use Tecactus\Reniec\Exception\InvalidDniException; | ||
|
||
class DNI | ||
{ | ||
protected $client; | ||
protected $baseUri; | ||
protected $apiToken; | ||
|
||
public function __construct($apiToken) | ||
{ | ||
$this->baseUri = "https://tecactus.com/"; | ||
$this->apiToken = $apiToken; | ||
$this->client = new Client(['base_uri' => $this->baseUri, 'headers' => ['Accept' => 'application/json', 'Authorization' => 'Bearer ' . $this->apiToken]]); | ||
} | ||
|
||
public function get($dni, $asArray = false) | ||
{ | ||
if (!$this->validate($dni)) { | ||
throw new InvalidDniException('DNI number seems not to be valid.'); | ||
} | ||
$response = $this->client->request('POST', 'api/reniec/dni', ['query' => [ | ||
'dni' => $dni | ||
]]); | ||
return json_decode($response->getBody()->getContents(), $asArray); | ||
} | ||
|
||
protected function validate($value) | ||
{ | ||
if (is_numeric($value)) { | ||
return strlen($value) == 8; | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Tecactus\Reniec\Exception; | ||
|
||
class InvalidDniException extends \Exception | ||
{ | ||
// | ||
} |