1
I am trying to issue a tax coupon in PHP by ultilizing sped-nfe. XML files are being generated. Signed Xmls are also, at the time of sending the recipe, I get the following error:
{"error":"Envio: An error occurred while trying to communication via soap, unable to load client cert: -8018 (SEC_ERROR_UNKNOWN_PKCS11_ERROR) [https:\/\/nfce-homologacao.svrs.rs.gov.br\/ws\/NfeAutorizacao\/NFeAutorizacao4.asmx]"}
I have already checked the path and password of certificate A1, both are correct, and when they are not, the error is different. I also checked the validity of the certificate, and it’s all right with him.
try {
$xml_assinado = file_get_contents($pasta."assinadas/".$chave.".xml");
$idLote = substr(str_replace(',', '', number_format(microtime(true)*1000000, 0)), 0, 15);
$response_envio = $tools->sefazEnviaLote([$xml_assinado], $idLote); // O erro é na chamada dessa função
var_dump($xml_assinado);
$stdCl = new Standardize($response_envio);
var_dump($xml_assinado);
$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;
}
Sending function:
public function sefazEnviaLote(
$aXml,
$idLote = '',
$indSinc = 0,
$compactar = false,
&$xmls = []
) {
if (!is_array($aXml)) {
throw new InvalidArgumentException('Envia Lote: XMLs de NF-e deve ser um array!');
}
if ($indSinc == 1 && count($aXml) > 1) {
throw new InvalidArgumentException('Envio sincrono deve ser usado para enviar '
. 'uma UNICA nota por vez. Você está tentando enviar varias.');
}
$servico = 'NfeAutorizacao';
$this->checkContingencyForWebServices($servico);
if ($this->contingency->type != '') {
// Em modo de contingencia esses XMLs deverão ser modificados e re-assinados e retornados
// no parametro $xmls para serem armazenados pelo aplicativo pois serão alterados.
foreach ($aXml as $doc) {
//corrigir o xml para o tipo de contigência setado
$xmls[] = $this->correctNFeForContingencyMode($doc);
}
$aXml = $xmls;
}
$ax = [];
foreach ($aXml as $xml) {
$ax[] = trim(preg_replace("/<\?xml.*?\?>/", "", $xml));
}
$sxml = trim(implode("", $ax));
$this->servico($servico, $this->config->siglaUF, $this->tpAmb);
$request = "<enviNFe xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
. "<idLote>$idLote</idLote>"
. "<indSinc>$indSinc</indSinc>"
. "$sxml"
. "</enviNFe>";
$this->isValid($this->urlVersion, $request, 'enviNFe');
$this->lastRequest = $request;
//montagem dos dados da mensagem SOAP
$parameters = ['nfeDadosMsg' => $request];
$body = "<nfeDadosMsg xmlns=\"$this->urlNamespace\">$request</nfeDadosMsg>";
if ($compactar) {
$gzdata = base64_encode(gzencode($request, 9, FORCE_GZIP));
$parameters = ['nfeDadosMsgZip' => $gzdata];
$body = "<nfeDadosMsgZip xmlns=\"$this->urlNamespace\">$gzdata</nfeDadosMsgZip>";
}
$this->lastResponse = $this->sendRequest($body, $parameters);
return $this->lastResponse;
}
/**
* Check status of Batch of NFe sent by receipt of this shipment
* @param string $recibo
* @param int $tpAmb
* @return string
* @throws InvalidArgumentException
*/
public function sefazConsultaRecibo($recibo, $tpAmb = null)
{
if (empty($recibo)) {
throw new InvalidArgumentException('Consulta Recibo: numero do recibo vazio!');
}
if (empty($tpAmb)) {
$tpAmb = $this->tpAmb;
}
//carrega serviço
$servico = 'NfeRetAutorizacao';
$this->checkContingencyForWebServices($servico);
$this->servico($servico, $this->config->siglaUF, $tpAmb);
if ($this->urlService == '') {
$msg = "A consulta de NFe nao esta disponivel na SEFAZ {$this->config->siglaUF}!";
throw new RuntimeException($msg);
}
$request = "<consReciNFe xmlns=\"$this->urlPortal\" versao=\"$this->urlVersion\">"
. "<tpAmb>$tpAmb</tpAmb>"
. "<nRec>$recibo</nRec>"
. "</consReciNFe>";
$this->isValid($this->urlVersion, $request, 'consReciNFe');
$this->lastRequest = $request;
$parameters = ['nfeDadosMsg' => $request];
$body = "<nfeDadosMsg xmlns=\"$this->urlNamespace\">$request</nfeDadosMsg>";
$this->lastResponse = $this->sendRequest($body, $parameters);
return $this->lastResponse;
}
Sorry for the extension of the codes
Environment: Fedora 26
takes a look if the path where temporary files are saved you have write permission
– Lucas Miranda
They are with all persmissões, the files can be saved, I just can’t communicate and receive the xml from Sefaz (approved or not)
– Jaffe.Marques
then it may be a problem in encryption, just disable: example: $Soap->setEncriptPrivateKey(false);
– Lucas Miranda
I turned it off, it’s still the same mistake
– Jaffe.Marques
then please show your code for analysis
– Lucas Miranda
I updated the codes
– Jaffe.Marques