public function sefazConsultaRecibo($recibo = '', $tpAmb = '2', &$aRetorno = array(), $saveMensagens = true)
{
if ($recibo == '') {
$msg = "Deve ser informado um recibo.";
throw new Exception\InvalidArgumentException($msg);
}
if ($tpAmb == '') {
$tpAmb = $this->aConfig['tpAmb'];
}
$siglaUF = $this->aConfig['siglaUF'];
//carrega serviço
$servico = 'NfeRetAutorizacao';
$this->zLoadServico('nfe', $servico, $siglaUF, $tpAmb);
if ($this->urlService == '') {
$msg = "A consulta de NFe não está disponível na SEFAZ {$siglaUF}!!!";
throw new Exception\RuntimeException($msg);
}
$cons = "<consReciNFe xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<tpAmb>{$tpAmb}</tpAmb>" . "<nRec>{$recibo}</nRec>" . "</consReciNFe>";
//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 = "<nfeDadosMsg xmlns=\"{$this->urlNamespace}\">{$cons}</nfeDadosMsg>";
//envia a solicitação via SOAP
$retorno = $this->oSoap->send($this->urlService, $this->urlNamespace, $this->urlHeader, $body, $this->urlMethod);
$this->soapDebug = $this->oSoap->soapDebug;
//salva mensagens
if ($saveMensagens) {
$lastMsg = $this->oSoap->lastMsg;
$filename = "{$recibo}-consReciNFe.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg);
$filename = "{$recibo}-retConsReciNFe.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $retorno);
}
//tratar dados de retorno
$aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno);
//podem ser retornados nenhum, um ou vários protocolos
//caso existam protocolos protocolar as NFe e movelas-las para a
//pasta enviadas/aprovadas/anomes
return (string) $retorno;
}