You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FlightController.php 4.7 KiB

3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: Redstop
  12. * PhpStorm TopController.php
  13. * Create By 2017/5/2 13:30 $
  14. */
  15. namespace backend\modules\api\controllers;
  16. use yii\web\Controller;
  17. use common\models\Utils;
  18. use Yii;
  19. class FlightController extends Controller
  20. {
  21. public $enableCsrfValidation = false;
  22. /**
  23. * Function Description:入口文件
  24. * Function Name: actionIndex
  25. *
  26. * @return bool
  27. *
  28. * @author Redstop
  29. */
  30. public function actionIndex()
  31. {
  32. return 'hello me';
  33. }
  34. /**
  35. * Function Description:
  36. * Function Name: actionGetFlightInfo
  37. *
  38. * @return string
  39. *
  40. * @author Redstop
  41. */
  42. public function actionGetFlightInfo()
  43. {
  44. $request = Yii::$app->request;
  45. $f_code = $request->post("f_code");//航班代码
  46. $f_date = $request->post("f_date");//航班代码
  47. $f_code = strtoupper($f_code);
  48. if( $f_date == false ) {
  49. $f_date = date("Ymd");
  50. } else {
  51. $f_date = date( "Ymd", strtotime($f_date) );
  52. }
  53. $return_array = array();
  54. $return_array["flight_code"] = $f_code;
  55. $return_array["flight_date"] = date( "Y-m-d", strtotime($f_date) );
  56. $request_url = "http://www.variflight.com/flight/fnum/{$f_code}.html?AE71649A58c77&fdate={$f_date}";
  57. $result = Utils::httpRequest($request_url);
  58. $str_pos = strripos( $result, '<div class="li_com">' );
  59. $result2 = substr( $result, $str_pos );
  60. $span_array = explode("</span>", $result2);
  61. //获取预计起飞时间
  62. $cut_time = $span_array[1];
  63. $str_pos = strpos( $cut_time, '>' );
  64. $cut_time = substr( $cut_time, $str_pos + 1 );
  65. $cut_time = $this->getTimeFromString($cut_time);
  66. $return_array["flight_time"] = $cut_time;
  67. //获取实际起飞时间
  68. $cut_time = $span_array[2];
  69. $str_pos = strpos( $cut_time, '>' );
  70. $cut_time = substr( $cut_time, $str_pos + 1 );
  71. $cut_time = $this->getTimeFromString($cut_time);
  72. $return_array["flight_time_real"] = $cut_time;
  73. //获取出发地
  74. $cut_time = $span_array[3];
  75. $str_pos = strpos( $cut_time, '>' );
  76. $cut_time = substr( $cut_time, $str_pos + 1 );
  77. $return_array["flight_start_addr"] = $cut_time;
  78. //获取预计到达时间
  79. $cut_time = $span_array[4];
  80. $str_pos = strpos( $cut_time, '>' );
  81. $cut_time = substr( $cut_time, $str_pos + 1 );
  82. $cut_time = $this->getTimeFromString($cut_time);
  83. $return_array["arrive_time"] = $cut_time;
  84. //获取实际到达时间
  85. $cut_time = $span_array[5];
  86. $str_pos = strpos( $cut_time, '>' );
  87. $cut_time = substr( $cut_time, $str_pos + 1 );
  88. $cut_time = $this->getTimeFromString($cut_time);
  89. $return_array["arrive_time_real"] = $cut_time;
  90. //获取到达地
  91. $cut_time = $span_array[6];
  92. $str_pos = strpos( $cut_time, '>' );
  93. $cut_time = substr( $cut_time, $str_pos + 1 );
  94. $return_array["flight_end_addr"] = $cut_time;
  95. //到达日期
  96. $str_pos2 = strpos( $result, '<a class="searchlist_innerli" href="' );
  97. $result = substr( $result, $str_pos2 );
  98. $span_array = explode('"></a>', $result);
  99. $detail_url = "http://www.variflight.com".substr( $span_array[0],36);
  100. $result = Utils::httpRequest($detail_url);
  101. $str_pos = strpos( $result, '<div class="f_title f_title_c">' );
  102. $flight_date = substr( $result, $str_pos+ 63,10 );
  103. $return_array["arrive_date"] = $flight_date;
  104. echo json_encode($return_array);
  105. }
  106. /**
  107. * Function Description:
  108. * Function Name: getTimeFromString
  109. *
  110. * @return string
  111. *
  112. * @author Redstop
  113. */
  114. public function getTimeFromString( $ori_string ) {
  115. $return_time = "";
  116. $string_length = strlen($ori_string);
  117. for( $index_temp = 0; $index_temp < $string_length; $index_temp++ ) {
  118. $strtoken = $ori_string[$index_temp];
  119. if( is_numeric($strtoken) ) {
  120. $return_time .= $strtoken;
  121. }
  122. }
  123. if( strlen($return_time) == 4 ) {
  124. return substr( $return_time, 0, 2 ).":".substr( $return_time, 2 );
  125. } else {
  126. return "";
  127. }
  128. }
  129. }