5
I’ve done a lot of research on this and so far I haven’t been able to do anything concrete. Is this possible?
I want to make a form with the key access field and captcha code to be filled in. will soon be sent this data to the portal nfe and return me the information of the nfe.
With this occurs the expired session error.
index php.
Untitled document
<body>
<?php
function recebe_imagem($url, $arquivo, $cookief = "", $cookiej = "") {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
/* if(!empty($cookief)) {
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
}
if(!empty($cookiej)) {
curl_setopt($ch, CURLOPT_COOKIESESSION, "cookie.txt");
} */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0)");
//curl_setopt($ch, ,
$data = curl_exec($ch);
//curl_close ($ch);
$fp = fopen($arquivo, 'w');
fwrite($fp, $data);
fclose($fp);
return $arquivo;
}
?>
<?php
$img = recebe_imagem("http://www.nfe.fazenda.gov.br/scripts/srf/intercepta/captcha.aspx?opt=image ", "receita.gif", "", "receita.txt");
?>
<img src="receita.gif" />
<form method="POST" action="consulta.php">
captcha
<input name='letras' maxlength='4' size='8' />
<br />
codigo acesso
<input name='cnpj' maxlength='44' size='60' />
<input type="submit" />
</form>
</body>
php query.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sem título</title>
</head>
<body>
<?php
$cnpj = $_POST['cnpj'];
$letras = $_POST['letras'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "ContentPlaceHolder1$txtChaveAcessoCompleta=$cnpj&ContentPlaceHolder1$txtCaptcha=$letras&ContentPlaceHolder1$btnConsultar=Continuar");
curl_setopt($ch, CURLOPT_REFERER, "http://www.nfe.fazenda.gov.br/portal/consulta.aspx?tipoConsulta=completa&tipoConteudo=XbSeqxE8pl8= ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, "http://www.nfe.fazenda.gov.br/portal/consultaCompleta.aspx?tipoConteudo=XbSeqxE8pl8= ");
$output = curl_exec($ch);
echo utf8_encode($output);
?>
</body>
Is there any script to run this better?
Valew, the system is running here for testing> http://www.meifacil.com.br/system/estudo/nfe/ ’s test access code> 33110733068883000201550010115687931122936510 .
– adrigoli