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.
 
 
 
 
 
 

136 lines
5.2 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm JourneyService.php
  13. * Create By 2016/11/20 17:42 $
  14. */
  15. namespace WeChatUser\Service;
  16. use Base\Tool\Tool;
  17. use Util\Util\Util;
  18. use WeChatUser\Model\User;
  19. class JourneyService
  20. {
  21. /**
  22. * Function Description:我要找车
  23. * Function Name: findCar
  24. * @param $order_id
  25. * @param $run_date
  26. *
  27. * @return string
  28. *
  29. * @author 张帅
  30. */
  31. public function findCar($order_id,$run_date){
  32. $user = new User();
  33. $car_info = $user->getCar($order_id,$run_date);
  34. if(!$car_info['flag'] || count($car_info['data']) == 0){
  35. return Util::returnJsEr('暂未派车');
  36. }
  37. $car_info = $car_info['data'];
  38. if($car_info['bus_id'] == 0){
  39. return Util::returnJsEr('暂未派车');
  40. }
  41. $bus_id = $car_info['bus_id'];
  42. $bus_org_id = $car_info['bus_org_id'];
  43. $bus_no = $car_info['bus_no'];
  44. $j = '';
  45. $w = '';
  46. $get_car_postion_flag = false;
  47. if( $bus_org_id == "9477" ) {
  48. $car_position = $this->get_bailian_bus_position($bus_no);
  49. if( false != $car_position ) {
  50. $get_car_postion_flag = true;
  51. $j = $car_position['lon'];
  52. $w = $car_position['lat'];
  53. }
  54. }
  55. if( $get_car_postion_flag == false ) {
  56. if ($p = $this->getposition($bus_no)) { //通过北斗查找车辆信息
  57. $j = $p['Data'][0]['vehicle']['longitude'];
  58. $w = $p['Data'][0]['vehicle']['latitude'];
  59. } else {
  60. //$sql_phone = "SELECT pos_x,pos_y from run_bus_pos where driver_id='" . $res_id_a[0]["res_id"] . "' order by log_time desc";
  61. return Util::returnJsEr('没有找到车');
  62. }
  63. }
  64. $res_arr['address']=$car_info['address'];
  65. $res_arr['res_id'] = $car_info['res_id'];
  66. $res_arr['res_name'] = $car_info['res_name'];
  67. $res_arr['longitude'] = $car_info['res_x'];
  68. $res_arr['latitude'] = $car_info['res_y'];
  69. $bus['bus_id'] = $bus_id;
  70. $bus['bus_no'] = $bus_no;
  71. $bus['driver_name'] = $car_info['driver_name'];
  72. $bus['driver_mobile'] = $car_info['driver_mobile'];
  73. $bus['color']=$car_info['color'];
  74. $bus['img_url']=$car_info['img_url'];
  75. $bus['bus_name']=$car_info['bus_name'];
  76. if($j && $w){
  77. $bus['longitude'] = $j;
  78. $bus['latitude'] = $w;
  79. }else{
  80. return Util::returnJsEr('该车尚未开启定位功能');
  81. }
  82. return Util::returnJsSu('',array('res'=>$res_arr,'bus'=>$bus));
  83. }
  84. private function getposition($busno){
  85. $base_url = "http://api.hstsp.cn:8077/data/";
  86. $account_id = "hdgps";
  87. $account_pwd = md5("123456");
  88. $login_url = $base_url."login/tokenDuration.do?account={$account_id}&passwd={$account_pwd}";
  89. $result = Util::httpRequest( $login_url );
  90. $result_array = json_decode($result,true);
  91. $token_str = $result_array["tokenStr"];
  92. $check_car_no = urlencode($busno);
  93. $get_car_id_url = $base_url."LogisticalCar/queryCarId.do?tokenStr={$token_str}&plateCodes={$check_car_no}";
  94. $result = Util::httpRequest( $get_car_id_url );
  95. $result_array = json_decode($result,true);
  96. $car_id = number_format($result_array["Data"][0]["id"],0,'','');
  97. $get_car_info_url = $base_url."VehicleMonitor/queryMultiVehicleLocation.do?tokenStr={$token_str}&vehicleIds=". $car_id."&mapType=1";
  98. $result = Util::httpRequest( $get_car_info_url );
  99. $result_array = json_decode($result,true);
  100. return $result_array;
  101. }
  102. private function get_bailian_bus_position($busno) {
  103. $url = "http://218.5.80.24:5220/api/v10/Car/RealGnssData";
  104. $base64 = base64_encode("bailian:blab16");
  105. $data = json_encode(array(
  106. 'car_no' => $busno,
  107. 'car_color' => 0
  108. ));
  109. $header = array();
  110. $header[] ='Content-Type: application/json';
  111. $header[] ='Authorization: Basic '.$base64;
  112. $ch = curl_init();
  113. curl_setopt($ch, CURLOPT_URL, $url);
  114. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  115. curl_setopt($ch, CURLOPT_POST, 1);
  116. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  117. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  118. curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
  119. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  120. $file_contents = curl_exec($ch);
  121. curl_close($ch);
  122. $car_position = json_decode($file_contents, true);
  123. if( false == $car_position || $car_position["status"] != 1 ) {
  124. return false;
  125. }
  126. return $car_position["content"];
  127. }
  128. }