Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/07/2017, 16:38
Avatar de jlgarduza
jlgarduza
 
Fecha de Ingreso: noviembre-2014
Ubicación: Veracruz
Mensajes: 67
Antigüedad: 9 años, 5 meses
Puntos: 0
Pregunta 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($chCURLOPT_COOKIEJAR"cookie.txt");
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($chCURLOPT_COOKIE"cookie.txt");
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
curl_setopt($chCURLOPT_FOLLOWLOCATION1);

curl_setopt($chCURLOPT_CUSTOMREQUEST"POST");
curl_setopt($chCURLOPT_POST1);
curl_setopt($chCURLOPT_POSTFIELDSjson_encode(array("login"=>"[email protected]","password"=>"UsEr123")));
curl_exec ($ch);

curl_setopt($chCURLOPT_URL'https://switch.mx/beta/services.do?action=save');
curl_setopt($chCURLOPT_POSTtrue);
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($chCURLOPT_POSTFIELDSjson_encode($total));
$era=  curl_exec ($ch);
$enajson_decode($era,true);

curl_setopt($chCURLOPT_CUSTOMREQUEST"GET");
curl_setopt($chCURLOPT_POSTfalse);
curl_setopt($chCURLOPT_HTTPGETtrue);
curl_setopt($chCURLOPT_AUTOREFERERtrue);
//107615135684
curl_setopt($chCURLOPT_URL'https://switch.mx/beta/services.do?action=details&serviceId='.$ena['id']);
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$consumoscurl_exec ($ch);

curl_setopt($chCURLOPT_URL"https://switch.mx/beta/services.do?action=find");
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$serviciocurl_exec ($ch);

$decodificado=json_decode($serviciotrue);


$consume=json_decode($consumostrue);
$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($chCURLOPT_URL'https://switch.mx/beta/features.do?ServiceId='.$ena['id'].'&rpu='.$rpu.'&name='.$rpu.'&featureId=6&providerId=1');
curl_setopt($chCURLOPT_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($chCURLOPT_CUSTOMREQUEST"POST");

curl_setopt($chCURLOPT_URL'https://switch.mx/beta/services.do?action=delete');
curl_setopt($chCURLOPT_POSTtrue);
curl_setopt($chCURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($chCURLOPT_POSTFIELDSjson_encode($decodificado['0']));
echo 
curl_exec ($ch);
curl_close ($ch);


echo 
json_encode($res);
?>
__________________
Jorge Luis Garduza Garcia
Analista de Sistemas Web