elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


  Mostrar Temas
Páginas: [1]
1  Programación / PHP / Problemas para cargar pagina mediante curl en: 4 Octubre 2012, 23:51 pm
Hola, que tal, les explico.
Estoy realizando un pequeño script en php para poder enviar datos a la pagina de verificacion de CFDI del SAT, aqui en mexico.
esta es la pagina: https://verificacfdi.facturaelectronica.sat.gob.mx/

Entonces lo que hice fue cargar la pagina con php y curl, lo que me permite obtener la informacion del captcha y cargar la pagina mediante post para que de esa forma poder enviar los datos que solicita la pagina automaticament, sin necesidad de teclean algo.

Pero mi problema es que cuando quiero enviar los parametros mediante curl y post, me carca un error. pero si en mi formulario el action es hacia la pa pagina del sat directamente funciona sin nigun problema.

Sera que alguien tenga alguna idea de porque sucede eso??
aca les paso el codigo de mi script
PAra probar en el formulario, si dejo el action en blanco cargo mi mismo script me me marca un error el resultado de la pagina del SAT, pero si coloco la direccion del SAT, el resultado es correcto.

Gracias de antemano. !!!
saludos.
Código
  1. <?php
  2.  
  3. function post_web_page($url, $option)
  4. {
  5. echo $option;
  6. $ch = curl_init($url);//URL A ENVIAR EL CONTENIDO
  7. $options = array(
  8.     CURLOPT_RETURNTRANSFER => true,     // return web page
  9.        //CURLOPT_HEADER         => false,    // don't return headers
  10.        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  11.        CURLOPT_ENCODING       => "",       // handle all encodings
  12.        //CURLOPT_USERAGENT      => "spider", // who am i
  13.        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
  14.        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  15.        CURLOPT_TIMEOUT        => 120,      // timeout on response
  16.        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
  17. CURLOPT_POST => true,
  18. CURLOPT_POSTFIELDS => $option,
  19. CURLOPT_SSL_VERIFYPEER => true,
  20. CURLOPT_SSL_VERIFYHOST => 2,
  21. CURLOPT_CAINFO => getcwd() . "\GeoTrustGlobalCA.crt",
  22.  
  23.  
  24.    );
  25. //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//OPCIONAL: NO RETORNARA EL RESULTADO DE LA OPERACION
  26.  
  27. curl_setopt_array( $ch, $options );
  28. $content = curl_exec( $ch );
  29.  
  30.    $err     = curl_errno( $ch );
  31.    $errmsg  = curl_error( $ch );
  32.    $header  = curl_getinfo( $ch );
  33.  
  34.  
  35.    $header['errno']   = $err;
  36.    $header['errmsg']  = $errmsg;
  37.    $header['content'] = $content;
  38.    return $header;
  39. }
  40.  
  41. function get_web_page( $url )
  42. {
  43.  
  44.    $options = array(
  45.        CURLOPT_RETURNTRANSFER => true,     // return web page
  46.        CURLOPT_HEADER         => false,    // don't return headers
  47.        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  48.        CURLOPT_ENCODING       => "",       // handle all encodings
  49.        CURLOPT_USERAGENT      => "spider", // who am i
  50.        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
  51.        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  52.        CURLOPT_TIMEOUT        => 120,      // timeout on response
  53.        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
  54. CURLOPT_SSL_VERIFYPEER => false,
  55.  
  56.    );
  57.  
  58.    $ch      = curl_init( $url );
  59.    curl_setopt_array( $ch, $options );
  60.    $content = curl_exec( $ch );
  61.    $err     = curl_errno( $ch );
  62.    $errmsg  = curl_error( $ch );
  63.    $header  = curl_getinfo( $ch );
  64. curl_close( $ch );
  65.  
  66.    $header['errno']   = $err;
  67.    $header['errmsg']  = $errmsg;
  68.    $header['content'] = $content;
  69.    return $header;
  70. }
  71.  
  72. if (empty($_POST)){
  73. $url = 'https://verificacfdi.facturaelectronica.sat.gob.mx/';
  74. $res=get_web_page( $url );
  75.  
  76. $output=str_replace('href="', 'href="https://verificacfdi.facturaelectronica.sat.gob.mx/', $res['content']);
  77. $output=str_replace('src="', 'src="https://verificacfdi.facturaelectronica.sat.gob.mx/', $output);
  78. echo '<div style="display:none">'. $output .'</div>';
  79. ?>
  80. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
  81. <script>
  82.  
  83.  
  84. $(function(){
  85. a=$('#__VIEWSTATE').val();
  86. $('#VIEWSTATE').attr({'value': a});
  87. a=$('#ctl00_MainContent_ImgCaptcha').attr('src');
  88. $('#c').attr('src', a);
  89.  
  90.  
  91.  
  92.  
  93. });
  94.  
  95. </script>
  96. <br/>
  97.  
  98. <form action="" method="post" enctype="application/x-www-form-urlencoded" name="form" id="form" >
  99. <input type="submit" />
  100. <input type="hidden" value="true" name="__ASYNCPOST" />
  101. <input type="hidden" value="" name="__EVENTARGUMENT" />
  102. <input type="hidden" value="" name="__EVENTTARGET" />
  103. <input type="hidden" value="" name="__VIEWSTATE" id="VIEWSTATE" />
  104. <input type="hidden" value="" name="__VIEWSTATEENCRYPTED" />
  105. <input type="hidden" value="Verificar CFDI" name="ctl00$MainContent$BtnBusqueda" />
  106. <input type="text" value="" name="ctl00$MainContent$TxTCaptchaNumbers" id="cap" />
  107. <input type="hidden" value="AXT940727FP8" name="ctl00$MainContent$TxtRfcEmisor" />
  108. <input type="hidden" value="AGU931206CH4" name="ctl00$MainContent$TxtRfcReceptor" />
  109. <input type="hidden" value="EF48422A-1B0D-467F-A9E5-BEEFAD703560" name="ctl00$MainContent$TxtUUID" />
  110. <input type="hidden" value="ctl00$MainContent$UpnlBusqueda|ctl00$MainContent$BtnBusqueda" name="ctl00$ScriptManager1" />
  111. <img id="c" src="" />
  112. </form>
  113.  
  114.  
  115. <?php
  116. }
  117. else
  118. {
  119.  
  120.  
  121. $op = "__ASYNCPOST=true&__EVENTARGUMENT=&__EVENTTARGET=&__VIEWSTATE=".$_POST['__VIEWSTATE']."&__VIEWSTATEENCRYPTED=&ctl00$MainContent$BtnBusqueda=".$_POST['ctl00$MainContent$BtnBusqueda']."&ctl00$MainContent$TxTCaptchaNumbers=".$_POST['ctl00$MainContent$TxTCaptchaNumbers']."&ctl00$MainContent$TxtRfcEmisor=".$_POST['ctl00$MainContent$TxtRfcEmisor']."&ctl00$MainContent$TxtRfcReceptor=:".$_POST['ctl00$MainContent$TxtRfcReceptor']."&ctl00$MainContent$TxtUUID=".$_POST['ctl00$MainContent$TxtUUID']."&ctl00$ScriptManager1=".$_POST['ctl00$ScriptManager1'];
  122.  
  123. $url="https://verificacfdi.facturaelectronica.sat.gob.mx/";
  124. $res = post_web_page($url,$op);
  125. echo htmlentities( $res['content']).'<br/>';
  126. echo $res['errmsg'].'<br/>';
  127. echo   $res['errno'].'<br/>';
  128.  
  129. }
  130. ?>
  131.  
  132.  
  133.  
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines