<?php

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => 'https://sefin.nfse.gov.br/sefinnacional/danfse/41191521200059799000191000000003377323110000012442',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_SSLCERT => realpath('certificado.pfx'),
    CURLOPT_SSLCERTPASSWD => '123456',
    CURLOPT_SSLCERTTYPE => 'P12',
));

$response = curl_exec($curl);

curl_close($curl);

file_put_contents('danfse.txt', '');

file_put_contents('shared/pdf/danfse.pdf', $response);
?>
