体育管项目脚本
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.

100 lines
3.5 KiB

<?php
namespace task\tasks;
include 'Base.php';
class Video extends Base
{
public function run()
{
$config = $this->config('api_config');
$url = $config['host_url'] . "/api/resource/v1/cameras";
$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 = $this->post_token($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 = $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' => base64_encode($row['cameraName']),
'cameraType' => $row['cameraType'],
'cameraTypeName' => $row['cameraTypeName'],
'regionIndexCode' => $row['regionIndexCode'],
'transTypeName' => $row['transTypeName'],
'transType' => $row['transType'],
'createTime' => $row['createTime'],
'url' => $row2,
'regionName' => isset($regionIndexCodeArr[$row['regionIndexCode']]) ? base64_encode( $regionIndexCodeArr[$row['regionIndexCode']]) : ''
];
}
}
$requestRes = $this->request_create_data($requestData,'/api/pass.create/createVideo', $config['host_path'],true);
if (!$requestRes['status']) {
return $requestRes['msg'];
}
} catch (\Exception $e) {
return $e->getMessage();
}
return true;
}
}
$Video = new Video();
echo $Video->run();
$Video = new Video();
echo $Video->run();