$elem = $nfe->taginfNFeSupl($std);
$result = $nfe->montaNFe();
$xml1 = $nfe->getXML();
$chave = $nfe->getChave();
$modelo = $nfe->getModelo();
// Pasta principal onde vai ficar os XML
$pasta = "../../../xml/";
header('Content-type: text/json');
if (!empty($error)) {
// reporta o erro para o usurio
$erros = array($error);
echo json_encode(array("error" => "Erro ao emitir nota", "log" => $erros));
die;
} else {
/*
* SALVA ENTRADA
*/
if (!is_dir($pasta . 'entradas/' . date('Y-m-d'))) {
mkdir($pasta . 'entradas/' . date('Y-m-d'), 0775, true);
}
$filename = $pasta . "entradas/" . date('Y-m-d') . "/" . $chave . ".xml"; // apos assinar salva arquivo
file_put_contents($filename, trim($xml1)); // salva xml assinado
chmod($filename, 0775);
/*
* FIM SALVA ENTRADA
*/
/*
* VERIFICAR O CERTIFICADO
*/
try {
$tools = new Tools($configJson, Certificate::readPfx($content, $senhacert));
$tools->model($modelo);
} catch (\Exception $e) {
echo json_encode(array("error" => "Certificado: " . $e->getMessage()));
die;
}
/*
* FIM CERTIFICADO
*/
/*
* ASSINAR
*/
try {
$response_assina = $tools->signNFe($xml1);
$stdCl = new Standardize($response_assina);
$arr = $stdCl->toArray();
if (!is_dir($pasta . 'assinadas/' . date('Y-m-d'))) {
mkdir($pasta . 'assinadas/' . date('Y-m-d'), 0775, true);
}
$filename_assina = $pasta . "assinadas/" . date('Y-m-d') . "/" . $chave . ".xml"; // apos assinar salva arquivo
file_put_contents($filename_assina, trim($response_assina)); // salva xml assinado
chmod($filename_assina, 0775);
} catch (\Exception $e) {
echo json_encode(array("error" => "Assina: " . str_replace("{http://www.portalfiscal.inf.br/nfe}", "", $e->getMessage())));
die;
}
/*
* FIM ASSINAR
*/
/*
* ENVIO PARA O SEFAZ
*/
try {
$xml_assinado = file_get_contents($pasta . "assinadas/" . date('Y-m-d') . "/" . $chave . ".xml");
$idLote = substr(str_replace(',', '', number_format(microtime(true) * 1000000, 0)), 0, 15);
$response_envio = $tools->sefazEnviaLote([$xml_assinado], $idLote);
$stdCl = new Standardize($response_envio);
$arr_envio = $stdCl->toArray();
if ($arr_envio['cStat'] == 103) { // OK ENVIO
$recibo_envio = $arr_envio['infRec']['nRec'];
} else {
echo json_encode(array("error" => "Envio: " . $arr_envio['xMotivo'] . " (" . $arr_envio['cStat'] . ")"));
die;
}
} catch (\Exception $e) {
echo json_encode(array("error" => "Envio: " . $e->getMessage()));
die;
ele ta dando erro nessa parte, não sei o que seria