接入教程
1. 阅读授权指南获取访问令牌
2. 选择测试环境或生产环境
3. 调用订单创建接口提交预订
4. 使用订单查询接口获取状态
5. 通过修改接口更新订单信息
6. 调用取消接口终止订单
使用Python创建航班订单
python
import requests
url = "https://api.example.com/v1/flight/orders"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
data = {
"passengerDetails": {
"name": "John Doe",
"contact": "john@example.com"
},
"flightInfo": {
"origin": "JFK",
"destination": "LAX",
"date": "2024-12-01"
}
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
使用PHP查询航班订单
php
<?php
$url = "https://api.example.com/v1/flight/orders/ORD12345";
$headers = [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json"
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status: " . $httpCode . "\n";
echo "Response: " . $response;
使用JavaScript取消航班订单
javascript
const url = "https://api.example.com/v1/flight/orders/ORD12345";
const options = {
method: "DELETE",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
};
fetch(url, options)
.then(response => {
console.log(`Status: ${response.status}`);
return response.json();
})
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
常见问题
如何获取API访问令牌?
您需要参考授权指南,通过OAuth 2.0客户端凭证流程获取访问令牌。测试环境令牌有效期较短,生产环境请妥善保管。
测试环境和生产环境有什么区别?
测试环境仅包含生产环境的子集数据,用于开发和调试。API调用限制较低,但不保证实时航班数据的准确性。
订单创建后可以修改吗?
支持有限度的订单修改,具体取决于航空公司的政策和航班状态。请查阅API文档中的订单修改端点说明。
Aitishiku.com