Пример #1
0
	public function getAirlineDetail()
	{
		$retcode = "200";
		$arr_message = array("result" => "fail", "message" => "操作出现异常,请稍后再试!");

		$arr_body = $this->arr_body;
		$departCityCode = trim($arr_body['departCityCode']);
		$arriveCityCode = trim($arr_body['arriveCityCode']);
		
		$departTime = trim($arr_body['departTime']);
		$returnTime = trim($arr_body['returnTime']);

		$departDate = substr($departTime, 0, 10);
		$returnDate = substr($returnTime, 0, 10);
		
		$flight = trim($arr_body['flight']);
		$returnFlight = trim($arr_body['returnFlight']);
		
		$ws = "http://openapi.ctrip.com/Flight/DomesticFlight/OTA_FlightSearch.asmx?wsdl";
		$now = time();
		$xml = '<?xml version="1.0" encoding="utf-8"?><Request><Header AllianceID="' . $this->aid . '" SID="' . $this->sid . '" TimeStamp="' . $now . '" RequestType="OTA_FlightSearch" Signature="' . $this->GetSign($now, "OTA_FlightSearch") . '" /><FlightSearchRequest><SearchType>S</SearchType><Routes><FlightRoute><DepartCity>' . $departCityCode . '</DepartCity><ArriveCity>' . $arriveCityCode . '</ArriveCity><DepartDate>' . $departDate . '</DepartDate><EarliestDepartTime>' . $departTime . '</EarliestDepartTime><LatestDepartTime>' . $departTime . '</LatestDepartTime></FlightRoute>' . (($returnDate != "" && $returnTime != "" && $returnFlight != "") ? '<FlightRoute><DepartCity>' . $arriveCityCode . '</DepartCity><ArriveCity>' . $departCityCode . '</ArriveCity><DepartDate>' . $returnDate . '</DepartDate><EarliestDepartTime>' . $returnTime . '</EarliestDepartTime><LatestDepartTime>' . $returnTime . '</LatestDepartTime></FlightRoute>' : '') . '</Routes></FlightSearchRequest></Request>';
file_put_contents("/dx/mobilepay/log/debug.log", $xml . "\r\n", FILE_APPEND | LOCK_EX);
		$client = new SoapClient($ws);
		$result = $client->Request(array('requestXML' => $xml));
		
		$flightList = array();

		if(property_exists($result, "RequestResult"))
		{
			$xml = $result->RequestResult;
		}
		$xml = simplexml_load_string($xml);
		$flightCount = 0;
		if(isset($xml->FlightSearchResponse->FlightRoutes))
		{
			$flightRoutesNode = $xml->FlightSearchResponse->FlightRoutes;

			$db = new DB_test();
			foreach($flightRoutesNode->children() as $domesticFlightRouteNode)
			{
				$flightsListNode = $domesticFlightRouteNode->FlightsList;
				foreach ($flightsListNode->children() as $flightNode)
				{
					$sql = "INSERT INTO ctrip_airticket_flight_list (depart_city_code, depart_port_code, 
					arrive_city_code, arrive_port_code, 
					depart_time, arrive_time, 
					flight, craft_code, 
					airline_iata_code, seat_class, 
					sub_seat_class, display_sub_seat_class, 
					rate, price, 
					standard_price, tax, 
					oil_fee, standard_price_for_child, 
					tax_for_child, oil_fee_for_child, 
					standard_price_for_baby, tax_for_baby, 
					oil_fee_for_baby, meal_type, 
					stop_count, rer_code, 
					end_code, ref_code, 
					rer_note, end_note, 
					ref_note, remark, 
					quantity, punctuality_rate, 
					ticket_type, price_type, 
					product_type, product_source, 
					inventory_type, before_fly_date, 
					route_index, need_apply, 
					recommend, refund_fee_formula_id, 
					can_up_grade, 
					can_separate_sale, 
					can_no_defer, 
					can_post, 
					is_fly_man, 
					only_own_city, 
					is_lowest_cz_special_price, 
					allow_cp_type, 
					policy_id, 
					is_rebate, 
					rebate_amount) 
					VALUES 
					('" . $flightNode->DepartCityCode . "', '" . strval($flightNode->DPortCode) . "', '" . 
					strval($flightNode->ArriveCityCode) . "', '" . strval($flightNode->APortCode) . "', '" . 
					strval($flightNode->TakeOffTime) . "', '" . strval($flightNode->ArriveTime) . "', '" . 
					strval($flightNode->Flight) . "', '" . strval($flightNode->CraftType) . "', '" . 
					strval($flightNode->AirlineCode) . "', '" . strval($flightNode->Class) . "', '" . 
					strval($flightNode->SubClass) . "', '" . strval($flightNode->DisplaySubclass) . "', " . 
					doubleval($flightNode->Rate) . ", " . doubleval($flightNode->Price) . ", " . 
					doubleval($flightNode->StandardPrice) . ", " . doubleval($flightNode->AdultTax) . ", " . 
					doubleval($flightNode->AdultOilFee) . ", " . doubleval($flightNode->ChildStandardPrice) . ", " . doubleval($flightNode->ChildTax) . ", " . doubleval($flightNode->ChildOilFee) . ", " . 
					doubleval($flightNode->BabyStandardPrice) . ", " . doubleval($flightNode->BabyTax) . ", " . 
					doubleval($flightNode->BabyOilFee) . ", '" . strval($flightNode->MealType) . "', " . 
					intval($flightNode->StopTimes) . ", '" . strval($flightNode->Nonrer) . "', '" . 
					strval($flightNode->Nonend) . "', '" . strval($flightNode->Nonref) . "', '" . 
					strval($flightNode->Rernote) . "', '" . strval($flightNode->Endnote) . "', '" . 
					strval($flightNode->Nonref) . "', '" . strval($flightNode->Remarks) . "', " . 
					intval($flightNode->Quantity) . ", " . doubleval($flightNode->PunctualityRate) . ", " . 
					intval($flightNode->TicketType) . ", '" . strval($flightNode->PriceType) . "', '" . 
					strval($flightNode->ProductType) . "', " . intval($flightNode->ProductSource) . ", '" . 
					strval($flightNode->InventoryType) . "', " . intval($flightNode->BeforeFlyDate) . ", " . 
					intval($flightNode->RouteIndex) . ", '" . strval($flightNode->NeedApplyString) . "', " . 
					intval($flightNode->Recommend) . ", " . intval($flightNode->RefundFeeFormulaID) . ", " . 
					((strval($flightNode->CanUpGrade) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->CanSeparateSale) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->CanNoDefer) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->CanPost) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->IsFlyMan) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->OnlyOwnCity) == "true") ? 1 : 0) . ", " . 
					((strval($flightNode->IsLowestCZSpecialPrice) == "true") ? 1 : 0) . ", " . 
					intval($flightNode->AllowCPType) . ", " . intval($flightNode->PolicyID) . ", " . 
					((strval($flightNode->IsRebate) == "true") ? 1 : 0) . ", " . 
					intval($flightNode->PolicyID) . ");";
					$sql = auto_charset($sql, 'utf-8', 'gbk');
					$db->query($sql);
					$flightCount++;
				}
			}
			$lastInsertId = $db->get_insert_id();
			
			$sql = "SELECT id, flight, price, standard_price AS standardPrice, oil_fee AS oilFee, tax, standard_price_for_child AS standardPriceForChild, oil_fee_for_child AS oilFeeForChild, tax_for_child AS taxForChild, standard_price_for_baby AS standardPriceForBaby, oil_fee_for_baby AS oilFeeForBaby, tax_for_baby AS taxForBaby, quantity, display_sub_seat_class AS class, rer_note AS rerNote, end_note AS endNote, ref_note AS refNote FROM ctrip_airticket_flight_list WHERE depart_city_code = '" . $departCityCode . "' AND arrive_city_code = '" . $arriveCityCode . "' AND flight = '" . $flight . "' AND id > " . ($lastInsertId - $flightCount);
			
			if($returnDate != "" && $returnTime != "" && $returnFlight != "")
			{
				$sql .= " UNION SELECT id, flight, price, standard_price AS standardPrice, oil_fee AS oilFee, tax, standard_price_for_child AS standardPriceForChild, oil_fee_for_child AS oilFeeForChild, tax_for_child AS taxForChild, standard_price_for_baby AS standardPriceForBaby, oil_fee_for_baby AS oilFeeForBaby, tax_for_baby AS taxForBaby, quantity, display_sub_seat_class AS class, rer_note AS rerNote, end_note AS endNote, ref_note AS refNote FROM ctrip_airticket_flight_list WHERE depart_city_code = '" . $arriveCityCode . "' AND arrive_city_code = '" . $departCityCode . "' AND flight = '" . $returnFlight . "' AND id > " . ($lastInsertId - $flightCount);
			}
			
			$db->query($sql);
			$arr_msg = auto_charset($db->getData('', 'msgbody'), 'gbk', 'utf-8');
			$arr_message = array("result" => "success", "message" => "查询航班成功");
		}
		else
		{
			$arr_message = array("result" => "success", "message" => "航班信息有误");
		}
		
		$retcode = "0";
		
		$arr_msg['msgbody']['result'] = $arr_message['result'];
		$arr_msg['msgbody']['message'] = $arr_message['message'];
		
		$returnvalue = array ("msgbody" => $arr_msg['msgbody']);
		$returnval = TfbxmlResponse :: ResponsetoApp($retcode, $returnvalue);
		return $returnval;
	}