<?php
	$rut = $_GET["rut"];
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,"https://gestionapr.cl/public/Auth/create");
	curl_setopt($ch, CURLOPT_POST, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "usuario=puntoblue&clave=pb380380$#");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$data_token = curl_exec ($ch);
	curl_close ($ch);
	$json = json_decode($data_token, true);
	$token = $json["token"];

	$headers = array('Authorization:' . $token);
	
 	$ch = curl_init();        
    curl_setopt($ch, CURLOPT_URL, "https://gestionapr.cl/public/Webpay/consulta_deuda");
    curl_setopt($ch, CURLOPT_POSTFIELDS, "rut=" . $rut);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   
    $result=curl_exec($ch);
    $json = json_decode($result, true);
	
	$salida = array("data" => $json);
	echo json_encode($salida);
?>