|
- <?php
- /**
- *
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: Redstop
- * PhpStorm TopController.php
- * Create By 2017/5/2 13:30 $
- */
-
- namespace backend\modules\api\controllers;
- use yii\web\Controller;
- use common\models\Utils;
- use Yii;
-
- class FlightController extends Controller
- {
- public $enableCsrfValidation = false;
-
- /**
- * Function Description:入口文件
- * Function Name: actionIndex
- *
- * @return bool
- *
- * @author Redstop
- */
- public function actionIndex()
- {
- return 'hello me';
- }
-
- /**
- * Function Description:
- * Function Name: actionGetFlightInfo
- *
- * @return string
- *
- * @author Redstop
- */
- public function actionGetFlightInfo()
- {
- $request = Yii::$app->request;
- $f_code = $request->post("f_code");//航班代码
- $f_date = $request->post("f_date");//航班代码
- $f_code = strtoupper($f_code);
- if( $f_date == false ) {
- $f_date = date("Ymd");
- } else {
- $f_date = date( "Ymd", strtotime($f_date) );
- }
- $return_array = array();
- $return_array["flight_code"] = $f_code;
- $return_array["flight_date"] = date( "Y-m-d", strtotime($f_date) );
-
- $request_url = "http://www.variflight.com/flight/fnum/{$f_code}.html?AE71649A58c77&fdate={$f_date}";
- $result = Utils::httpRequest($request_url);
- $str_pos = strripos( $result, '<div class="li_com">' );
-
- $result2 = substr( $result, $str_pos );
- $span_array = explode("</span>", $result2);
- //获取预计起飞时间
- $cut_time = $span_array[1];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $cut_time = $this->getTimeFromString($cut_time);
- $return_array["flight_time"] = $cut_time;
- //获取实际起飞时间
- $cut_time = $span_array[2];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $cut_time = $this->getTimeFromString($cut_time);
- $return_array["flight_time_real"] = $cut_time;
- //获取出发地
- $cut_time = $span_array[3];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $return_array["flight_start_addr"] = $cut_time;
- //获取预计到达时间
- $cut_time = $span_array[4];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $cut_time = $this->getTimeFromString($cut_time);
- $return_array["arrive_time"] = $cut_time;
- //获取实际到达时间
- $cut_time = $span_array[5];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $cut_time = $this->getTimeFromString($cut_time);
- $return_array["arrive_time_real"] = $cut_time;
- //获取到达地
- $cut_time = $span_array[6];
- $str_pos = strpos( $cut_time, '>' );
- $cut_time = substr( $cut_time, $str_pos + 1 );
- $return_array["flight_end_addr"] = $cut_time;
- //到达日期
- $str_pos2 = strpos( $result, '<a class="searchlist_innerli" href="' );
- $result = substr( $result, $str_pos2 );
- $span_array = explode('"></a>', $result);
- $detail_url = "http://www.variflight.com".substr( $span_array[0],36);
-
- $result = Utils::httpRequest($detail_url);
- $str_pos = strpos( $result, '<div class="f_title f_title_c">' );
- $flight_date = substr( $result, $str_pos+ 63,10 );
- $return_array["arrive_date"] = $flight_date;
-
-
- echo json_encode($return_array);
- }
-
- /**
- * Function Description:
- * Function Name: getTimeFromString
- *
- * @return string
- *
- * @author Redstop
- */
- public function getTimeFromString( $ori_string ) {
- $return_time = "";
- $string_length = strlen($ori_string);
- for( $index_temp = 0; $index_temp < $string_length; $index_temp++ ) {
- $strtoken = $ori_string[$index_temp];
- if( is_numeric($strtoken) ) {
- $return_time .= $strtoken;
- }
- }
- if( strlen($return_time) == 4 ) {
- return substr( $return_time, 0, 2 ).":".substr( $return_time, 2 );
- } else {
- return "";
- }
- }
- }
|