06/07/2017, 16:38
|
| | | Fecha de Ingreso: noviembre-2014 Ubicación: Veracruz
Mensajes: 67
Antigüedad: 9 años, 5 meses Puntos: 0 | |
Obtener datos con cURL Hola!
necesito ayuda, estoy intentando obtener un dato de una pagina de la cual estoy consultando con php y cURL, pero no esta dejando, espero me puedan ayudar dejo el codigo. Código PHP: <?php date_default_timezone_set('America/Mexico_City'); $rpu = $_POST['rpu']; $rpu = str_replace('-', '', $rpu); //$URL = "https://switch.mx/beta/user.do?action=login"; //$conex = curl_init(); $ch = curl_init("https://switch.mx/beta/user.do?action=login"); $data = array("holder" => "amigo", "rpu" => $rpu ) ; $total= array("configData"=>$data,"providerId" => "1"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_COOKIE, "cookie.txt"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("login"=>"[email protected]","password"=>"UsEr123"))); curl_exec ($ch); curl_setopt($ch, CURLOPT_URL, 'https://switch.mx/beta/services.do?action=save'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($total)); $era= curl_exec ($ch); $ena= json_decode($era,true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_POST, false); curl_setopt($ch, CURLOPT_HTTPGET, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); //107615135684 curl_setopt($ch, CURLOPT_URL, 'https://switch.mx/beta/services.do?action=details&serviceId='.$ena['id']); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $consumos= curl_exec ($ch); curl_setopt($ch, CURLOPT_URL, "https://switch.mx/beta/services.do?action=find"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $servicio= curl_exec ($ch); $decodificado=json_decode($servicio, true); $consume=json_decode($consumos, true); $yacon=$consume['serviceData']; $res=array(); $i=0; $dias=0; foreach ($yacon as $name => $value){ $ini = strtotime($value['startDate']); $fin = strtotime($value['endDate']); $datediff = $fin - $ini; $dias += floor($datediff/(60*60*24)); setlocale(LC_ALL, 'es_ES').': '; $res[$i]=array("inicio"=>strtoupper(date('M y', strtotime($value['startDate']))),"final"=>strtoupper(date('M y', strtotime($value['endDate']))),"consumo"=>$value['consumption']); $i++; if ($dias>=340) { break; } } curl_setopt($ch, CURLOPT_URL, 'https://switch.mx/beta/features.do?ServiceId='.$ena['id'].'&rpu='.$rpu.'&name='.$rpu.'&featureId=6&providerId=1'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('application/x-www-form-urlencoded')); $data = curl_exec ($ch); $error = curl_error($ch); $destination = "recibos/".$rpu.".pdf"; $file = fopen($destination, "a+"); fputs($file, $data); fclose($file); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_URL, 'https://switch.mx/beta/services.do?action=delete'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($decodificado['0'])); echo curl_exec ($ch); curl_close ($ch); echo json_encode($res); ?>
__________________ Jorge Luis Garduza Garcia
Analista de Sistemas Web |