栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

适用于所有机场位置的Skyscanner API和使用CURL的Travel API

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

适用于所有机场位置的Skyscanner API和使用CURL的Travel API

经过大量搜索并与Skyscanner进行了讨论,我最终发现他们没有提供此类api

但是我已经成功实现了 Travel API ,我知道你们中很多人都在搜索这个程序,所以我在这里为所有人发布代码:)

I am calling below function using ajax:-function flight_data() {    $varApiKey = '?apiKey=ADD_KEY_HERE';    $country_pre = 'IR';    $originplace = '51.845159,-8.492835-latlong';    $curency = 'EUR';    $destination = 'DUB-iata';    $start_date = date('Y-m-d');    $dateoneMonth = strtotime($start_date);//$end_date = date("Y-m-d", strtotime("+1 month", $dateOneMonth));    $end_date = '';    $audult = '1';    $cabinclass = 'Economy';    $locationschema = 'iata';    $grouppricing = $preferDirects = 'true';    $query = "&country=" . $country_pre;    $query .= "&currency=" . $curency;    $query .= "&locale=en-IE";    $query .= "&originplace=" . $originplace;    $query .= "&destinationplace=" . $destination;    $query .= "&inbounddate=" . $end_date;    $query .= "&outbounddate=" . $start_date;    $query .= "&adults=" . $audult;    $query .="&locationschema=" . $locationschema;    $query .="&cabin&preferDirects=" . $preferDirects;    $query .="&grouppricing=" . $grouppricing;    $apiParamsUrl = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/" . $varApiKey . $query . "";    $apiParamsStr = parse_url($apiParamsUrl, PHP_URL_QUERY); // get the query string parametures    parse_str($apiParamsStr, $apiParamsArray); // parse into an array// the api url. First we need to request for a session    $apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0';//open connection    $ch = curl_init();//set the url, number of POST vars, POST data    curl_setopt($ch, CURLOPT_URL, $apiSessionUrl);    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlenpred', 'Accept: application/json')); // make api return json data    curl_setopt($ch, CURLOPT_POST, count($apiParamsArray)); // set how many fiels    curl_setopt($ch, CURLOPT_POSTFIELDS, $apiParamsStr);    // set the fields// caputre the headers    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_VERBOSE, 1);    curl_setopt($ch, CURLOPT_HEADER, 1);//execute post    $response = curl_exec($ch);// get the headers    $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);    $header = substr($response, 0, $header_size);    $body = substr($response, $header_size);//close connection    curl_close($ch);//    print_r($response);//    die();// get the api session url    preg_match('~Location: ([^s]+)~', $header, $matches);    $apiSessionUrl = $matches[1];// add on the api key for the session    $apiSessionUrl .= $varApiKey;// get the json data    $data = file_get_contents($apiSessionUrl);// depre the json    $array = json_depre($data, true);// dump json array`enter pre here`    printf('<pre>Poll Data  %s</pre>', print_r($array, true));}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/392211.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号