Shuiwen.php
3.1 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
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 验证接口
*/
class Shuiwen extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = '*';
public $api = null;
protected $cookiedata = null;
function getcookie()
{
// 创建一个cURL资源
$curl = curl_init();
// 设置请求的URL
$url = "http://60.161.5.61:8087/web/login.do?mode=db&j_username=lxslj&j_password=LxslJ@2023&validateCode=nsyc";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
curl_close($ch);
// 获取响应标头中的cookie内容
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $header, $matches);
$cookies = array();
foreach ($matches[1] as $cookie) {
parse_str($cookie, $cookieArr);
$cookies = array_merge($cookies, $cookieArr);
}
//返回cookie内容
$this->cookiedata=$cookies['JSESSIONID'];
return $cookies['JSESSIONID'];
}
public function getwaterlevel()
{
$postres = $this->send_get("http://60.161.5.61:8087/web/realdata/realdataquerydata.do?stcdlist='80235810','80235820'&type=0");
$postres=json_decode($postres,true);
foreach ($postres['rows'] as $k=>$v){
$waterleveldata = [
'water_level' => $postres['rows'][$k]['39'],
'reservoir_id' => 40,
'createtime' => time(),
'reporttime' => time(),
'flow' => $postres['rows'][$k]['27'],
'number' => $postres['rows'][$k]['STCD']
];
Db::name("reservoir_rain_water_level")->insert($waterleveldata);
$waterleveldata = [
'rainfall' => $postres['rows'][$k]['1A'],
'total_rainfall' => $postres['rows'][$k]['1F'],
'reservoir_id' => 40,
'createtime' => time(),
'reporttime' => time(),
'number' => $postres['rows'][$k]['STCD']
];
Db::name("reservoir_rain_rainfall")->insert($waterleveldata);
}
return;
}
function send_get($url)
{
$Cookie=$this->getcookie();
$header="Cookie:JSESSIONID=".$Cookie;
$options = array(
"http" => array(
"method" => "GET", //or GET
"header" => "Cookie:JSESSIONID=".$Cookie,
"timeout" => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
public function shuiwenlogin(){
$postres=$this->send_get("http://60.161.5.61:8087/web/login.do?mode=db&j_username=lxslj&j_password=LxslJ@2023&validateCode=nsyc");
print_r($postres);return;
}
}