Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
valida placa para aceitar padrao mercosul e outras melhorias
Browse files Browse the repository at this point in the history
  • Loading branch information
chapeupreto committed Jan 12, 2019
1 parent ecb989e commit e9cd096
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ try {
$veiculo->buscar('GWW-6471');
if ($veiculo->existe()) {
print_r($veiculo->dados());
echo 'O ano do veiculo eh ' , $veiculo->anoModelo, PHP_EOL;
}
} catch (\Exception $e) {
echo $e->getMessage();
Expand Down
18 changes: 7 additions & 11 deletions src/Sinesp.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Sinesp
{
private $secret = '#8.1.0#g8LzUadkEHs7mbRqbX5l';
private $url = 'https://cidadao.sinesp.gov.br/sinesp-cidadao/mobile/consultar-placa/v4';
private $proxy = null;
private $proxy = '';

private $placa = '';
private $response = '';
Expand All @@ -16,7 +16,7 @@ class Sinesp
* Time (in seconds) to wait for a response
* @var int
*/
private $timeout = null;
private $timeout = 0;

public function buscar($placa, array $proxy = [])
{
Expand Down Expand Up @@ -89,10 +89,8 @@ private function obterResposta()
curl_setopt($ch, CURLOPT_PROXY, $this->proxy);
}

if ($this->timeout) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
}
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
Expand Down Expand Up @@ -129,13 +127,11 @@ private function verificarRequisitos()

private function setUp($placa)
{
$placa = $this->ajustar($placa);

if (!$this->validar($placa)) {
throw new \Exception('Placa do veiculo nao especificada ou em formato invalido!');
}

$this->placa = $placa;
$this->placa = $this->ajustar($placa);
}

private function token()
Expand Down Expand Up @@ -174,12 +170,12 @@ private function xml()

private function validar($placa)
{
return preg_match('/^[a-zA-Z]{3}-?\d{4}$/i', $placa);
return preg_match('/^[a-z]{3}-?\d[a-z0-9]{2}\d$/i', trim($placa));
}

private function ajustar($placa)
{
return str_replace(['-', ' '], '', $placa);
return str_replace('-', '', trim($placa));
}

private function latitude()
Expand Down

0 comments on commit e9cd096

Please sign in to comment.