Path: C:\
<?php
$achou='S';$erro='Sem Erro';
error_reporting(E_ALL);
ini_set('display_errors', 'On');
ini_set('max_execution_time', 2000); //300 seconds = 5 minutes
require ('vendor/autoload.php');
use NFePHP\NFe\Tools;
use NFePHP\Common\Certificate;
use NFePHP\NFe\Common\Standardize;
try {
$content = file_get_contents('TransWar.pfx');
$configJson = file_get_contents('config1.json');
$certificate = Certificate::readPfx($content, 'WPS475475');
$tools = new Tools($configJson, $certificate);
$tools->model('55');
$response = $tools->sefazDownload($chave);
$stdCl = new Standardize($response);
$std = $stdCl->toStd();
echo 'config1-->'.$std->cStat.'<br>';
if ($std->cStat != 138)
{ $configJson = file_get_contents('config2.json');
$tools = new Tools($configJson, $certificate);
$tools->model('55');
$response = $tools->sefazDownload($chave);
$stdCl = new Standardize($response);
$std = $stdCl->toStd();
echo 'config2-->'.$std->cStat.'<br>';
if ($std->cStat != 138)
{ $configJson = file_get_contents('config3.json');
$tools = new Tools($configJson, $certificate);
$tools->model('55');
$response = $tools->sefazDownload($chave);
$stdCl = new Standardize($response);
$std = $stdCl->toStd();
echo 'config3-->'.$std->cStat.'<br>';
if ($std->cStat != 138)
{$achou='N';}
}
}
$arquivo="NotasXML/nf-".$nrNF."_1.xml";
header('Content-type: text/xml; charset=UTF-8');
file_put_contents($arquivo,$stdCl);
if ($achou=='S') { include 'montaXML.php'; }
} catch (\Exception $e)
{ $erro='Erro na consulta: '. $e->getMessage(); }
?>