public function sefazStatus($siglaUF = '', $tpAmb = '2', &$aRetorno = array(), $salvarMensagens = true)
{
if ($tpAmb == '') {
$tpAmb = $this->aConfig['tpAmb'];
}
if ($siglaUF == '') {
$siglaUF = $this->aConfig['siglaUF'];
}
//carrega serviço
$servico = 'NfeStatusServico';
$this->zLoadServico('nfe', $servico, $siglaUF, $tpAmb);
if ($this->urlService == '') {
$msg = "O status não está disponível na SEFAZ {$siglaUF}!!!";
throw new Exception\RuntimeException($msg);
}
$cons = "<consStatServ xmlns=\"{$this->urlPortal}\" versao=\"{$this->urlVersion}\">" . "<tpAmb>{$tpAmb}</tpAmb><cUF>{$this->urlcUF}</cUF>" . "<xServ>STATUS</xServ></consStatServ>";
//valida mensagem com xsd
//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>";
//consome o webservice e verifica o retorno do SOAP
$retorno = $this->oSoap->send($this->urlService, $this->urlNamespace, $this->urlHeader, $body, $this->urlMethod);
$lastMsg = $this->oSoap->lastMsg;
$this->soapDebug = $this->oSoap->soapDebug;
if ($salvarMensagens) {
$datahora = date('Ymd_His');
$filename = $siglaUF . "_" . "{$datahora}-consStatServ.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $lastMsg);
$filename = $siglaUF . "_" . "{$datahora}-retConsStatServ.xml";
$this->zGravaFile('nfe', $tpAmb, $filename, $retorno);
}
//tratar dados de retorno
$aRetorno = ReturnNFe::readReturnSefaz($servico, $retorno);
return (string) $retorno;
}