Weatherwarning.php
1.7 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 首页接口
*/
class Weatherwarning extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $url = "https://api.caiyunapp.com/v2.6/HQi1gyemirzw5Nfd/";
/**
* 天气预警计划任务
* @return void
*/
public function weatherwarning(){
//查询需要检测点
$detectionaddress=Db::name("detectionaddress")->select();
foreach ($detectionaddress as $k=>$v){
$url=$v['lng'].','.$v['lat']."/realtime?alert=true";
$res=send_post($this->url.$url,[],'GET');
$res=json_decode($res,true);
if($res['result']['alert']['content']){
foreach ($res['result']['alert']['content'] as $ks=>$vs){
$warning_grade=substr($res['result']['alert']['content'][$ks]['code'],'2',2);//截取预警等级
$res['result']['alert']['content'][$ks]['code'];
$data=[
'detectionaddress_id'=>$detectionaddress[$k]['id'],
'warning_grade'=>$warning_grade,
'describe'=>$res['result']['alert']['content'][$ks]['description']
];
Db::name('weatherwarning')->insert($data);
}
}else{
$data=[
'detectionaddress_id'=>$detectionaddress[$k]['id'],
'warning_grade'=>5,
'describe'=>"暂无天气预警信息"
];
Db::name('weatherwarning')->insert($data);
}
}
$this->success("天气预警成功");
}
}