webservices應用----查詢航班

程序結果


開啓php.ini
extension=php_soap.dll

webservices接口

http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl

webservices函數使用

http://ws.webxml.com.cn/webservices/DomesticAirline.asmx

PHP代碼

<?php

header("Content-type: text/html; charset=utf-8");

//查詢城市列表
$client = new SoapClient('http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl');
$result = $client  -> getDomesticCity() -> getDomesticCityResult -> any; 
$city = new SimpleXMLElement($result);
$address = $city -> Airline1 -> Address;

//形成表單
echo "<form id ='form' name = 'city' method = 'post' action = ''>";
echo "開始城市:<select name='startCity'>";
foreach ($address as $city){
    echo "<option value={$city -> cnCityName}>{$city -> cnCityName}</option>";
}
echo "</select>";
echo " ";
echo "到達城市:<select name='lastCity'>";
foreach ($address as $city){
    echo "<option value={$city -> cnCityName}>{$city -> cnCityName}</option>";
}
echo "</select>"; 
echo " ";
echo "時間:<input type='text' name='theDate' value='" . date("Y-m-d") . "'/>";
echo "<input type='submit' />";
echo "</form>";

if($_POST){
    //獲取表單數據
    $startCity = $_POST['startCity'];
    $lastCity = $_POST['lastCity'];
    $theDate = $_POST['theDate'];
    $param = array(
      'startCity' => $startCity,
      'lastCity' => $lastCity,
      'theDate' => $theDate,  
      'userID' => ""
    );
    //查詢
    $result = $client -> getDomesticAirlinesTime($param) -> getDomesticAirlinesTimeResult ->any;
    echo "<hr />";
    $airline = new SimpleXMLElement($result) ;
    $airline_arr = $airline -> Airlines -> AirlinesTime;
//    var_dump($airline_arr);
    if("沒有航班" == $airline_arr[0] -> Company){
        echo "沒有航班。。。。";
    }else{
        echo "<table width='1000' border='1'>";
        echo "<tr><th>航空公司</th><th>航班</th><th>出發機場</th><th>到達機場</th><th>起飛時間</th><th>到達時間</th><th>機型</th><th>停靠站</th><th>飛行日期</th></tr>";
        foreach ($airline_arr as $air){
            echo "<tr><td>{$air -> Company}</td><td>{$air -> AirlineCode}</td><td>{$air -> StartDrome}</td><td>{$air -> ArriveDrome}</td>"
            . "<td>{$air -> StartTime}</td><td>{$air -> ArriveTime}</td><td>{$air -> Mode}</td><td>{$air -> AirlineStop}</td><td>{$air -> Week}</td></tr>";
        }
        echo"</table>";
    }
    
}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章