Last active
October 15, 2015 14:13
-
-
Save acras/cdb3b3bf634c0a988731 to your computer and use it in GitHub Desktop.
Exemplo de consulta a uma NFe enviada pela API do Focus NFe (https://focusnfe.com.br/api). Verifique o envio neste GIST: https://gist.github.com/acras/6e854ecd5fc7b1458c8a
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 | |
// Você deve definir isso globalmente para sua aplicação | |
// Servidor de homologação | |
$SERVER = "http://homologacao.acrasnfe.acras.com.br"; | |
// Servidor de produção | |
//$SERVER = "http://producao.acrasnfe.acras.com.br"; | |
$TOKEN = "token_recebido_do_suporte"; | |
print("=> Teste de consulta\n"); | |
// O processo de envio de NFSe é assíncrono, e pode ser necessário | |
// aguardar até que a nota seja processada | |
sleep(10); | |
// caso queira usar o formato YAML, use a linha abaixo | |
// $r = new HttpRequest($SERVER."/nfe2/consultar", HttpRequest::METH_GET); | |
// formato JSON | |
$r = new HttpRequest($SERVER."/nfe2/consultar.json", HttpRequest::METH_GET); | |
$r->addQueryData(array('token' => $TOKEN)); | |
$r->addQueryData(array('ref' => '1')); | |
try { | |
$r->send(); | |
$status = $r->getResponseCode(); | |
$body = $r->getResponseBody(); | |
print("Status = $status\n"); | |
print("Body = $body\n"); | |
// caso queira usar o formato YAML, use a linha abaixo (necessário biblioteca PECL yaml) | |
// $result = yaml_parse($body); | |
// formato JSON | |
$result = json_decode($body); | |
var_dump($result); | |
} catch (HttpException $ex) { | |
echo $ex; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment