|
- <?php
- /**
- *
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 张帅
- * PhpStorm JourneyService.php
- * Create By 2016/11/20 17:42 $
- */
-
- namespace WeChatUser\Service;
-
-
- use Base\Tool\Tool;
- use Util\Util\Util;
- use WeChatUser\Model\User;
-
- class JourneyService
- {
- /**
- * Function Description:我要找车
- * Function Name: findCar
- * @param $order_id
- * @param $run_date
- *
- * @return string
- *
- * @author 张帅
- */
- public function findCar($order_id,$run_date){
- $user = new User();
- $car_info = $user->getCar($order_id,$run_date);
- if(!$car_info['flag'] || count($car_info['data']) == 0){
- return Util::returnJsEr('暂未派车');
- }
-
- $car_info = $car_info['data'];
- if($car_info['bus_id'] == 0){
- return Util::returnJsEr('暂未派车');
- }
- $bus_id = $car_info['bus_id'];
- $bus_org_id = $car_info['bus_org_id'];
- $bus_no = $car_info['bus_no'];
- $j = '';
- $w = '';
- $get_car_postion_flag = false;
- if( $bus_org_id == "9477" ) {
- $car_position = $this->get_bailian_bus_position($bus_no);
- if( false != $car_position ) {
- $get_car_postion_flag = true;
- $j = $car_position['lon'];
- $w = $car_position['lat'];
- }
- }
- if( $get_car_postion_flag == false ) {
- if ($p = $this->getposition($bus_no)) { //通过北斗查找车辆信息
- $j = $p['Data'][0]['vehicle']['longitude'];
- $w = $p['Data'][0]['vehicle']['latitude'];
- } else {
- //$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";
- return Util::returnJsEr('没有找到车');
- }
- }
- $res_arr['address']=$car_info['address'];
- $res_arr['res_id'] = $car_info['res_id'];
- $res_arr['res_name'] = $car_info['res_name'];
- $res_arr['longitude'] = $car_info['res_x'];
- $res_arr['latitude'] = $car_info['res_y'];
- $bus['bus_id'] = $bus_id;
- $bus['bus_no'] = $bus_no;
- $bus['driver_name'] = $car_info['driver_name'];
- $bus['driver_mobile'] = $car_info['driver_mobile'];
- $bus['color']=$car_info['color'];
- $bus['img_url']=$car_info['img_url'];
- $bus['bus_name']=$car_info['bus_name'];
- if($j && $w){
- $bus['longitude'] = $j;
- $bus['latitude'] = $w;
- }else{
- return Util::returnJsEr('该车尚未开启定位功能');
- }
- return Util::returnJsSu('',array('res'=>$res_arr,'bus'=>$bus));
-
- }
-
- private function getposition($busno){
- $base_url = "http://api.hstsp.cn:8077/data/";
- $account_id = "hdgps";
- $account_pwd = md5("123456");
- $login_url = $base_url."login/tokenDuration.do?account={$account_id}&passwd={$account_pwd}";
- $result = Util::httpRequest( $login_url );
- $result_array = json_decode($result,true);
- $token_str = $result_array["tokenStr"];
- $check_car_no = urlencode($busno);
- $get_car_id_url = $base_url."LogisticalCar/queryCarId.do?tokenStr={$token_str}&plateCodes={$check_car_no}";
- $result = Util::httpRequest( $get_car_id_url );
- $result_array = json_decode($result,true);
- $car_id = number_format($result_array["Data"][0]["id"],0,'','');
- $get_car_info_url = $base_url."VehicleMonitor/queryMultiVehicleLocation.do?tokenStr={$token_str}&vehicleIds=". $car_id."&mapType=1";
- $result = Util::httpRequest( $get_car_info_url );
- $result_array = json_decode($result,true);
- return $result_array;
- }
-
- private function get_bailian_bus_position($busno) {
- $url = "http://218.5.80.24:5220/api/v10/Car/RealGnssData";
- $base64 = base64_encode("bailian:blab16");
- $data = json_encode(array(
- 'car_no' => $busno,
- 'car_color' => 0
- ));
- $header = array();
- $header[] ='Content-Type: application/json';
- $header[] ='Authorization: Basic '.$base64;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
- $file_contents = curl_exec($ch);
- curl_close($ch);
- $car_position = json_decode($file_contents, true);
- if( false == $car_position || $car_position["status"] != 1 ) {
- return false;
- }
- return $car_position["content"];
- }
- }
|