updateAreaList(); $this->updateCameraList(); } //同步区域列表 public function updateAreaList() { //查询使用海康服务器的矿区id $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all(); foreach ($mine_id_list as $key => $val) { MineServices::getHaiKangArea($val, CameraEnum::REQUEST_TYPE_LOCAL); } } public function updateCameraList() { //海康 //查询存在index_code列表 $index_code_list = MineList::where('index_code', '!=', null)->get(); foreach ($index_code_list as $key => $val) { $degree = explode('|', $val->degree); // $trans_result = CameraServices::getHaiKangTransList($degree[0]); $result = CameraServices::getHaiKangCamera($degree[0], $val->index_code, CameraEnum::CAMERA_TYPE_ALL); if ($result['status']) { $trans_arr = []; // foreach ($trans_result['data'] as $tk => $tv) { // $trans_arr[$tv['indexCode']]['ip'] = $tv['ip']; // } $index_code_arr = []; $arr_count = count($result['data']); foreach ($result['data'] as $k => $v) { $ip = ''; $port = ''; $com_number = ''; // if (isset($trans_arr[$v['trans_code']])) { // $ip = $trans_arr[$v['trans_code']]['ip']; // $port = CameraEnum::HAK_DEFAULT_PORT; // $com_number = $v['com_number']; // } //当前摄像头index_code数组 $index_code_arr[$k] = $v['camera_id']; $params = [ 'mine_id' => $val->id, 'camera_name' => $this->transformCameraName($v['camera_name']), 'index_code' => $v['camera_id'], 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID, 'camera_source' => CameraEnum::CAMERA_SOURCE_2, 'ip' => $ip, 'port' => $port, 'com_number' => $com_number, 'sort' => $arr_count - $k, ]; CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params); } //删除不存在的摄像头 CameraList::where('mine_id', $val->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete(); } } //同步天地伟业摄像头 //登录 // $url = 'http://10.71.177.215:7000/pangu/sdkServer/user/loginUser'; // $format = 'post'; // $data = array('username'=>'admin1','password'=>'Td123..','sysId'=>'PG'); // $res = $this->httpRequest($url,$format,$data); //设备列表 //通过接口获取设备 $url = 'http://10.71.177.215:7000/pangu/sdkServer/device/queryDeviceList'; $format = 'post'; $data = array('sOrgId'=>'21dsec1d-4a27-48d1-we4c5-e44fcc23110','iDeviceTypes'=>'5','rootCodes'=>'BH-0001','isOrgTree'=>true,'needPage'=>true,'pageSize'=>50,'currentPage'=>1); $device_list = $this->httpRequest($url,$format,$data); //获取金家渠mine_id $mine_list0 = DB::table('mine_list')->where('title', 'like', '%金家渠煤矿%')->get(); if(sizeof($mine_list0)>0){ $mine_id0 = $mine_list0[0]->id; }else{ $res0['parent_id'] = 0; $res0['title'] = '金家渠煤矿'; $res0['slug'] = 'JinJiaQuMeiKuang'; $res0['created_at'] = date('y-m-d h:i:s',time()); $res0['updated_at'] = date('y-m-d h:i:s',time()); DB::table('mine_list')->insert($res0); $mine_id0 = DB::getPdo()->lastInsertId(); } $mine_list = DB::table('mine_list')->where('title', 'like', '%金家渠地面%')->get(); if(sizeof($mine_list)>0){ $mine_id = $mine_list[0]->id; }else{ $res['parent_id'] = $mine_id0; $res['title'] = '金家渠地面'; $res['slug'] = 'JinJiaQuDiMian'; $res['created_at'] = date('y-m-d h:i:s',time()); $res['updated_at'] = date('y-m-d h:i:s',time()); DB::table('mine_list')->insert($res); $mine_id = DB::getPdo()->lastInsertId(); } if(sizeof($device_list['content'])>0){ for($i=0;$i$device_list['content'][$i]['sId'],'ip'=>'10.71.177.215','port'=>554,'type'=>0); $camera_url = $this->httpRequest($url,$format,$data); $params = [ 'mine_id' => $mine_id, 'ip' => '10.71.177.215', 'port' => 1554, // 'user_name' => 'admin1', // 'password' => 'Td123..', // 'camera_url' => $camera_url['content'][0]['url'], 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID, 'sort' => sizeof($device_list['content']) - $i, 'camera_name' => $device_list['content'][$i]['sName'], 'camera_source' => CameraEnum::CAMERA_SOURCE_2, 'index_code' => $device_list['content'][$i]['sId'], 'video_recorder'=> CameraEnum::VIDEO_RECORDER_TD, ]; CameraList::updateOrCreate(['index_code' => $device_list['content'][$i]['sId']], $params); } } } //删除不存在的摄像头 // CameraList::where('mine_id', $mine_id)->where('onlineStatus',0)->delete(); } public static function httpRequest($url, $format = 'get', $data = null){ //设置头信息 $headerArray =array("Content-type:application/json;","Accept:application/json","token:M3sWWDyqHsw3jmPP2VfIhd/z8KnV9gvJs2C4s/vbAfPAPuNUEmniC7OWtbFDSmWcm38LwUnZe2cuaClRsBegeQ=="); $curl=curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if ($format == 'post') { //post传值设置post传参 curl_setopt($curl, CURLOPT_POST, 1); if ($data) { $data = json_encode($data); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray); $data=json_decode(curl_exec($curl), true); curl_close($curl); //返回接口返回数据 return $data; } //转义摄像头名称中的特殊字符 public function transformCameraName($camera_name) { $camera_name = trim($camera_name); $camera_name = str_replace('#', '号', $camera_name); $camera_name = str_replace(' ', '-', $camera_name); $camera_name = str_replace('+', '', $camera_name); return $camera_name; } }