diff --git a/README.md b/README.md index 80eec4e..2d2efc0 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Para evitar problemas com indisponibilidade de serviços, a consulta é realizad * [Correios](http://www.buscacep.correios.com.br/sistemas/buscacep/) * [Viacep](https://viacep.com.br/) * [CEP Aberto](http://cepaberto.com/) -* [Widenet](https://apps.widenet.com.br/busca-cep/api-de-consulta) +* [Api CEP (Antigo Widenet)](https://apicep.com/) * [Republica Virtual](https://www.republicavirtual.com.br/cep/) A library irá retornar para você a resposta mais rápida, aumentando assim a performance da consulta. diff --git a/src/CepGratis.php b/src/CepGratis.php index 8548edc..1a83e5b 100644 --- a/src/CepGratis.php +++ b/src/CepGratis.php @@ -7,11 +7,11 @@ use Prhost\CepGratis\Contracts\ProviderContract; use Prhost\CepGratis\Exceptions\CepGratisInvalidParameterException; use Prhost\CepGratis\Exceptions\CepGratisTimeoutException; +use Prhost\CepGratis\Providers\ApiCepProvider; use Prhost\CepGratis\Providers\CepAbertoProvider; use Prhost\CepGratis\Providers\CorreiosProvider; use Prhost\CepGratis\Providers\RepublicaVirtualProvider; use Prhost\CepGratis\Providers\ViaCepProvider; -use Prhost\CepGratis\Providers\WidenetProvider; /** * Class to query CEP. @@ -64,7 +64,7 @@ public static function search(string $cep, array $options = [], int $timeout = n $cepGratis->addProvider(new ViaCepProvider()); $cepGratis->addProvider(new CorreiosProvider()); - $cepGratis->addProvider(new WidenetProvider()); + $cepGratis->addProvider(new ApiCepProvider()); $cepGratis->addProvider(new CepAbertoProvider()); $cepGratis->addProvider(new RepublicaVirtualProvider()); diff --git a/src/Clients/CurlHttpClient.php b/src/Clients/CurlHttpClient.php index 18ac132..30db3de 100644 --- a/src/Clients/CurlHttpClient.php +++ b/src/Clients/CurlHttpClient.php @@ -80,6 +80,7 @@ private function createCurl($uri, array $data = []) curl_setopt_array($curl, [ CURLOPT_URL => $uri, CURLOPT_RETURNTRANSFER => true, + CURLOPT_SSL_VERIFYPEER => false ]); if ($this->headers) { diff --git a/src/Providers/WidenetProvider.php b/src/Providers/ApiCepProvider.php similarity index 64% rename from src/Providers/WidenetProvider.php rename to src/Providers/ApiCepProvider.php index 08a08eb..4489625 100644 --- a/src/Providers/WidenetProvider.php +++ b/src/Providers/ApiCepProvider.php @@ -6,24 +6,27 @@ use Prhost\CepGratis\Contracts\HttpClientContract; use Prhost\CepGratis\Contracts\ProviderContract; -class WidenetProvider implements ProviderContract +class ApiCepProvider implements ProviderContract { /** * @return Address|null */ public function getAddress($cep, HttpClientContract $client, array $option = []) { - $response = $client->get('http://apps.widenet.com.br/busca-cep/api/cep/' . $cep . '.json'); + $response = $client->get('https://ws.apicep.com/busca-cep/api/cep/' . $cep . '.json'); if (!is_null($response)) { $content = json_decode($response); if (is_object($content) && !isset($content->erro)) { - if (isset($content->status) && $content->status == 0) { + if (isset($content->status) && ($content->status == 0 || $content->status == 404)) { return null; } - $address = trim(explode('- até', $content->address)[0]); - $address = trim(explode('- de', $address)[0]); + $address = ''; + if ($content->address) { + $address = trim(explode('- até', $content->address)[0] ?? ''); + $address = trim(explode('- de', $address)[0] ?? ''); + } return Address::create([ 'zipcode' => $cep, diff --git a/src/Providers/RepublicaVirtualProvider.php b/src/Providers/RepublicaVirtualProvider.php index 0d9c678..cfd2395 100644 --- a/src/Providers/RepublicaVirtualProvider.php +++ b/src/Providers/RepublicaVirtualProvider.php @@ -21,7 +21,7 @@ public function getAddress($cep, HttpClientContract $client, array $option = []) return Address::create([ 'zipcode' => $cep, - 'street' => $content->tipo_logradouro . ' ' . $content->logradouro, + 'street' => trim($content->tipo_logradouro . ' ' . $content->logradouro), 'neighborhood' => $content->bairro, 'city' => $content->cidade, 'state' => $content->uf,