From f90dd77358b824ac71964ac9a21da13bf9e315a1 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Wed, 29 Sep 2021 19:13:00 -0500 Subject: [PATCH 1/4] Update dni source --- src/Peru/Jne/Dni.php | 22 +++++----------------- src/Peru/Jne/Endpoints.php | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/Peru/Jne/Dni.php b/src/Peru/Jne/Dni.php index f11c6b6..3460d25 100644 --- a/src/Peru/Jne/Dni.php +++ b/src/Peru/Jne/Dni.php @@ -16,13 +16,6 @@ */ class Dni implements DniInterface { - /** - * JNE Request Token - * - * @var string - */ - private $requestToken = 'Dmfiv1Unnsv8I9EoXEzbyQExSD8Q1UY7viyyf_347vRCfO-1xGFvDddaxDAlvm0cZ8XgAKTaWclVFnnsGgoy4aLlBGB5m-E8rGw_ymEcCig1:eq4At-H2zqgXPrPnoiDGFZH0Fdx5a-1UiyVaR4nQlCvYZzAhzmvWxLwkUk6-yORYrBBxEnoG5sm-Hkiyc91so6-nHHxIeLee5p700KE47Cw1'; - /** * @var ClientInterface */ @@ -47,11 +40,11 @@ public function __construct(ClientInterface $client, DniParser $parser) /** * Override JNE Request token * + * @deprecated * @param string $requestToken */ public function setRequestToken(string $requestToken): void { - $this->requestToken = $requestToken; } /** @@ -63,18 +56,13 @@ public function setRequestToken(string $requestToken): void */ public function get(string $dni): ?Person { - $json = $this->client->post( - Endpoints::CONSULT, - '{"CODDNI": "'.$dni.'"}', - [ - 'Content-Type' => 'application/json;chartset=utf-8', - 'Requestverificationtoken' => $this->requestToken, - ]); + $url = sprintf(Endpoints::CONSULT, $dni); + $json = $this->client->post($url, []); - if ($json === false || !($result = json_decode($json)) || !isset($result->data)) { + if ($json === false || !($result = json_decode($json)) || !isset($result->nombreSoli)) { return null; } - return $this->parser->parse($dni, $result->data); + return $this->parser->parse($dni, $result); } } diff --git a/src/Peru/Jne/Endpoints.php b/src/Peru/Jne/Endpoints.php index 9b5e916..09d5c53 100644 --- a/src/Peru/Jne/Endpoints.php +++ b/src/Peru/Jne/Endpoints.php @@ -6,5 +6,5 @@ final class Endpoints { - public const CONSULT = 'https://aplicaciones007.jne.gob.pe/srop_publico/Consulta/api/AfiliadoApi/GetNombresCiudadano'; + public const CONSULT = 'https://ww1.sunat.gob.pe/ol-ti-itatencionf5030/registro/solicitante?tipDocu=1&numDocu=%s'; } From 89757343754179d8eca390a18d113f8acda5d458 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Wed, 29 Sep 2021 19:13:22 -0500 Subject: [PATCH 2/4] Update parse dni response --- src/Peru/Jne/DniParser.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Peru/Jne/DniParser.php b/src/Peru/Jne/DniParser.php index d359e70..4605561 100644 --- a/src/Peru/Jne/DniParser.php +++ b/src/Peru/Jne/DniParser.php @@ -6,18 +6,13 @@ class DniParser { - public function parse(string $dni, string $raw): ?Person + public function parse(string $dni, $data): ?Person { - $parts = explode('|', $raw); - if (count($parts) !== 3 || empty($parts[0])) { - return null; - } - $person = new Person(); $person->dni = $dni; - $person->apellidoPaterno = $parts[0]; - $person->apellidoMaterno = $parts[1]; - $person->nombres = $parts[2]; + $person->apellidoPaterno = $data->apePatSoli; + $person->apellidoMaterno = $data->apeMatSoli; + $person->nombres = $data->nombreSoli; $person->codVerifica = strval($this->getVerifyCode($dni)); return $person; From 9ca909b40723a4dd663cd0526f610499cfaf2eb5 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Wed, 29 Sep 2021 21:59:45 -0500 Subject: [PATCH 3/4] Update async DNI call --- src/Peru/Jne/Async/Dni.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Peru/Jne/Async/Dni.php b/src/Peru/Jne/Async/Dni.php index 66bc9ee..56daee7 100644 --- a/src/Peru/Jne/Async/Dni.php +++ b/src/Peru/Jne/Async/Dni.php @@ -9,13 +9,6 @@ class Dni { - /** - * JNE Request Token - * - * @var string - */ - private $requestToken = 'Dmfiv1Unnsv8I9EoXEzbyQExSD8Q1UY7viyyf_347vRCfO-1xGFvDddaxDAlvm0cZ8XgAKTaWclVFnnsGgoy4aLlBGB5m-E8rGw_ymEcCig1:eq4At-H2zqgXPrPnoiDGFZH0Fdx5a-1UiyVaR4nQlCvYZzAhzmvWxLwkUk6-yORYrBBxEnoG5sm-Hkiyc91so6-nHHxIeLee5p700KE47Cw1'; - /** * @var ClientInterface */ @@ -41,11 +34,11 @@ public function __construct(ClientInterface $client, DniParser $parser) /** * Override JNE Request token * + * @deprecated unused * @param string $requestToken */ public function setRequestToken(string $requestToken): void { - $this->requestToken = $requestToken; } /** @@ -57,24 +50,16 @@ public function setRequestToken(string $requestToken): void */ public function get(string $dni): PromiseInterface { - $payload = '{"CODDNI": "'.$dni.'"}'; + $url = sprintf(Endpoints::CONSULT, $dni); return $this->client - ->postAsync( - Endpoints::CONSULT, - $payload, - [ - 'Content-Type' => 'application/json;chartset=utf-8', - 'Content-Length' => strlen($payload), - 'Requestverificationtoken' => $this->requestToken, - ]) + ->postAsync($url, null) ->then(function ($json) use ($dni) { - $result = json_decode($json); - if (!$result || !isset($result->data)) { + if ($json === false || !($result = json_decode($json)) || !isset($result->nombreSoli)) { return null; } - return $this->parser->parse($dni, $result->data); + return $this->parser->parse($dni, $result); }); } } From 43a2d7c59c882461edcddc3ba09119afef8e5826 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Mon, 8 Nov 2021 21:41:56 -0500 Subject: [PATCH 4/4] Fix dni parser tests --- tests/Peru/Jne/DniParserTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Peru/Jne/DniParserTest.php b/tests/Peru/Jne/DniParserTest.php index c8c29b8..17c8119 100644 --- a/tests/Peru/Jne/DniParserTest.php +++ b/tests/Peru/Jne/DniParserTest.php @@ -27,7 +27,8 @@ protected function setUp() */ public function testParseDni($dni) { - $person = $this->parser->parse($dni, 'A|B|C'); + $obj = json_decode('{"apeMatSoli": "PATERNO","apePatSoli": "MATERNO","nombreSoli": "NOMBRES"}'); + $person = $this->parser->parse($dni, $obj); $this->assertNotNull($person); $this->assertNotNull($person->codVerifica);