Php-based real-time flight api call code example
Code description: php-based real-time flight api call code example
Associated Data: Flight dynamics [PHP] code
// + ---------------------------------------------------------------------- // ---------------------------- // Sample code of Flight Dynamic Call-aggregate data // online interface documentation: https://www.php1.cn///---------------------------------- Header ('content-type: text/html; charset = utf-8 '); // Configure Your applied appkey $ appkey = "*********************"; // ************* 1. city list ************ $ url =" http://apis.juhe.cn/plan/city "; $ Params = array (" dtype "=>" ", // return type, such as json or xml (default json); $ paramstring = http_build_query ($ params ); $ content = juhecurl ($ url, $ paramstring); $ result = json_decode ($ content, true); if ($ result) {if ($ result ['error _ Code'] = '0') {print_r ($ result);} else {echo $ result ['error _ Code']. ":". $ result ['reason '] ;}} else {echo "request failed ";} //************************************** * *********** // *************** 2. flight query (new) ************ $ url =" http://apis.juhe.cn/plan/snew "; $ Params = array (" name "=>" ", // flight number, for example, CZ3869" key "=> $ appkey, // app key "date" => "", // request time, for example, 2012-12-27 (default day time) "dtype" => "", // return type, such: json or xml (default json); $ paramstring = http_build_query ($ params); $ content = juhecurl ($ url, $ paramstring); $ result = json_decode ($ content, true); if ($ result) {if ($ result ['error _ Code'] = '0') {print_r ($ result );} else {echo $ result ['error _ Code']. ":". $ result ['reason '] ;}} else {echo "request failed ";} //************************************** * *********** // *************** 3. airport introduction ************ $ url =" http://apis.juhe.cn/plan/airport "; $ Params = array (" code "=>" ", // Airport International three-character code, such as: FUG" key "=> $ appkey, // app key "dtype" => "", // return type, such as json or xml (default json); $ paramstring = http_build_query ($ params ); $ content = juhecurl ($ url, $ paramstring); $ result = json_decode ($ content, true); if ($ result) {if ($ result ['error _ Code'] = '0') {print_r ($ result);} else {echo $ result ['error _ Code']. ":". $ result ['reason '] ;}} else {echo "request failed ";} //************************************** * *********** // *************** 4. route query ************ $ url =" http://apis.juhe.cn/plan/bc "; $ Params = array (" start "=>" ", // urlencode, for example, Beijing or PEK" end "=> "", // the city to be reached, such as: Shanghai Pudong or PVG "key" => $ appkey, // app key "date" => "", // request time, such: (The current day by default) "dtype" => "", // return type, such as json or xml (default json); $ paramstring = http_build_query ($ params ); $ content = juhecurl ($ url, $ paramstring); $ result = json_decode ($ content, true); if ($ result) {if ($ result ['error _ Code'] = '0') {print_r ($ result);} else {echo $ Result ['error _ Code']. ":". $ result ['reason '] ;}} else {echo "request failed ";} //************************************** * ***********/***** request interface returned content * @ param string $ url [requested URL] * @ param string $ params [request parameter] * @ param int $ ipost [whether to use the POST form] * @ return string */function juhecurl ($ url, $ params = false, $ ispost = 0) {$ httpInfo = array (); $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); Curl_setopt ($ ch, CURLOPT_USERAGENT, 'juhedata'); curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt ($ ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ ch, optional, true); curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true); if ($ ispost) {curl_setopt ($ ch, CURLOPT_POST, true); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ params); curl_setopt ($ ch, CURLOPT_URL, $ url);} els E {if ($ params) {curl_setopt ($ ch, CURLOPT_URL, $ url .'? '. $ Params);} else {curl_setopt ($ ch, CURLOPT_URL, $ url) ;}}$ response = curl_exec ($ ch); if ($ response === FALSE) {// echo "cURL Error :". curl_error ($ ch); return false;} $ httpCode = curl_getinfo ($ ch, CURLINFO_HTTP_CODE); $ httpInfo = array_merge ($ httpInfo, curl_getinfo ($ ch )); curl_close ($ ch); return $ response ;}