· 8 years ago · Feb 01, 2018, 06:38 PM
1<?php
2
3namespace Cia\Services\Bus\Helpers;
4
5use Cia\Services\Bus\Service;
6
7/**
8 * Class ConsultaPlaca
9 *
10 * @package Cia\Services\Bus\Helpers\ConsutaPlaca
11 */
12
13
14
15
16class SinespPlaca extends Service {
17
18
19 private $secretKey = 'Mw6HqdLgQsX41xAGZgsF';
20 private $version;
21 private $url = [
22 'v1' => 'https://cidadao.sinesp.gov.br/sinesp-cidadao/mobile/consultar-placa/v2',
23 'v2' => 'https://189.9.194.154/sinesp-cidadao/mobile/consultar-placa/v3'
24 ];
25 private $placa = '';
26
27
28 public function consultaPlaca($placa, $version = 'v1') {
29 $this->placa = str_replace(['-', ' '], '', $placa);
30 $this->version = $version;
31 $response = $this->postXML($this->url[$this->version], $this->xml());
32 $response = str_ireplace(['soap:', 'ns2:'], '', $response);
33 $response = utf8_encode($response);
34 return (array) simplexml_load_string($response)->Body->getStatusResponse->return;
35 }
36
37 private function generateToken() {
38 if($this->version == 'v1') {
39 return hash_hmac('sha1', $this->placa,$this->placa . $this->secretKey);
40 } else {
41 return hash_hmac('sha1', $this->placa,$this->placa . '#8.1.0#' . $this->secretKey);
42 }
43 }
44
45
46
47 private function xml() {
48 $xml=<<<EOX
49<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
50<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
51 <v:Header>
52 <b>Google Android SDK built for x86</b>
53 <c>ANDROID</c>
54 <d>8.1.0</d>
55 <e>4.3.2</e>
56 <f>10.0.2.15</f>
57 <g>%s</g>
58 <h>0.0</h>
59 <i>0.0</i>
60 <k></k>
61 <l>%s</l>
62 <m>8797e74f0d6eb7b1ff3dc114d4aa12d3</m>
63 </v:Header>
64 <v:Body>
65 <n0:getStatus xmlns:n0="http://soap.ws.placa.service.sinesp.serpro.gov.br/">
66 <a>%s</a>
67 </n0:getStatus>
68 </v:Body>
69</v:Envelope>
70EOX;
71 return sprintf($xml, $this->generateToken(), strftime('%Y-%m-%d %T'), $this->placa);
72 }
73
74 protected function getJsonHeader()
75 {
76 return ['Content-Type' => 'text/xml'];
77 }
78
79
80}