You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
6.3 KiB
183 lines
6.3 KiB
<?php
|
|
|
|
namespace app\task\controller;
|
|
|
|
use think\Db;
|
|
|
|
class Pass
|
|
{
|
|
/**
|
|
* 执行函数
|
|
* @return bool
|
|
* @throws \think\Exception
|
|
* @throws \think\exception\PDOException
|
|
*/
|
|
public function run()
|
|
{
|
|
$config = config('api_config');
|
|
$dateData = getTargetDate();
|
|
$token = getAccessToken();
|
|
|
|
$arr = [
|
|
'hourly' => [
|
|
'startTime' => $dateData['day']['c_start_time'],
|
|
'endTime' => date('c',time()),
|
|
],
|
|
'daily' => [
|
|
'startTime' => $dateData['month']['c_start_time'],
|
|
'endTime' => date('c',time()),
|
|
],
|
|
'monthly' => [
|
|
'startTime' => $dateData['year']['c_start_time'],
|
|
'endTime' => date('c'),
|
|
]
|
|
];
|
|
|
|
$url = $config['host_url'] . "/api/cfas/v2/passengerFlow/groups";
|
|
|
|
|
|
// $delete = Db::table('bt_passenger_flow')->where('id','>',1)->delete();
|
|
|
|
$requestData = [];
|
|
try {
|
|
foreach ($arr as $granularity => $value) {
|
|
|
|
$dataArr = [
|
|
'granularity' => $granularity,
|
|
'startTime' => $value['startTime'],
|
|
'endTime' => $value['endTime'],
|
|
'ids' => '01' // --- <replace> --- //
|
|
];
|
|
|
|
$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'];
|
|
|
|
foreach ($list as $val) {
|
|
$insert_arr = [
|
|
'groupId' => $val['groupId'],
|
|
'groupName' => $val['groupName'],
|
|
'flowInNum' => $val['flowInNum'],
|
|
'flowOutNum' => $val['flowOutNum'],
|
|
'noRepeatInNum' => $val['noRepeatInNum'],
|
|
'noRepeatOutNum' => $val['noRepeatOutNum'],
|
|
'holdValue' => $val['holdValue'],
|
|
'createTime' => $val['createTime'],
|
|
'updateTime' => $val['updateTime'],
|
|
'netValue' => $val['netValue'],
|
|
'statTime' => $val['statTime'],
|
|
'granularity' => $granularity,
|
|
];
|
|
|
|
Db::table('bt_passenger_flow')->insert($insert_arr);
|
|
$requestData[] = $insert_arr;
|
|
}
|
|
|
|
}
|
|
} catch (\Exception $e) {
|
|
exit( $e->getMessage() );
|
|
}
|
|
|
|
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/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;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|