我创建了一个包含2条记录的数组。您可以在下面看到它。
$sabre_req = array(
'0' => array(
'origin' => 'CGK',
'destination' => 'SUB',
'depart_date' => '2019-01-09T11:00:00',
'return_date' => '2019-01-10T11:00:00',
'budget_from' => 10000,
'budget_to' => 100000,
'total_pax' => 1,
),
'1' => array(
'origin' => 'CGK',
'destination' => 'SUB',
'depart_date' => '2019-01-09T11:00:00',
'return_date' => '2019-01-10T11:00:00',
'budget_from' => 10000,
'budget_to' => 100000,
'total_pax' => 1,
),
);
在第二条记录中无法解决,给了我一个错误。
它只是给了我一个价格结果,但我有2条记录在阵列中。
<?php
$sabre_req = array(
'0' => array(
'origin' => 'CGK',
'destination' => 'SUB',
'depart_date' => '2019-01-09T11:00:00',
'return_date' => '2019-01-10T11:00:00',
'budget_from' => 10000,
'budget_to' => 100000,
'total_pax' => 1,
),
'1' => array(
'origin' => 'CGK',
'destination' => 'SUB',
'depart_date' => '2019-01-09T11:00:00',
'return_date' => '2019-01-10T11:00:00',
'budget_from' => 10000,
'budget_to' => 100000,
'total_pax' => 1,
),
);
foreach ($sabre_req as $value) {
$key = "T1RLAQIzXupmNQFuFpTBLKCrqDubwwLN8xCK9f5pKbye0zUer0e6Yo3ZAADAqojZeUxbXOlWCOguUB0wHVvIquBzWTSmbdU7uvlv43nYyDPMSduE/kD23vLDuoHQldLyGlV443ZVTyJgheFqyufXNoD0oIPd8hsQhFr2WWxLzjV4dtJ9V3u7TxcdD+aqhB4w/Z3rOCLZh8WDVouzUYuSum9zgTmK4q6v8fyXM5qoVQkYmON2dUv7CvsFarm/htGSC2wu5ADO3XoIXz5bdbb/shs7pOhm0IpqBf0SKT6QvRG1XWdozN0IYIyuI3IU";
$header[] = "Authorization: Bearer " . $key;
$header[] = "Accept: application/json";
$header[] = "Content-Type: application/json";
$data = '{
"OTA_AirLowFareSearchRQ": {
"Target": "Production",
"POS": {
"Source": [{
"PseudoCityCode":"F9CE",
"RequestorID": {
"Type": "1",
"ID": "1",
"CompanyName": {
}
}
}]
},
"OriginDestinationInformation": [{
"RPH": "1",
"DepartureDateTime": "'.$value['depart_date'].'",
"OriginLocation": {
"LocationCode": "'.$value['origin'].'"
},
"DestinationLocation": {
"LocationCode": "'.$value['destination'].'"
},
"TPA_Extensions": {
"SegmentType": {
"Code": "O"
}
}
},
{
"RPH": "2",
"DepartureDateTime": "'.$value['return_date'].'",
"OriginLocation": {
"LocationCode": "'.$value['origin'].'"
},
"DestinationLocation": {
"LocationCode": "'.$value['destination'].'"
},
"TPA_Extensions": {
"SegmentType": {
"Code": "O"
}
}
}],
"TravelPreferences": {
"ValidInterlineTicket": true,
"CabinPref": [{
"Cabin": "Y",
"PreferLevel": "Preferred"
}],
"TPA_Extensions": {
"TripType": {
"Value": "Return"
},
"LongConnectTime": {
"Min": 780,
"Max": 1200,
"Enable": true
},
"ExcludeCallDirectCarriers": {
"Enabled": true
}
}
},
"TravelerInfoSummary": {
"SeatsRequested": [1],
"AirTravelerAvail": [{
"PassengerTypeQuantity": [{
"Code": "ADT",
"Quantity": 1
}]
}],
"PriceRequestInformation" : {
"CurrencyCode" : "PHP"
}
},
"TPA_Extensions": {
"IntelliSellTransaction": {
"RequestType": {
"Name": "50ITINS"
}
}
}
}
}';
$jsonstr = json_decode($data, true);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api-crt.cert.havail.sabre.com/v4.3.0/shop/flights?mode=live&limit=50&offset=1" );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
$result = curl_exec ($ch);
curl_close($ch);
$sabre_data = json_decode($result, true);
// // get the lowest fare
$lowest_fare = array();
if(@$sabre_data['OTA_AirLowFareSearchRS']['PricedItinCount'] > 0)
{
foreach ($sabre_data['OTA_AirLowFareSearchRS']['PricedItineraries']['PricedItinerary'] as $pricing_info)
{
foreach ($pricing_info['AirItineraryPricingInfo'] as $pricing_info)
{
$is_available = 1;
foreach ($pricing_info['PTC_FareBreakdowns']['PTC_FareBreakdown'] as $breakdown)
{
foreach ($breakdown['FareInfos']['FareInfo'] as $key => $seats)
{
if($value['total_pax'] > $seats['TPA_Extensions']['SeatsRemaining']['Number'])
{
$is_available = 0;
}
}
}
// If is_available == 1 get the price
if($is_available == 1)
{
$lowest_fare[] = array(
"price" => $pricing_info['ItinTotalFare']['TotalFare']['Amount'],
);
}
}
}
}
else
{
echo "no content";
}
$lowest_price = min($lowest_fare);
$total_fare = $lowest_price['price'] * $value['total_pax'];
echo '<br>'.$total_fare;
}
?>
这是结果。
9559no content
Warning: min(): Array must contain at least one element in C:\xampp\htdocs\apitut\sabre.php on line 169
0