宝体数据调用接口
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.
 
 
 
 
 
 

77 lines
2.6 KiB

<?php
namespace app\task\controller;
use think\Db;
class Video
{
public function run()
{
$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',
'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;
}
}