Ysyun.php
4.3 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
<?php
/**
* Created by PhpStorm.
* User: pcl
* Date: 2023/9/1
* Time: 9:49
*/
namespace app\api\controller;
use app\common\controller\Api;
use fast\Http;
use think\Db;
/**
* 验证接口
*/
class Ysyun extends Api
{
protected $noNeedLogin = '*';
protected $layout = '';
protected $error = null;
protected $appKey;
protected $appSecret;
public function _initialize()
{
parent::_initialize();
$this->appKey = '59abe2483ddb416084b7820b5cf517b5';
$this->appSecret = '6a91527ddc8d223ae577533cdb32a54b';
}
/***
* 萤时云定时获得accessToken
* 每6天执行1次
*/
public function getaccessToken()
{
$url = "https://open.ys7.com/api/lapp/token/get";
$post_data = [
'appKey' => $this->appKey,
'appSecret' => $this->appSecret,
];
$accessToken = send_post($url, $post_data, "POST");
$accessToken = json_decode($accessToken, true);
if ($accessToken['code'] == 200) {
//更新token
$access_token = $accessToken['data']['accessToken'];
return $access_token;
} else {
//重新执行1次
$this->getaccessToken();
}
}
/***
* 定时任务,第5小时执行
* 更新设备在线状态信息
*/
public function upHkStatus()
{
//获得设备列表
$list = Db::name('reservoir_hkws_hardware')
->field('id,scode')
->select();
if ($list) {
$token = $this->getaccessToken();
foreach ($list as $k => $v) {
//接口获得设备状态
$res = $this->getHkAllinfo($token, $v['scode']);
if ($res != -1) {
//更新状态
$data['updatetime'] = time();
$data['status'] = $res['status'] == 1 ? 1 : 2;
$rs = Db::name('reservoir_hkws_hardware')
->where(['scode' => $v['scode']])
->update($data);
}
}
}
$this->success('执行成功', $rs);
}
/***
* 获得指定设备的详细信息
*/
protected function getHkAllinfo($token, $scode)
{
$url = "https://open.ys7.com/api/lapp/device/info";
$post_data = [
'accessToken' => $token,
'deviceSerial' => $scode,
];
$info = send_post($url, $post_data, "POST");
$info = json_decode($info, true);
if ($info['code'] == 200) {
return $info['data'];//['status']在线状态:0-不在线,1-在线
} else {
return -1;
}
}
/***
* 获得指定设备的播放地址
*/
public function getHkAddress($data)
{
$url = "https://open.ys7.com/api/lapp/v2/live/address/get";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
/***
* 获得指定设备的播放地址
*/
public function getquery($data)
{
$url = "https://open.ys7.com/api/lapp/voice/query";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
/***
* 获得指定设备的播放地址
*/
public function send($data)
{
$url = "https://open.ys7.com/api/lapp/voice/send";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
/***
* 取消视频加密
*/
public function Cameraoff($data)
{
$url = "https://open.ys7.com/api/lapp/device/encrypt/off";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
/***
* 操作云台开始
*/
public function ytCenterStart($data)
{
$url = "https://open.ys7.com/api/lapp/device/ptz/start";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
/***
* 操作云台结束
*/
public function ytCenterStop($data)
{
$url = "https://open.ys7.com/api/lapp/device/ptz/stop";
$info = send_post($url, $data, "POST");
$info = json_decode($info, true);
return $info;
}
}