Advertisement
toritoesinocente

Untitled

Nov 9th, 2018
2,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.    //datos de factura RFC emisor, RFC receptor, Total, UUID
  3.    //@toro https://tar.mx/archivo/2018/validar-folio-fiscal-cfdi-con-php-directo-del-sat-2018.html
  4.    $emisor="";
  5.    $receptor="";
  6.    $total="";
  7.    $uuid="";
  8.    //
  9.    $soap = sprintf('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header/><soapenv:Body><tem:Consulta><tem:expresionImpresa>?re=%s&amp;rr=%s&amp;tt=%s&amp;id=%s</tem:expresionImpresa></tem:Consulta></soapenv:Body></soapenv:Envelope>', $emisor,$receptor,$total,$uuid);
  10.    //encabezados
  11.    $headers = [
  12.    'Content-Type: text/xml;charset=utf-8',
  13.    'SOAPAction: http://tempuri.org/IConsultaCFDIService/Consulta',
  14.    'Content-length: '.strlen($soap)
  15.    ];
  16.  
  17.    $url = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc';
  18.    $ch = curl_init();
  19.    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  20.    curl_setopt($ch, CURLOPT_URL, $url);
  21.    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  22.    curl_setopt($ch, CURLOPT_POST, true);
  23.    curl_setopt($ch, CURLOPT_POSTFIELDS, $soap);
  24.    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  25.    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  26.    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  27.    $res = curl_exec($ch);
  28.    curl_close($ch);
  29.    $xml = simplexml_load_string($res);
  30.    $data = $xml->children('s', true)->children('', true)->children('', true);
  31.    $data = json_encode($data->children('a', true), JSON_UNESCAPED_UNICODE);
  32.    print_r(json_decode($data));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement