Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // API Interract
- function getTrains($api_sncf_user, $api_sncf_mdp, $VilleDepart, $VilleArrivee, $date, $NbJourneys){
- try {
- $url= "https://".$api_sncf_user."@api.sncf.com/v1/coverage/sncf/journeys?from=".$VilleDepart."&to=".$VilleArrivee."&datetime=".$date."&datetime_represents=departure&min_nb_journeys=".$NbJourneys."";
- //Try file get contents
- $data = file_get_contents($url);
- json_decode($data, true);
- //Try Curl
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_VERBOSE, true);
- $response = curl_exec($ch);
- $resultData = json_decode($response, true);
- //DBUG//
- echo 'JSON FGC: ';
- var_dump($data);
- echo '<br/>';
- echo 'JSON CURL: ';
- var_dump($resultData);
- echo '<br/>';
- echo 'API URL : '.$url.'<br/>';
- echo 'API USER : '.$api_sncf_user.'<br/>';
- echo 'API MDP : '.$api_sncf_mdp.'<br/>';
- echo 'API $VilleDepart : '.$VilleDepart.'<br/>';
- echo 'API $VilleArrivee : '.$VilleArrivee.'<br/>';
- echo 'API $date : '.$date.'<br/>';
- echo 'API $NbJourneys : '.$NbJourneys.'<br/>';
- } catch (Exception $e) {
- echo 'Exception reçue : ', $e->getMessage(), "\n";
- }
- }
- // Identifiants de l'API SNCF https://data.sncf.com/api/fr/documentation
- $api_sncf_user = 'd8c032e8-695f-46be-b6cf-f57580ad4ca2';
- $api_sncf_mdp = '';
- // Initialiation des variables
- // Pour trouver l'id de la ville rechercher "id" dans la requete suivante https://api.sncf.com/v1/coverage/sncf/places?q=LYON
- $VilleDepart = 'admin:fr:63052'; // Le Breuil sur Couze ( Marie stop area)
- $VilleArrivee = 'admin:fr:63113'; // Clermont-ferrand (la pardieu stop area stop_area:OCE:SA:87782607 )
- $date = "20190714";
- $NbJourneys ="4"; //Nb de trains minimum par jour à afficher
- getTrains($api_sncf_user, $api_sncf_mdp, $VilleDepart, $VilleArrivee,$date,$NbJourneys);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement