-
-
Save miguelarauj1o/1d8103adddb9f7b8fd2c98269f566efa to your computer and use it in GitHub Desktop.
Consulta de informações básicas sobre veículos através da placa utilizando o sistema Sinesp Cidadão.
This file contains hidden or 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
require "uri" | |
require "net/http" | |
require 'base64' | |
require 'cgi' | |
require 'openssl' | |
HOST_KEY = "shienshenlhq" | |
def search_plate plate | |
hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), HOST_KEY.encode("ASCII"), plate.encode("ASCII")) | |
latitude = rand(-90.000000000...90.000000000) | |
longitude = rand(-180.000000000...180.000000000) | |
puts hmac | |
http = Net::HTTP.new('sinespcidadao.sinesp.gov.br', 80) | |
http.use_ssl = false | |
path = '/sinesp-cidadao/ConsultaPlacaNovo27032014' | |
data = %Q{<?xml version="1.0" encoding="utf-8" standalone="yes" ?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><soap:Header><dispositivo>GT-S1312L</dispositivo><nomeSO>Android</nomeSO><versaoAplicativo>1.1.1</versaoAplicativo><versaoSO>4.1.4</versaoSO><aplicativo>aplicativo</aplicativo><ip>177.206.169.90</ip><token>#{hmac}</token><latitude>#{latitude}</latitude><longitude>#{longitude}</longitude></soap:Header><soap:Body><webs:getStatus xmlns:webs="http://soap.ws.placa.service.sinesp.serpro.gov.br/"><placa>#{plate}</placa></webs:getStatus></soap:Body></soap:Envelope>\n/sinesp-cidadao/ConsultaPlaca HTTP/1.1\r<br>\r\n} | |
headers = {'Host' => 'sinespcidadao.sinesp.gov.br', 'Content-Type' => "application/x-www-form-urlencoded; charset=UTF-8", "Accept" => "text/plain, */*; q=0.01", "Cache-Control" => "no-cache", "Pragma" => "no-cache", "x-wap-profile" => "http://wap.samsungmobile.com/uaprof/GT-S7562.xml", "Content-length" => data.size.to_s, "User-Agent" => "Mozilla/5.0 (Linux; U; Android 4.1.4; pt-br; GT-S1162L Build/IMM76I) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"} | |
resp, data = http.post(path, data, headers) | |
puts data.inspect | |
puts Hash.from_xml(resp.body).inspect | |
end | |
search_plate("JKH3791") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment