Last active
July 29, 2017 23:31
-
-
Save herenow/ddcf5e97015e00b42feeb2e5b10c35cf to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
$cep = str_replace('-', '', $POST['id']); | |
$url = 'http://api.postmon.com.br/v1/cep/'.$cep; | |
$handle = curl_init(); | |
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($handle, CURLOPT_URL, $url); | |
$response = curl_exec($handle); | |
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
curl_close($handle); | |
if($httpCode == 200) { | |
$dados = json_decode($response, true); | |
$requestedCidade = $_POST['cidade']; | |
$requestedEstado = $_POST['estado']; | |
$returnedCidade = $dados['cidade']; | |
$returnedEstado = $dados['estado']; | |
if($requestedEstado != "" && $requestedEstado != $returnedEstado) { | |
$data = 2; | |
} | |
else { | |
$data = array( | |
'cidade' => $returnedCidade, | |
'endereco' => $dados['logradouro'], | |
'bairro' => $dados['bairro'], | |
'uf' => $returnedEstado, | |
'script' => '<script>$(".img-loader").hide(0); $(".img-ok").show(0);</script>' | |
); | |
} | |
} | |
else { | |
$data = 1; | |
} | |
// Valor final para ser interpretado pelo javascript(SEMPRE json_encode) | |
echo json_encode($data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment