Fly.php
8.9 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<?php
/**
* Created by PhpStorm.
* User: YRF
* Date: 2024/6/13
* Time: 14:12
*/
namespace app\api\controller\v6;
//允许所有的跨域请求
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: *");
header('Access-Control-Allow-Methods: POST,GET,OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400');
date_default_timezone_set('PRC');
use app\common\controller\Api;
use think\Db;
use fast\Http;
use think\Request;
//无人机相关,调用saas的开放api
class Fly extends Api
{
// 无需登录的接口,*表示全部
protected $noNeedLogin = ['*'];
// 无需鉴权的接口,*表示全部
protected $noNeedRight = ['*'];
protected $baseUrl = "https://flycloud.tenyes.cn";
protected $AppKey = "flyCloud_21207808";
protected $AppSecret = "7f59d21bd34ab50815fe1bc915f10cd1";//"0eeb4c061cdf2052137101e5eec104cf";
//获得最新1张全景图
public function getpano()
{
$data = $this->request->param();
$url = $this->baseUrl . '/project/getOneNewPanoShot';
$res = Http::post($url, $data);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
/**
* 获得token
*/
public function getToken()
{
//获得token
$token = Db::name('fly_token')
->order('id desc')
->where(['id' => 1])
->value('token');
//判断token是否过期
$row = false;
if (!empty($token)) {
$row = $this->tokenCheck($token);
if ($row == true) {
$this->success("获取成功", $token);
}
}
if (empty($token) || $row == false) {
//获得新token
$tokenNew = $this->uptoken();
if (!empty($tokenNew)) {
//更新token
$to['token'] = $tokenNew;
$to['createtime'] = time();
if (empty($token)) {
Db::name('fly_token')->insertGetId($to);
} else {
Db::name('fly_token')->where(['id' => 1])->update($to);
}
$this->success("获取成功", $tokenNew);
} else {
$this->error("获取失败");
}
}
}
//获得新token
protected function uptoken()
{
$url = $this->baseUrl . '/openapi/v1/getToken';
$data['AppKey'] = $this->AppKey;
$data['AppSecret'] = $this->AppSecret;
$res = Http::post($url, $data);
$res = json_decode($res, true);
if ($res['code'] == 200) {
return $res['data']['data'];
} else {
return '';
}
}
//判断token是否过期
protected function tokenCheck($authorization)
{
$data = [];
$url = $this->baseUrl . '/openapi/v1/tokenGetUserInfo';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
return true;
} else {
return false;
}
}
/**
* 按token获得用户信息
*/
public function getUserInfo()
{
$data = $this->request->param();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/tokenGetUserInfo';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
//获得组织下的设备列表
public function getDeviceList()
{
$data = $this->request->param();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/getOrgDeviceList';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
//获得机场直播
public function getDockLive()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/dockLiveStart';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
//获得飞机直播
public function getAirLive()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/airLiveStart';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
//获得机顶直播
public function getAirTopLive()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/airTopLiveStart';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
/**
* 获得媒体分类信息统计
*/
public function getMediaCount()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/apiMediaCount_app';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
/**
* 按分类获得媒体列表
*/
public function getCatsMediaList()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/apiGetTypeMedia_app';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
/**
* 获得航线列表
*
*/
public function getFightfileList()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/getFightfileList';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
/***
*
* 获得航线航点详情
* /openapi/v1/apiGetRoutean
*/
public function getRoutean()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/apiGetRoutean';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
//创建计划
public function createPlan()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/apiCreatePlan';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
// 一键返航
public function goHome()
{
$data = $this->request->getContent();
$authorization = $this->request->header('Authorization');
$url = $this->baseUrl . '/openapi/v1/apiGohome';
$res = Http::postHeader($url, $data, [], $authorization);
$res = json_decode($res, true);
if ($res['code'] == 200) {
$this->success("获取成功", $res['data']);
} else {
$this->error($res['msg']);
}
}
}