public function sefazDistDFe($fonte = 'AN', $tpAmb = '2', $cnpj = '', $ultNSU = 0, $numNSU = 0, &$aRetorno = array())
{
if ($tpAmb == '') {
$tpAmb = $this->aConfig['tpAmb'];
}
$siglaUF = $this->aConfig['siglaUF'];
if ($cnpj == '') {
$cnpj = $this->aConfig['cnpj'];
}
//carrega serviço
$servico = 'NfeDistribuicaoDFe';
$this->zLoadServico('nfe', $servico, $fonte, $tpAmb);
if ($this->urlService == '') {
$msg = "A distribuição de documento DFe não está disponível na SEFAZ {$fonte}!!!";
throw new Exception\RuntimeException($msg);
}
$cUF = self::getcUF($siglaUF);
$ultNSU = str_pad($ultNSU, 15, '0', STR_PAD_LEFT);
$tagNSU = "<distNSU><ultNSU>{$ultNSU}</ultNSU></distNSU>";
if ($numNSU != 0) {
$numNSU = str_pad($numNSU, 15, '0', STR_PAD_LEFT);
$tagNSU = "<consNSU><NSU>{$numNSU}</NSU></consNSU>";
}
//monta a consulta
$cons = "<distDFeInt xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<tpAmb>{$tpAmb}</tpAmb>" . "<cUFAutor>{$cUF}</cUFAutor>" . "<CNPJ>{$cnpj}</CNPJ>{$tagNSU}</distDFeInt>";
//validar mensagem com xsd
//if (! $this->validarXml($cons)) {
// $msg = 'Falha na validação. '.$this->error;
// throw new Exception\RuntimeException($msg);
//}
//montagem dos dados da mensagem SOAP
$body = "<nfeDistDFeInteresse xmlns=\"{$this->urlNamespace}\">" . "<nfeDadosMsg xmlns=\"{$this->urlNamespace}\">{$cons}</nfeDadosMsg>" . "</nfeDistDFeInteresse>";
//envia dados via SOAP e verifica o retorno este webservice não requer cabeçalho
$this->urlHeader = '';
$retorno = $this->oSoap->send($this->urlService, $this->urlNamespace, $this->urlHeader, $body, $this->urlMethod);
$lastMsg = $this->oSoap->lastMsg;
$this->soapDebug = $this->oSoap->soapDebug;
//salva mensagens
$tipoNSU = (int) ($numNSU != 0 ? $numNSU : $ultNSU);
$datahora = date('Ymd_His');
$filename = "{$tipoNSU}-{$datahora}-distDFeInt.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg);
$filename = "{$tipoNSU}-{$datahora}-retDistDFeInt.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $retorno);
//tratar dados de retorno
$aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno);
return (string) $retorno;
}