-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.php
63 lines (37 loc) · 1.27 KB
/
weather.php
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
<?php
namespace bottest;
include_once 'key.php';
class Weather extends Key
{ public $text="кострома";
public function apiWeather($fields= array())
{
$url = "http://api.openweathermap.org/data/2.5/weather?q=".$this->text."&appid=".$this->weatherKey;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if($response === false)
$this->processRequestError(curl_error($ch));
curl_close($ch);
$response = json_decode($response);
return($response);
//die('$response = '. print_r($response, true)."\n");
// print_r($response['name']['main.temp']['wind.speed']);
}
private function processRequestError($error)
{
$this->processError("Ошибка" . $error);
}
public function getWeater()
{
$getText= array(
'name'=> $this->apiWeather('name'),
'temp'=>$this->apiWeather('main.temp')
);
}
}