From 24fb32c105aeecc2a10736f96c93823f38900455 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Thu, 6 Jul 2023 19:21:29 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=9B=91=E6=8E=A7=E7=82=B9?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/pass/Create.php | 30 +++++++ .../api/controller/video/Video.php | 50 ++---------- source/application/task/controller/Pass.php | 80 +++++++++++++++++++ 3 files changed, 116 insertions(+), 44 deletions(-) diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index 94818e3..009ce5e 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -157,4 +157,34 @@ class Create extends Controller return $this->renderSuccess(); } + public function createVideo() + { + $data_json = $this->request->param('data'); + $data = json_decode(html_entity_decode($data_json),true); + + #Db::table('bt_passenger_flow_real')->where('id','>',1)->delete(); + + $dm = new Dm(); + foreach ($data as $val) { + + $insert_arr = [ + 'cameraIndexCode' => $val['cameraIndexCode'], + 'cameraName' => $val['cameraName'], + 'cameraType' => $val['cameraType'], + 'cameraTypeName' => $val['cameraTypeName'], + 'regionIndexCode' => $val['regionIndexCode'], + 'transTypeName' => $val['transTypeName'], + 'transType' => $val['transType'], + 'createTime' => $val['createTime'], + 'url' => $val['url'] + ]; + #Db::table('bt_passenger_flow_real')->insert($insert_arr); + + $dm->insert('bt_video',$insert_arr); + } + + return $this->renderSuccess(); + } + + } \ No newline at end of file diff --git a/source/application/api/controller/video/Video.php b/source/application/api/controller/video/Video.php index 5538079..1fedb61 100644 --- a/source/application/api/controller/video/Video.php +++ b/source/application/api/controller/video/Video.php @@ -3,57 +3,19 @@ namespace app\api\controller\video; use app\api\controller\Controller; +use app\common\dm\Dm; class Video extends Controller { public function getVideo() { - $config = config('api_config'); - $url = $config['host_url'] . "/api/resource/v1/cameras"; - $token = getAccessToken(); - - # 获取视频资源 - try { - - $dataArr = [ - 'pageNo' => 1, - 'pageSize' => 10, - ]; - $json_data = json_encode($dataArr); - $result = postToken($url,$json_data,false,[],$token); - - $res_data = json_decode($result,true); - if ($res_data['code'] != 0) throw new \Exception('请求失败'); - $list = (array)$res_data['data']['list']; - - $urlArr = []; - foreach ($list as $row) { - - # 获取监控点视频链接 - $cameraIndexCode = $row['cameraIndexCode']; - $url2 = $config['host_url'] . "/api/video/v2/cameras/previewURLs"; - $dataArr2 = [ - 'cameraIndexCode' => $cameraIndexCode, - 'streamType' => 0, - 'transmode' => $row['transType'], - 'expand' => 'transcode=0', - 'streamform' => 'ps' - ]; - $json_data2 = json_encode($dataArr2); - $result2 = postToken($url2,$json_data2,false,[],$token); - $res_data2 = json_decode($result2,true); - if ($res_data2['code'] != 0) throw new \Exception('请求失败'); - $list2 = (array)$res_data2['data']; - foreach ($list2 as $row2) { - $urlArr[] = $row2; - } - } - - } catch (\Exception $e) { - return $this->renderError($e->getMessage()); + $urlArr = []; + $dm = new Dm(); + $list = $dm->select('bt_video'); + foreach ($list as $row) { + $urlArr[] = $row['url']; } - return $this->renderSuccess(compact('urlArr')); } } \ No newline at end of file diff --git a/source/application/task/controller/Pass.php b/source/application/task/controller/Pass.php index cd0ed49..63efc46 100644 --- a/source/application/task/controller/Pass.php +++ b/source/application/task/controller/Pass.php @@ -97,6 +97,86 @@ class Pass if ($result['code'] != 1) exit($result['msg']); } + $this->getVideo(); + return true; + } + + public function getVideo() + { + $config = config('api_config'); + $url = $config['host_url'] . "/api/resource/v1/cameras"; + $token = getAccessToken(); + + # 获取视频资源 + try { + + $dataArr = [ + 'pageNo' => 1, + 'pageSize' => 100, + ]; + $json_data = json_encode($dataArr); + $result = postToken($url,$json_data,false,[],$token); + + $res_data = json_decode($result,true); + if ($res_data['code'] != 0) throw new \Exception('请求失败'); + $list = (array)$res_data['data']['list']; + + $requestData = []; + foreach ($list as $row) { + + # 获取监控点视频链接 + $cameraIndexCode = $row['cameraIndexCode']; + $url2 = $config['host_url'] . "/api/video/v2/cameras/previewURLs"; + $dataArr2 = [ + 'cameraIndexCode' => $cameraIndexCode, + 'streamType' => 0, + 'transmode' => $row['transType'], + 'expand' => 'transcode=0', + 'streamform' => 'ps' + ]; + $json_data2 = json_encode($dataArr2); + $result2 = postToken($url2,$json_data2,false,[],$token); + $res_data2 = json_decode($result2,true); + if ($res_data2['code'] != 0) throw new \Exception('请求失败'); + $list2 = (array)$res_data2['data']; + foreach ($list2 as $row2) { + + $requestData[] = $insert = [ + 'cameraIndexCode' => $cameraIndexCode, + 'cameraName' => $row['cameraName'], + 'cameraType' => $row['cameraType'], + 'cameraTypeName' => $row['cameraTypeName'], + 'regionIndexCode' => $row['regionIndexCode'], + 'transTypeName' => $row['transTypeName'], + 'transType' => $row['transType'], + 'createTime' => $row['createTime'], + 'url' => $row2 + ]; + + Db::table('bt_video')->insert($insert); + } + } + + if (!empty($requestData)) { + $token = '9c4cb25665cf08667c815420ab383cb5'; + + $data = [ + 'data' => json_encode($requestData), + 'token' => md5('9c4cb25665cf08667c815420ab383cb5' . date('Ymd')) + ]; + $json_data = json_encode($data); + $createUrl = $config['host_path'] . '/api/pass.create/createVideo'; + + + $result = postToken($createUrl,$json_data,false,[],$token); + $result = json_decode($result,true); + if ($result['code'] != 1) exit($result['msg']); + } + + } catch (\Exception $e) { + echo $e->getMessage(); + exit; + } return true; }