From dbfd5750679cdb204d3a31466a7b8b2cae7375c4 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Tue, 11 Jul 2023 11:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=90=84=E5=9C=BA=E7=AE=A1?= =?UTF-8?q?=E5=AE=9E=E6=96=BD=E5=AE=9E=E6=97=B6=E8=BF=9B=E9=A6=86=E4=BA=BA?= =?UTF-8?q?=E6=95=B0=E5=A2=9E=E5=8A=A0=E6=8B=A5=E6=8C=A4=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/pass/Create.php | 32 ++++++ source/application/common/model/Pass.php | 34 +++++++ source/application/task/controller/Pass.php | 97 +------------------ .../application/task/controller/Passall.php | 16 +-- .../application/task/controller/Passreal.php | 17 +--- source/application/task/controller/Video.php | 77 +++++++++++++++ web/video.php | 15 +++ 7 files changed, 167 insertions(+), 121 deletions(-) create mode 100644 source/application/task/controller/Video.php create mode 100644 web/video.php diff --git a/source/application/api/controller/pass/Create.php b/source/application/api/controller/pass/Create.php index 009ce5e..8470d99 100644 --- a/source/application/api/controller/pass/Create.php +++ b/source/application/api/controller/pass/Create.php @@ -186,5 +186,37 @@ class Create extends Controller return $this->renderSuccess(); } + public function createGroup() + { + $data_json = $this->request->param('data'); + $data = json_decode(html_entity_decode($data_json),true); + + $dm = new Dm(); + foreach ($data as $val) { + + $query = $dm->find('bt_passenger_monitor_group','"groupId"='."'{$val['groupId']}'"); + if (!empty($query)) continue; + + $insert_arr = [ + 'groupId' => $val['groupId'], + 'groupName' => $val['groupName'], + 'groupType' => $val['groupType'], + 'statType' => $val['statType'], + 'regionId' => $val['regionId'], + 'thirdPartCode' => $val['thirdPartCode'], + 'workStartTime' => $val['workStartTime'], + 'workEndTime' => $val['workEndTime'], + 'holdBase' => $val['holdBase'], + 'earlyWarningValue' => $val['earlyWarningValue'], + 'warningValue' => $val['warningValue'], + 'warningSwitch' => $val['warningSwitch'] + ]; + + $dm->insert('bt_passenger_monitor_group',$insert_arr); + } + + return $this->renderSuccess(); + } + } \ No newline at end of file diff --git a/source/application/common/model/Pass.php b/source/application/common/model/Pass.php index fdbed98..757ea1d 100644 --- a/source/application/common/model/Pass.php +++ b/source/application/common/model/Pass.php @@ -31,4 +31,38 @@ class Pass extends BaseModel } return ''; } + + /** + * 请求创建数据 + * @param $requestData + * @param $url + * @param $host_path + * @return array|int[] + */ + public static function requestCreateData($requestData,$url,$host_path = '') + { + # 验证传输数据 + if (empty($requestData) && is_array($requestData)) return ['status' => 0, 'msg' => 'requestData不能为空,且必须是数组']; + if (empty($url)) return ['status' => 0, 'msg' => 'url不能为空']; + # 获取请求路径 + if (empty($host_path)) { + $config = config('api_config'); + $host_path = $config['host_path']; + } + # 验证令牌 + $token = '9c4cb25665cf08667c815420ab383cb5'; + # 请求接口数据 + $data = [ + 'data' => json_encode($requestData), + 'token' => md5($token . date('Ymd')) + ]; + $json_data = json_encode($data); + $createUrl = $host_path . $url; + # 发起请求 + $result = postToken($createUrl,$json_data,false,[],$token); + $result = json_decode($result,true); + # 判断返回信息 + if ($result['code'] != 1) return ['status' => 0, 'msg' => $result['msg']]; + return ['status' => 1]; + } } \ No newline at end of file diff --git a/source/application/task/controller/Pass.php b/source/application/task/controller/Pass.php index 63efc46..0d8daed 100644 --- a/source/application/task/controller/Pass.php +++ b/source/application/task/controller/Pass.php @@ -81,101 +81,10 @@ class Pass exit( $e->getMessage() ); } - if (!empty($requestData)) { - $token = '9c4cb25665cf08667c815420ab383cb5'; + $requestRes = \app\common\model\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlow', $config['host_path']); - $data = [ - 'data' => json_encode($requestData), - 'token' => md5('9c4cb25665cf08667c815420ab383cb5' . date('Ymd')) - ]; - $json_data = json_encode($data); - $createUrl = $config['host_path'] . '/api/pass.create/createPassengerFlow'; - - - $result = postToken($createUrl,$json_data,false,[],$token); - $result = json_decode($result,true); - 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; + if (!$requestRes['status']) { + return $requestRes['msg']; } return true; diff --git a/source/application/task/controller/Passall.php b/source/application/task/controller/Passall.php index 61b1869..bae15c4 100644 --- a/source/application/task/controller/Passall.php +++ b/source/application/task/controller/Passall.php @@ -91,20 +91,10 @@ class Passall exit( $e->getMessage() ); } - if (!empty($requestData)) { - $token = '9c4cb25665cf08667c815420ab383cb5'; + $requestRes = \app\common\model\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowAll', $config['host_path']); - $data = [ - 'data' => json_encode($requestData), - 'token' => md5('9c4cb25665cf08667c815420ab383cb5' . date('Ymd')) - ]; - $json_data = json_encode($data); - $createUrl = $config['host_path'] . '/api/pass.create/createPassengerFlowAll'; - - - $result = postToken($createUrl,$json_data,false,[],$token); - $result = json_decode($result,true); - if ($result['code'] != 1) exit($result['msg']); + if (!$requestRes['status']) { + return $requestRes['msg']; } return true; diff --git a/source/application/task/controller/Passreal.php b/source/application/task/controller/Passreal.php index c6ab98e..ec62b79 100644 --- a/source/application/task/controller/Passreal.php +++ b/source/application/task/controller/Passreal.php @@ -56,21 +56,10 @@ class Passreal exit( $e->getMessage() ); } + $requestRes = \app\common\model\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowReal', $config['host_path']); - 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/bt_passenger_flow_real'; - - - $result = postToken($createUrl,$json_data,false,[],$token); - $result = json_decode($result,true); - if ($result['code'] != 1) exit($result['msg']); + if (!$requestRes['status']) { + return $requestRes['msg']; } return true; diff --git a/source/application/task/controller/Video.php b/source/application/task/controller/Video.php new file mode 100644 index 0000000..e5a9988 --- /dev/null +++ b/source/application/task/controller/Video.php @@ -0,0 +1,77 @@ + 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', + 'protocol' => 'rtmp', + '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); + } + } + $requestRes = \app\common\model\Pass::requestCreateData($requestData,'/api/pass.create/createVideo', $config['host_path']); + + if (!$requestRes['status']) { + return $requestRes['msg']; + } + + } catch (\Exception $e) { + return $e->getMessage(); + } + + return true; + } +} \ No newline at end of file diff --git a/web/video.php b/web/video.php new file mode 100644 index 0000000..c2580eb --- /dev/null +++ b/web/video.php @@ -0,0 +1,15 @@ +