<?php


$url = 'https://sbit1.crtm.es:50480/servicios/spai/rest/carga/programacion/interurbanos/CRTM/oferta';
//$url = 'https://bonotransportepro.grupotecopy.es/bonotransporte/trayecto/rutas';
$registros = array();
$registros [] = array("idconce"=>"VCM-501",
  "nulinges"=>"94092", 
  "nulinuser"=>"4",
  "idsublinea"=>"4092201",
  "denominasub"=>"MÓSTOLES SUR - HOSPITAL REY JUAN CARLOS",
  "sentido"=>2, "longkms"=>8.07, "anio"=>2022, "mes"=>4, "dia"=>1, "calend"=>"2",
  "tphor"=>"2", "nexpedi"=>38, "kmtsreal"=>306.66, "totviaje"=>527, "tipo"=>"PR"
);

//$registros[]=array('id_parada_ruta'=>9777,'cod_tarjeta'=>0,'fecha'=>time()."000");


$datosOferta= array('DatosFicheroProgOferta' => array('NombreFichero'=>'VCM-501_2022_4_PR.JSON','Registros'=>$registros));
//$datosOferta=array('token'=>'eyJzdWIiOiJhZG1pbkB0ZXN0LmVzIiwiY3J','id_conductor'=>'333',"num_pasajeros_totales"=> "1",'trayectos_ciudadano'=>$registros);
echo var_dump(json_encode($datosOferta));
$data = json_encode($datosOferta);
file_put_contents('VCM-501_2022_4_PR.JSON',$data);

$crl = curl_init($url);
curl_setopt($crl, CURLOPT_POST, 1);
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($crl, CURLOPT_POSTFIELDS, $data);
curl_setopt($crl, CURLOPT_HTTPHEADER, array('Accept: application/json','Content-Type: application/json'));
curl_setopt($crl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 10);

$result = curl_exec($crl);

if ($result === FALSE) {
  echo '<br />Err: ';
  die(curl_error($crl));
}
echo "R: ".$result;
echo '<br />Resultado: ' .var_dump(json_decode($result, TRUE)).'<br />';
echo 'Res:'.curl_getinfo($crl,CURLINFO_HTTP_CODE );
curl_close($crl);
?>