接口描述
接口分为两种查询方式。方式一:通过航班号和查询日期进行查询;方式二:通过航班起降地和查询日期进行查询。
请求说明
接口域名
api.hangxx.com
请求示例
HTTP 方法:GET/POST
请求URL:https://接口域名/restapi/airQuery/flightTime?authCode=鉴权码&flightNo=航班号&leaveCode=起飞城市三字码&arriveCode=降落城市三字码&queryDate=查询日期
url请求参数说明如下:
请求参数
参数 | 是否必选 | 类型 | 说明 |
---|---|---|---|
authCode | 是 | string | 航讯讯应用鉴权码,个人中心 -> 应用管理 -> 新建应用 -> 获得应用鉴权码 |
flightNo | 否 | string | 航班号(通过航班号查询必须填写,如填写了航班号则会根据航班号进行查询) |
leaveCode | 否 | string | 起飞城市三字码(通过航班起降地必须填写,如填写了航班号则此参数无效) |
arriveCode | 否 | string | 降落城市三字码(通过航班起降地必须填写,如填写了航班号则此参数无效) |
queryDate | 是 | string | 查询日期,格式:yyyy-MM-dd,如:1999-01-01,往前只能查询当前时间前3天的航班信息 |
请求代码示例
提示一:使用示例代码前,请记得替换相应的参数值。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
#请先安装requests模块 url='https://接口域名/restapi/airQuery/flightTime?authCode= &flightNo=&leaveCode=&arriveCode=&queryDate=' r=requests.get(url) print r.text
//请先导入httpclient相应的包 HttpClient httpclient = HttpClients.createDefault(); HttpGet get = new HttpGet("https://接口域名/restapi/airQuery/flightTime?authCode=&flightNo=&leaveCode= &arriveCode=&queryDate="); HttpResponse response = httpclient.execute(get); System.out.println(EntityUtils.toString(response.getEntity()));
<?php $host = "https://接口域名"; $path = "/restapi/airQuery/flightTime?authCode=&flightNo=&leaveCode= &arriveCode=&queryDate="; $method = "GET"; $url = $host . $path; $curl = curl_init(); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_FAILONERROR, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HEADER, false); if (1 == strpos("$".$host, "https://")) { curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); echo curl_exec($curl); ?>
using System.IO; using System.Text; using System.Net; using System.Net.Security; using System.Security.Cryptography.X509Certificates; private const String host = "https://接口域名"; private const String path = "/restapi/airQuery/flightTime?authCode=&flightNo=&leaveCode= &arriveCode=&queryDate="; private const String method = "POST"; static void Main(string[] args) { String querys = ""; String url = host + path; HttpWebRequest httpRequest = null; HttpWebResponse httpResponse = null; if (0 < querys.Length) { url = url + "?" + querys; } if (host.Contains("https://")) { ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback (CheckValidationResult); httpRequest = (HttpWebRequest)WebRequest.CreateDefault(new Uri(url)); } else { httpRequest = (HttpWebRequest)WebRequest.Create(url); } httpRequest.Method = method; try { httpResponse = (HttpWebResponse)httpRequest.GetResponse(); } catch (WebException ex) { httpResponse = (HttpWebResponse)ex.Response; } Console.WriteLine(httpResponse.StatusCode); Console.WriteLine(httpResponse.Method); Console.WriteLine(httpResponse.Headers); Stream st = httpResponse.GetResponseStream(); StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8")); Console.WriteLine(reader.ReadToEnd()); Console.WriteLine("\n"); } public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { return true; }
返回说明
返回结果示例
{ "code":200, "message":"查询成功", "flightInfos":[ { "planArriveTime":"2010-10-28 12:30:00", //计划到达时间 "airlineCompany":"中国国航", //航空公司 "arrivePortCode":"PEK", //到达机场编码 "arrivePort":"首都机场", //到达机场名称 "planLeaveTime":"2010-10-28 10:00:00", //计划起飞时间 "arriveCity":"北京", //到达城市 "arriveBuilding":"T3", //到达航站楼 "flightNo":"CA1450", //航班号 "leaveBuilding":"T2", //起飞航站楼 "leavePort":"江北机场", //起飞机场 "state":"航班计划", //航班状态 "leavePortCode":"CKG", //起飞机场编码 "leaveCity":"重庆" //起飞城市 } ] }