Isc.php
6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
namespace app\api\controller\reservoir\hkws;
use app\common\controller\Api;
use think\Request;
use think\Db;
use isc\Api as Iscapi;
/**
* Class Displacement
* @package app\api\controller
*/
class Isc extends Api
{
protected $noNeedLogin = ['playbackUrl','CameraUrlall','getCameraUrl', 'getcamera_search','getCameraUrl', 'getTestTalkUrl', 'take_pic', 'voice_zhanyong_username'];
protected $noNeedRight = '*';
public $api = null;
public function _initialize()
{
parent::_initialize();
$this->api = new Iscapi();
}
public function getCameraUrl()
{
$cameraIndexCode = input('post.cameraIndexCode');
$protocol = input('post.protocol', 'rtsp');
$streamType = input('post.streamType', 0);
if ($streamType == 0) {
$stype = 1;
} else {
$stype = 0;
}
$res = $this->api->getPreviewUrl($cameraIndexCode, $protocol, $stype);
//获得监控信息,经纬度查询天气预报
$info = Db::name('reservoir_hkws_hardware')
->where(['indexCode' => $cameraIndexCode])
->field('id,latitude,longitude,indexCode')
->find();
$res['data']['latitude'] = $info['latitude'];
$res['data']['longitude'] = $info['longitude'];
$data['camera'] = $res;
$res = $this->getTalkUrlFunc($cameraIndexCode);
$data['talk'] = $res;
$this->success('', $data);
}
/**
* 回放功能
* @return void
*/
public function playbackUrl()
{
$cameraIndexCode = input('cameraIndexCode');
$begin_time = input('beginTime');
$end_time = input('endTime');
//时间要为DATE_ISO8601格式 这个等接接口的时候看前端传什么格式的时间再调整
if($begin_time>time()){
$this->error("时间选择错误");
}
if($end_time>time()){
$this->error("时间选择错误");
}
$beginTime = date("Y-m-d\TH:i:s",$begin_time).".000+08:00";
$endTime = date("Y-m-d\TH:i:s",$end_time).".000+08:00";
$res = $this->api->playbackUrl($cameraIndexCode,$beginTime,$endTime);
if($res['code']=="0"){
foreach ($res['data']['list'] as $k=>$v){
$res['data']['list'][$k]['beginTime']=date("Y-m-d H:i:s",strtotime($res['data']['list'][$k]['beginTime']));
$res['data']['list'][$k]['endTime']=date("Y-m-d H:i:s",strtotime($res['data']['list'][$k]['endTime']));
}
$this->success('请求成功', $res);
}else{
$data=['cameraIndexCode'=>$cameraIndexCode,'begin_time'=>$begin_time,'end_time'=>$end_time];
$errdata=[
'data'=>$data,
'res'=>$res
];
$this->error('请求失败',$errdata);
}
}
public function CameraUrlall(){
$protocol = $this->request->param('protocol');
$hardware=Db::name("reservoir_hkws_hardware")->where('reservoir_id',27)->limit(16)->select();
$streamType = "1";
$return_data=[];
foreach ($hardware as $k=>$v){
$cameraIndexCode = $hardware[$k]['indexCode'];
$res = $this->api->getPreviewUrl($cameraIndexCode,$protocol,$streamType);
$return_data[$k]=$res;
$return_data[$k]['name']=$hardware[$k]['name '];
}
$this->success('',$return_data);
}
public function getTalkUrl()
{
$cameraIndexCode = input('post.cameraIndexCode');
$res = $this->api->getTalkUrl($cameraIndexCode);
$this->success('', $res);
}
public function getTalkUrlFunc($cameraIndexCode)
{
$res = $this->api->getTalkUrl($cameraIndexCode);
return $res;
}
public function getTestTalkUrl()
{
$cameraIndexCode = input('get.cameraIndexCode');
$res = $this->api->testgetPreviewUrl($cameraIndexCode);
$this->success('', $res);
}
public function getcamera_search()
{
$res = $this->api->testgetcamera_searchUrl();
$this->success('', $res);
}
public function yuntai()
{
$cameraIndexCode = input('post.cameraIndexCode');
$action = input('post.action');
$command = input('post.command');
$speed = input('post.speed');
$res = $this->api->controlling($cameraIndexCode, $action, $command, $speed);
$this->success('', $res);
}
/**
* 手动抓图
*/
public function take_pic()
{
$cameraIndexCode = input('post.cameraIndexCode');
$res = $this->api->manualCapture($cameraIndexCode);
$this->success('', $res);
}
/**
* 15. 语音通道占用与解除占用
*/
public function operate_voice()
{
$param = $this->request->param();
if (empty($param['cameraIndexCode'])) {
$this->error("设备编码不能为空");
}
if (empty($param['type'])) {
$this->error("操作类型不能为空");
}
$hardware = Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->find();
if (empty($hardware)) {
$this->error("未找到有效设备");
}
if ($param['type'] == 1) {
//开启占用
Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->update(["intercom_occupancy_userid" => $this->auth->id]);
$uid = $this->auth->id;
} elseif ($param['type'] == 2) {
//解除占用
Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->update(["intercom_occupancy_userid" => ""]);
$uid = "";
}
$this->success("操作成功", $uid);
}
/**
* 16. 获取语音对讲占用人
*/
public function voice_zhanyong_username()
{
$param = $this->request->param();
if (empty($param['cameraIndexCode'])) {
$this->error("设备编码不能为空");
}
$userid = Db::name("reservoir_hkws_hardware")->where("indexCode", $param['cameraIndexCode'])->value("intercom_occupancy_userid");
if (empty($userid)) {
$this->error("无人占用");
} else {
$staff_name = Db::name("inspection_staff")->where("user_id", $userid)->value("staff_name");
$this->success("占用人姓名获取成功", $staff_name);
}
}
}