Download Nfe / NFEPHP

Asked

Viewed 2,217 times

4

Good morning, I am consulting the Nfe of a certain client, so far so good, is returning the Key notes all right, but when I use the download option, the same returns 'Paralyzed Service without Forecast', in a quick read, I noticed that this Download service 'Nfedownloadnf', has been discontinued, I would like to know how to download Nfe using 'Nfedistribuicaodfe', follows code snippet...

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
require_once '../../bootstrap.php';
use NFePHP\NFe\ToolsNFe;
$nfe = new ToolsNFe('../../config/config.json');
$nfe->setModelo('55');
$ultNSU = 0;
$numNSU = 0;
$tpAmb = '1';
$cnpj = '';
$aResposta = array();
$aRespostaDownload = array();
$xml = $nfe->sefazDistDFe('AN', $tpAmb, $cnpj, $ultNSU, $numNSU, $aResposta);
foreach ($aResposta['aDoc'] as $k => $v) {
    $xml = simplexml_load_string($v['doc']);
    $xml = get_object_vars($xml);
    if (isset($xml['vNF'])) {
        $dados = array(
            'chnfe' => $xml['chNFe'],
            'cnpj' => $xml['CNPJ'],
            'xnome' => utf8_decode($xml['xNome']),
            'ie' => $xml['IE'],
            'data' => date('Y-m-d H:i:s', strtotime($xml['dhEmi'])),
            'tpnf' => $xml['tpNF'],
            'vnf' => $xml['vNF'],
            'nprot' => $xml['nProt'],
            'csitnfe' => $xml['cSitNFe'],
            'nsu' => $v['NSU']
        );
        $resp = $nfe->sefazDownload($dados['chnfe'], $tpAmb, $cnpj, $aRespostaDownload);
        var_dump($aRespostaDownload);exit();
    }
}
echo '<br><br><PRE>';
echo htmlspecialchars($nfe->soapDebug);
echo '</PRE><BR>';
print_r($aResposta);
echo "<br>";

inserir a descrição da imagem aqui

  • Good morning Felipe, although the request is being made different I have the same problem... confirms to me if the webservice you are using is this: * https://hom.nfe.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx*

  • I am using 'https://www.nfe.fazenda.gov.br/NfeDownloadNF/NfeDownloadNF.asmx'

  • in some places even talk possible problem with the revenue service, but it doesn’t make sense... because I have another program that is downloading normally... a boy answered me in my question saying that the recipe is changing some validations... follows the link that he made available: http://www.contabeis.com.br/noticias/35193/cfc-alert_overdreations-validations-fiscals-electronicnotations-electronic/

  • Yeah, I also read something about using 'Nfedistribuicaodfe' to download the xml, but I don’t know how...

2 answers

1


This service went off the air even, now only with sefazDistDFe, it returns all the access keys that were issued against the CNPJ digital certificate configured in NFEPHP, here I use version 4.00 of the NFEPHP API, you need to understand how ULTNSU works, through it you will download all the xml’s in "real time" (because it depends on the SEFAZ).

whereas you have studied in ultNSU let’s go step by step.

1º it only provides you up to 50 documents(DF-e) per HOUR.

2º you can only call this function from hour to hour if the return is less than 50 and if there is document without the manifest if not you will be temporarily blocked by SEFAZ (read the NT).

3º obtaining the relation of nfs(access keys) you need MANIFEST-LAS(NT) to get the xml with legal validity, I use the MANIFESTO 210210(Science of Operation) because it is only manifestation that leaves the note to see even since you did not receive it physically, file in the examples folder(4.00testaManifesta.php).

4º after the manifest executes the function sefazDistDFe again, even if it has already run within an hour since it executed the manifest before, ATTENTION TO ultNSU.

5º in this last run if you do IstDFe it will already return (zipped) the xml with legal validity, gzdecode($base64_returned.

  • Please do not add email in reply.

0

Felipe, stick to the technical standard NT 2014.002.v.1.02. Where is clear in the quote:

Date of deactivation of Web Services Nfeconsultadest and Nfedownloadnf: 02/05/2017;

Therefore, both services are disabled. Now one should work with the service Nfedistribuicaodfe, that works with ideology of events and participants of the document. I recommend reading this technical standard of implementation:

https://www.nfe.fazenda.gov.br/portal/exibirArquivo.aspx?conteudo=VcEhGZODuo4=

This service changes completely, and it is no longer possible to download via access key, as the documents are distributed according to their availability in the AN environment.

  • OK Junior understood this part, you would have an xml to demonstrate how the query would look with the access key, as described in the documentation 'consChNFe' and 'chNFe'?

  • great, I was able to download the nfe

  • 1 vote against Accept The webservice Downloadnfe has been disabled as per NT 2014.002.v.1.02. The webservice you should use is: https://www1.nfe.fazenda.gov.br/NFeDistribuicaDFe/NFeDistribuicaDFe.asmx In this webservice you perform the recipient manifestation and in the next query it returns the full Nfe XML. Follow link of technical note: Technical Note 2014.002 - v1.02

Browser other questions tagged

You are not signed in. Login or sign up in order to post.