From 83b9eb588400a87a282ecdd74d44b0c7bf4be73c Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq,com> Date: Wed, 2 Aug 2023 10:56:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BA=BF=E4=B8=8A=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/Base.php | 320 +++++++++++++++++++++++++++++++++++++++++++++ tasks/Group.php | 26 ++-- tasks/Lib.php | 45 ++++--- tasks/LibLease.php | 36 +++++ tasks/Pass.php | 36 ++--- tasks/Passall.php | 36 +++-- tasks/Passreal.php | 82 ++++++++---- tasks/Video.php | 50 ++++--- 8 files changed, 521 insertions(+), 110 deletions(-) create mode 100644 tasks/Base.php create mode 100644 tasks/LibLease.php diff --git a/tasks/Base.php b/tasks/Base.php new file mode 100644 index 0000000..7c05f6b --- /dev/null +++ b/tasks/Base.php @@ -0,0 +1,320 @@ + [ + # 调用网址地址 + 'host' => '192.168.1.253', + # 端口号 + 'port' => '443', + # 请求key + 'cid' => '27268113', + # 请求密钥 + 'cskey' => 'Y9NWZJw9cF3cw3J476Ru', + # 请求智慧景区接口地址 + 'host_url' => 'https://192.168.1.253:443/artemis', + # 脚本数据推送创建数据地址 + //'host_path' => 'http://btgym.xingtongworld.com/index.php?s=', + 'host_path' => 'http://10.97.121.2:8442/index.php?s=', + # 允许跨域 请求的IP地址 + 'access_control_allow_origin' => [ + 'http://10.97.121.2:8443', + ] + ] + ]; + + + /** + * 获取 接口 accessToken + * @return mixed + */ + function get_access_token(){ + + // 记录缓存, 时效2小时分钟 + $token = $this->get_cache('api_access_token'); + + if (empty($token)) { + $config = $this->config('api_config'); + // + $url = $config['host_url']."/oauth/token?client_id=".$config['cid']."&client_secret=".$config['cskey']; + // do post + $ret = $this->curl_post($url); + $res = json_decode($ret,true); + if ($res['access_token']) { + $this->set_cache('api_access_token', $res['access_token'], 7200); + $token = $res['access_token']; + } + } + + return $token; + } + + + /** + * 获取当前时间日期 + * @param $granularity // 返回当前日期 all = 所有 + * @return array + */ + function get_target_date($granularity = 'all') { + date_default_timezone_set('Asia/Shanghai'); + $data = []; + + if ($granularity === 'day' || $granularity === 'all') { + $date = $granularity !== 'all' ? $granularity : 'day'; + $data[$date] = [ + 'start_time' => strtotime('today'), + 'end_time' => strtotime('tomorrow - 1 second'), + ]; + } + if ($granularity === 'week' || $granularity === 'all') { + $date = $granularity !== 'all' ? $granularity : 'week'; + $data[$date] = [ + 'start_time' => strtotime('this week midnight'), + 'end_time' => strtotime('next week midnight - 1 second'), + ]; + } + if ($granularity === 'month' || $granularity === 'all') { + $date = $granularity !== 'all' ? $granularity : 'month'; + $data[$date] = [ + 'start_time' => strtotime(date('Y-m-01 00:00:00')), + 'end_time' => strtotime(date('Y-m-t 23:59:59')), + ]; + } + if ($granularity === 'year' || $granularity === 'all') { + $date = $granularity !== 'all' ? $granularity : 'year'; + $data[$date] = [ + 'start_time' => strtotime('first day of January this year'), + 'end_time' => strtotime('first day of January next year - 1 second'), + ]; + } + + foreach ($data as &$val) { + $val['c_start_time'] = date("c",$val['start_time']); + $val['c_end_time'] = date("c",$val['end_time']); + $val['start_time'] = date("Y-m-d H:i:s",$val['start_time']); + $val['end_time'] = date("Y-m-d H:i:s",$val['end_time']); + } + return $data; + } + + + + function get_cache($key){ + + + return ''; + } + + + + + function set_cache($key, $value,$expire_time = 0) + { + + } + + + /** + * 获取配置数据 + * @param $key + * @return array|mixed + */ + function config($key = 'all') { + $config = $this->api_config; + if ($key == 'all') { + return $config; + } else { + return isset($config[$key]) ? $config[$key] : []; + } + } + + + /** + * curl请求指定url (post) + * @param $url + * @param array $data + * @return mixed + */ + function curl_post($url, $data = []) + { + $header = [ + 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12' + ]; + $curl = curl_init(); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + curl_close($ch); + return $result; + } + + + /** + * 模拟POST请求 + * @param string $url 请求地址 + * @param mixed $data 请求数据 + * @param false $useCert 是否引入微信支付证书 + * @param array $sslCert 证书路径 + * @param string $token 请求token + * @return bool|mixed|string + */ + function post_token($url, $data = [], $useCert = false, $sslCert = [], $token = '') + { + $header = [ + 'Content-type: application/json;', + "access_token: {$token}" + ]; + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_POST, TRUE); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + if ($useCert == true) { + // 设置证书:cert 与 key 分别属于两个.pem文件 + curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM'); + curl_setopt($curl, CURLOPT_SSLCERT, $sslCert['certPem']); + curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM'); + curl_setopt($curl, CURLOPT_SSLKEY, $sslCert['keyPem']); + } + $result = curl_exec($curl); + if ($result === false) { + curl_error($curl); + } + curl_close($curl); + return $result; + } + + /** + * Authorization 信息传输请求 + * @param $url + * @param $user + * @param $password + * @param $data + * @return bool|mixed|string + */ + function get_data($url,$user,$password,$data = []) { + + $header = [ + 'Content-type: application/json;', + "Authorization: Basic " . base64_encode("{$user}:{$password}") + ]; + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_POST, TRUE); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); + $result = curl_exec($curl); + if ($result === false) { + curl_error($curl); + } + curl_close($curl); + return $result; + } + + /** + * 输出数据 + * @param $data // 待数据 + * @param $is_die // 是否停止运行 + * @return void + */ + function dump($data, $is_die = true) { + var_dump($data); + if ($is_die) die; + } + + /** + * @param $requestData + * @param $url + * @param $host_path + * @return array|void + */ + function request_create_data($requestData,$url,$host_path = '',$encrypt = false) + { + # 验证传输数据 + 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' => $encrypt ? json_encode($requestData) : base64_encode(json_encode($requestData)), + 'token' => md5($token . date('Ymd')) + ]; + $date = (int)date("d"); + $date['signature'] = md5($token . ($date % 2) . md5($data['data'])); + $json_data = json_encode($data); + $createUrl = $host_path . $url; + # 发起请求 + $result = $this->post_token($createUrl,$json_data,false,[],$token); +var_dump($result); +$result = json_decode($result,true); +var_dump($result); + # 判断返回信息 + if ($result['code'] != 1) return ['status' => 0, 'msg' => $result['msg']]; + return ['status' => 1]; + } + + + function get_real_group_ids($config,$token,$dataType) + { + $url = $config['host_url'] . "/api/cfas/v2/countGroup/groups/page"; + $pageNo = 1; + $pageSize = 1; + + $groupIdArr = []; + while (1) { + + $dataArr = [ + "regionId" => "root000000", + "isCascade" => 1, + "groupType" => 0, + "statType" => 0, + "pageNo" => $pageNo, + "pageSize" => $pageSize + ]; + + $json_data = json_encode($dataArr); + $result = $this->post_token($url, $json_data, false, [], $token); + $res_data = json_decode($result, true); + + # 存在错误结束循环 + if ($res_data['code'] != 0) break; + # 数据不存在结束循环 + $list = (array)$res_data['data']['list']; + if (empty($list)) break; + + foreach ($list as $value) { + + $groupIdArr[] = $value['groupId']; + } + + # 总条数不够结束循环 + if (count($list) < $pageSize) break; + ++$pageNo; + } + + return $dataType == 2 ? $groupIdArr : implode(",", $groupIdArr); + } +} diff --git a/tasks/Group.php b/tasks/Group.php index dff103e..1ebd448 100644 --- a/tasks/Group.php +++ b/tasks/Group.php @@ -2,17 +2,15 @@ namespace task\tasks; use task\module\Pass\Pass; +include 'Base.php'; -$aa = new Group(); -echo $aa->run(); -class Group +class Group extends Base { function run() { - include_once '../common.php'; - include_once '../module/Pass/Pass.php'; - $config = config('api_config'); - $token = get_access_token(); + $config = $this->config('api_config'); + //var_dump($config);die; + $token = $this->get_access_token(); $url = $config['host_url'] . "/api/cfas/v2/countGroup/groups/page"; @@ -32,7 +30,7 @@ class Group ]; $json_data = json_encode($dataArr); - $result = post_token($url,$json_data,false,[],$token); + $result = $this->post_token($url,$json_data,false,[],$token); $res_data = json_decode($result,true); @@ -50,12 +48,12 @@ class Group 'groupType' => $value['groupType'], 'statType' => $value['statType'], 'regionId' => $value['regionId'], - 'thirdPartCode' => $value['thirdPartCode'], + 'thirdPartCode' => $value['thirdPartCode'] ?: '', 'workStartTime' => $value['workStartTime'], 'workEndTime' => $value['workEndTime'], 'holdBase' => $value['holdBase'], - 'earlyWarningValue' => $value['earlyWarningValue'], - 'warningValue' => $value['warningValue'], + 'earlyWarningValue' => $value['earlyWarningValue'] ?: '', + 'warningValue' => $value['warningValue'] ?: '', 'warningSwitch' => $value['warningSwitch'] ]; @@ -67,7 +65,7 @@ class Group ++$pageNo; } - $requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createGroup',$config['host_path']); + $requestRes = $this->request_create_data($requestData,'/api/pass.create/createGroup',$config['host_path']); if (!$requestRes['status']) { return $requestRes['msg']; @@ -75,4 +73,6 @@ class Group return true; } -} \ No newline at end of file +} +$aa = new Group(); +echo $aa->run(); diff --git a/tasks/Lib.php b/tasks/Lib.php index 9edbc2c..7bc488e 100644 --- a/tasks/Lib.php +++ b/tasks/Lib.php @@ -10,51 +10,52 @@ class Lib extends Base public $libCameraId = [ [ 'groupId' => 'baz001', # 分馆代码 - 'name' => '宝安图书馆', # 单位名称 - 'cameraId' => '9,7,6,4,2,1,67,3', # 客流系统内分馆摄像头 + 'name' => '图书馆', # 单位名称 + 'cameraId' => '9,7,6,4,2,1,67,3,135,144,145', # 客流系统内分馆摄像头 ], [ 'groupId' => 'BAF055', - 'name' => '1990分馆', - 'cameraId' => '134,135', + 'name' => '文化馆', + 'cameraId' => '134,141,142', ] ]; public function run() { $config = $this->config('api_config'); - + $requestData = []; $allData = $this->getBaoAnLibData(); - $tempAllArr = [ - 'groupId' => 'lib001', - 'groupName' => '图书馆' + 'group_id' => 'lib001', + 'group_name' => base64_encode('文化') ]; - foreach ($allData as $allKey => $allValue) { + /*foreach ($allData as $allKey => $allValue) { foreach ($allValue as $aKey => $aValue) { $tempAllArr[$allKey."_".$aKey] = $aValue; } - } - $requestData[] = $tempAllArr; - + }*/ $libData = $this->getBaoAnLibData(true); foreach ($libData as $row) { $tempArr = [ - 'groupId' => $row['groupId'], - 'groupName' => $row['name'] + 'group_id' => $row['groupId'], + 'group_name' => base64_encode($row['name']) ]; foreach ($row['data'] as $key => $value) { foreach ($value as $k => $v) { - $tempArr[$key."_".$k] = $v; + $field = $key."_".$k; + $tempArr[$field] = $v ?: 0; + if (!isset($tempAllArr[$field])) $tempAllArr[$field] = 0; + $tempAllArr[$field] += $tempArr[$field]; } } $requestData[] = $tempArr; } + $requestData[] = $tempAllArr; - $requestRes = $this->request_create_data($requestData,'/api/library.pass/create',$config['host_path']); + $requestRes = $this->request_create_data($requestData,'/api/library.pass/create',$config['host_path'],true); if (!$requestRes['status']) { return $requestRes['msg']; @@ -63,6 +64,15 @@ class Lib extends Base return true; } + + // 获取图书馆借阅,办证数据 + public function runService() + { + $url = 'http://10.99.57.79:9999/SSBusiness/monitor/getLibraryService?library=044007'; + $result = $this->curl_post($url); + $result_data = json_decode($result,true); + var_dump($result);die; + } /** * @param $is_group @@ -76,6 +86,7 @@ class Lib extends Base foreach ($this->libCameraId as $value) { $url = $this->libUrl . '&cameraid=' . $value['cameraId']; $result = $this->curl_post($url); +var_dump($result); $result = json_decode($result,true); $data[] = [ 'data' => $result, @@ -93,4 +104,4 @@ class Lib extends Base } $lib = new Lib(); -echo $lib->run(); \ No newline at end of file +echo $lib->run(); diff --git a/tasks/LibLease.php b/tasks/LibLease.php new file mode 100644 index 0000000..0d0bb16 --- /dev/null +++ b/tasks/LibLease.php @@ -0,0 +1,36 @@ +config('api_config'); + $url = 'http://10.99.57.79:9999/SSBusiness/monitor/getLibraryService?library=044007'; + $result = $this->get_data($url,'balib','Ba2015lib'); + $result_data = json_decode($result,true); + + if ($result_data['success'] != 1) return '失败'; + $content = $result_data['content']; + if (!$content) return '数据不存在'; + + $requestData = [ + [ + 'library' => $result_data['library'], + 'newreader' => $content['newreader'], + 'servcount' => $content['servcount'], + 'returncount' => $content['returncount'] + ] + ]; + $requestRes = $this->request_create_data($requestData,'/api/library.pass/createLibraryLease',$config['host_path'],true); + + if (!$requestRes['status']) return $requestRes['msg']; + + return true; + } + +} +$lib = new LibLease(); +echo $lib->run(); diff --git a/tasks/Pass.php b/tasks/Pass.php index c1821ca..278f305 100644 --- a/tasks/Pass.php +++ b/tasks/Pass.php @@ -2,17 +2,14 @@ namespace task\tasks; -$pass = new Pass(); -echo $pass->run(); -class Pass +include 'Base.php'; +class Pass extends Base { public function run() { - include_once '../common.php'; - include_once '../module/Pass/Pass.php'; - $config = config('api_config'); - $dateData = get_target_date(); - $token = get_access_token(); + $config = $this->config('api_config'); + $dateData = $this->get_target_date(); + $token = $this->get_access_token(); $arr = [ 'hourly' => [ @@ -33,7 +30,7 @@ class Pass $requestData = []; try { - $ids = \task\module\Pass\Pass::getRealGroupIds($config,$token,1); + $ids = $this->get_real_group_ids($config,$token,1); foreach ($arr as $granularity => $value) { $dataArr = [ @@ -44,7 +41,7 @@ class Pass ]; $json_data = json_encode($dataArr); - $result = post_token($url,$json_data,false,[],$token); + $result = $this->post_token($url,$json_data,false,[],$token); $res_data = json_decode($result,true); if ($res_data['code'] != 0) throw new \Exception('请求失败'); @@ -54,14 +51,14 @@ class Pass $insert_arr = [ 'groupId' => $val['groupId'], 'groupName' => $val['groupName'], - 'flowInNum' => $val['flowInNum'], - 'flowOutNum' => $val['flowOutNum'], - 'noRepeatInNum' => $val['noRepeatInNum'], - 'noRepeatOutNum' => $val['noRepeatOutNum'], - 'holdValue' => $val['holdValue'], + 'flowInNum' => $val['flowInNum'] ?: 0, + 'flowOutNum' => $val['flowOutNum'] ?: 0, + 'noRepeatInNum' => $val['noRepeatInNum'] ?: 0, + 'noRepeatOutNum' => $val['noRepeatOutNum'] ?: 0, + 'holdValue' => $val['holdValue'] ?: 0, 'createTime' => $val['createTime'], 'updateTime' => $val['updateTime'], - 'netValue' => $val['netValue'], + 'netValue' => $val['netValue'] ?: 0, 'statTime' => $val['statTime'], 'granularity' => $granularity, ]; @@ -74,7 +71,7 @@ class Pass return $e->getMessage(); } - $requestRes = \task\module\Pass\Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlow', $config['host_path']); + $requestRes = $this->request_create_data($requestData,'/api/pass.create/createPassengerFlow', $config['host_path']); if (!$requestRes['status']) { return $requestRes['msg']; @@ -82,4 +79,7 @@ class Pass return true; } -} \ No newline at end of file +} + +$pass = new Pass(); +echo $pass->run(); diff --git a/tasks/Passall.php b/tasks/Passall.php index 04a5083..1d28ecf 100644 --- a/tasks/Passall.php +++ b/tasks/Passall.php @@ -2,19 +2,15 @@ namespace task\tasks; -use task\module\Pass\Pass; -$Passall = new Passall(); -echo $Passall->run(); -class Passall +include 'Base.php'; +class Passall extends Base { public function run() { - include_once '../common.php'; - include_once '../module/Pass/Pass.php'; - $config = config('api_config'); - $dateData = get_target_date(); - $token = get_access_token(); + $config = $this->config('api_config'); + $dateData = $this->get_target_date(); + $token = $this->get_access_token(); $dateArr = [ 'day' => [ @@ -43,7 +39,7 @@ class Passall $requestData = []; try { - $ids = Pass::getRealGroupIds($config,$token,1); + $ids = $this->get_real_group_ids($config,$token,1); foreach ($dateArr as $date => $value) { @@ -58,7 +54,7 @@ class Passall ]; $json_data = json_encode($dataArr); - $result = post_token($url,$json_data,false,[],$token); + $result = $this->post_token($url,$json_data,false,[],$token); $res_data = json_decode($result,true); if ($res_data['code'] != 0) throw new \Exception('请求失败'); @@ -67,14 +63,14 @@ class Passall $insert_arr = [ 'groupId' => $val['groupId'], 'groupName' => $val['groupName'], - 'flowInNum' => $val['flowInNum'], - 'flowOutNum' => $val['flowOutNum'], - 'noRepeatInNum' => $val['noRepeatInNum'], - 'noRepeatOutNum' => $val['noRepeatOutNum'], - 'holdValue' => $val['holdValue'], + 'flowInNum' => $val['flowInNum'] ?: 0, + 'flowOutNum' => $val['flowOutNum'] ?: 0, + 'noRepeatInNum' => $val['noRepeatInNum'] ?: 0, + 'noRepeatOutNum' => $val['noRepeatOutNum'] ?: 0, + 'holdValue' => $val['holdValue'] ?: 0, 'createTime' => $val['createTime'], 'updateTime' => $val['updateTime'], - 'netValue' => $val['netValue'], + 'netValue' => $val['netValue'] ?: 0, 'statTime' => $val['statTime'], 'granularity' => $granularity, 'date' => $date, @@ -88,7 +84,7 @@ class Passall return $e->getMessage(); } - $requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowAll', $config['host_path']); + $requestRes = $this->request_create_data($requestData,'/api/pass.create/createPassengerFlowAll', $config['host_path']); if (!$requestRes['status']) { return $requestRes['msg']; @@ -96,4 +92,6 @@ class Passall return true; } -} \ No newline at end of file +} +$Passall = new Passall(); +echo $Passall->run(); diff --git a/tasks/Passreal.php b/tasks/Passreal.php index 61d598c..ab1ba96 100644 --- a/tasks/Passreal.php +++ b/tasks/Passreal.php @@ -2,61 +2,89 @@ namespace task\tasks; -use task\module\Pass\Pass; +include 'Base.php'; -$Passall = new Passreal(); -echo $Passall->run(); -class Passreal +class Passreal extends Base { public function run() { - include_once '../common.php'; - include_once '../module/Pass/Pass.php'; - $config = config('api_config'); + $config = $this->config('api_config'); $requestData = []; try{ + date_default_timezone_set('Asia/Shanghai'); + # $url = $config['host_url'] . "/api/cfas/v3/passenger/realTime"; + $url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups"; + + $token = $this->get_access_token(); + # $dataArr = $this->get_real_group_ids($config,$token,2); + $dataArr = [ + 'ids' => $this->get_real_group_ids($config,$token,1), + 'granularity' => 'daily', + 'startTime' => date("c",strtotime('today')), + 'endTime' => date('c',time()) + ]; + - $url = $config['host_url'] . "/api/cfas/v3/passenger/realTime"; - - $token = get_access_token(); - $dataArr = Pass::getRealGroupIds($config,$token,2); $json_data = json_encode($dataArr); - $result = post_token($url,$json_data,false,[],$token); + $result = $this->post_token($url,$json_data,false,[],$token); $res_data = json_decode($result,true); $list = (array) $res_data['data']; - - foreach ($list as $value) { - + $existsArr = []; + foreach ($list['list'] as $value) { + $existsArr[] = $value['groupId']; $insert_arr = [ 'groupId' => $value['groupId'], - 'regionId' => $value['regionId'], - 'statisticsTime' => $value['statisticsTime'], - 'enter' => $value['enter'], - 'exit' => $value['exit'], - 'pass' => $value['pass'] ?: '', - 'holdValue' => $value['holdValue'], - 'allEnter' => $value['allEnter'], - 'allExit' => $value['allExit'] + 'regionId' => '0', + 'statisticsTime' => $value['statTime'], + 'enter' => $value['noRepeatOutNum'], + 'exit' => $value['flowOutNum'], + 'pass' => $value['holdValue'] ?: '', + 'holdValue' => $value['netValue'], + 'allEnter' => $value['flowInNum'], + 'allExit' => $value['noRepeatInNum'] ]; #Db::table('bt_passenger_flow_real')->insert($insert_arr); $requestData[] = $insert_arr; } - + /* $idsArr = explode(",",$dataArr['ids']); + foreach ($idsArr as $id) { + $is_continue = true; + if (in_array($id,$existsArr)) $is_continue = false; + if ($is_continue) { + $requestData[] = [ + 'groupId' => $id, + 'regionId' => '0', + 'statisticsTime' => date("Y-m-d\TH") . ':00:00.000+08:00', + 'enter' => 0, + 'exit' => 0, + 'pass' => 0, + 'holdValue' => 0, + 'allEnter' => 0, + 'allExit' => 0 + ]; + } + }*/ } catch (\Exception $e) { return $e->getMessage(); } - $requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createPassengerFlowReal', $config['host_path']); + $requestRes = $this->request_create_data($requestData,'/api/pass.create/createPassengerFlowReal', $config['host_path'],true); if (!$requestRes['status']) { return $requestRes['msg']; } - + #$file = fopen('/tmp/passreal.txt','a'); + #$file_msg = '['.date('Y-m-d H:i:s',time()).']'; + #fwrite($file,$file_msg . PHP_EOL); + #fclose($file); + # file_put_contents('/tmp/passreal.txt','['.date('Y-m-d H:i:s',time()).']'.PHP_EOL,FILE_APPEND); return true; } -} \ No newline at end of file +} +$Passall = new Passreal(); +echo $Passall->run(); diff --git a/tasks/Video.php b/tasks/Video.php index ec818ab..817175b 100644 --- a/tasks/Video.php +++ b/tasks/Video.php @@ -2,29 +2,41 @@ namespace task\tasks; -use task\module\Pass\Pass; - -$Video = new Video(); -echo $Video->run(); -class Video +include 'Base.php'; +class Video extends Base { public function run() { - include_once '../common.php'; - include_once '../module/Pass/Pass.php'; - $config = config('api_config'); + $config = $this->config('api_config'); $url = $config['host_url'] . "/api/resource/v1/cameras"; - $token = get_access_token(); + $token = $this->get_access_token(); # 获取视频资源 try { + $regionIndexCodeArr = []; + + $regionUrl = $config['host_url'] . '/api/irds/v2/region/nodesByParams'; + $regionReqData = [ + 'resourceType' => 'region', + 'pageNo' => 1, + 'pageSize' => 100 + ]; + $regionRes = $this->post_token($regionUrl,json_encode($regionReqData),false,[],$token); + $regionResData = json_decode($regionRes,true); + + if ($regionResData['code'] != 0) throw new \Exception('获取区域信息失败'); + $regionList = (array)$regionResData['data']['list']; + foreach ($regionList as $regionRow) { + $regionIndexCodeArr[$regionRow['indexCode']] = $regionRow['name']; + } + $dataArr = [ 'pageNo' => 1, 'pageSize' => 100, ]; $json_data = json_encode($dataArr); - $result = post_token($url,$json_data,false,[],$token); + $result = $this->post_token($url,$json_data,false,[],$token); $res_data = json_decode($result,true); if ($res_data['code'] != 0) throw new \Exception('请求失败'); @@ -32,6 +44,7 @@ class Video $requestData = []; foreach ($list as $row) { + # 获取监控点视频链接 $cameraIndexCode = $row['cameraIndexCode']; @@ -45,27 +58,30 @@ class Video 'streamform' => 'ps' ]; $json_data2 = json_encode($dataArr2); - $result2 = post_token($url2,$json_data2,false,[],$token); + $result2 = $this->post_token($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'], + 'cameraName' => base64_encode($row['cameraName']), 'cameraType' => $row['cameraType'], 'cameraTypeName' => $row['cameraTypeName'], 'regionIndexCode' => $row['regionIndexCode'], 'transTypeName' => $row['transTypeName'], 'transType' => $row['transType'], 'createTime' => $row['createTime'], - 'url' => $row2 + 'url' => $row2, + 'regionName' => isset($regionIndexCodeArr[$row['regionIndexCode']]) ? base64_encode( $regionIndexCodeArr[$row['regionIndexCode']]) : '' ]; } } - $requestRes = Pass::requestCreateData($requestData,'/api/pass.create/createVideo', $config['host_path']); + + $requestRes = $this->request_create_data($requestData,'/api/pass.create/createVideo', $config['host_path'],true); if (!$requestRes['status']) { return $requestRes['msg']; @@ -77,4 +93,6 @@ class Video return true; } -} \ No newline at end of file +} +$Video = new Video(); +echo $Video->run();