Created
October 15, 2015 14:12
-
-
Save acras/3d30ef7f9257361d1548 to your computer and use it in GitHub Desktop.
Exemplo de consulta a NFe em PHP utilizando CURL e a API da Focus NFe (https://focusnfe.com.br/api). Para verificar o envio veja o GIST: https://gist.github.com/acras/1e9bb6edde3fdbaac081
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"; | |
$ch = curl_init(); | |
$ref = 1; //Substituir pela sua identificação interna da nota | |
// caso queira usar o formato YAML, use a linha abaixo | |
// curl_setopt($ch, CURLOPT_URL, $SERVER."/nfe2/consultar?ref=" . $ref . "&token=" . $TOKEN); | |
// formato JSON | |
curl_setopt($ch, CURLOPT_URL, $SERVER."/nfe2/consultar.json?ref=" . $ref . "&token=" . $TOKEN); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array()); | |
$body = curl_exec($ch); | |
$result = curl_getinfo($ch, CURLINFO_HTTP_CODE); | |
//as três linhas abaixo imprimem as informações retornadas pela API, aqui o seu sistema deverá | |
//interpretar e lidar com o retorno | |
print("STATUS: ".$result."\n"); | |
print("BODY: ".$body."\n\n"); | |
print(""); | |
curl_close($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment