header("content-type:text/html;charset=utf-8");
date_default_timezone_set("Asien/Shanghai");
error_reporting(0);
// Bestimmen Sie die Stadt anhand der IP
$user_ip = $_SERVER['REMOTE_ADDR'];
$url ="http://int.dpool.sina.com.cn/iplookup/iplookup.php ?format =json&ip=$user_ip";
$address = file_get_contents($url);
$address_arr = json_decode($address); // Das Objekt zurückgeben und in ein Array konvertieren müssen
//Nehmen Sie Shanghai als Beispiel
stdClass Object | |
( | |
[ret] => 1 | |
[start] => -1 | |
[end] => -1 | |
[country] => 中国 | |
[province] => 上海 | |
[city] => 上海 | |
[district] => | |
[isp] => | |
[type] => | |
[desc] => | |
) |
Array | |
( | |
[ret] => 1 | |
[start] => -1 | |
[end] => -1 | |
[country] => 中国 | |
[province] => 上海 | |
[city] => 上海 | |
[district] => | |
[isp] => | |
[type] => | |
[desc] => | |
) |
$city = $address_arr["city"];
$con=file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=$city&output=json&ak=spmMww7Eoqcmf3FXbnLyDUwL"); //Beachten Sie, dass der ak-Wert registriert werden muss die Baidu-Schnittstelle, angehängte Adresse: http://lbsyun.baidu.com/apiconsole/key
$con = json_decode($con);
stdClass-Objekt | |
( | |
[Fehler] => 0 | |
[status] => Erfolg | |
[Datum] => 23.09.2016 | |
[Ergebnisse] => Array | |
( | |
[0] => stdClass-Objekt | |
( | |
[aktuelleStadt] => 上海 | |
[pm25] => 42 | |
[index] => Array | |
( | |
[0] => stdClass-Objekt | |
( | |
[Titel] => 穿衣 | |
[zs] => 热 | |
[tipt] => 穿衣指数 | |
[des] => 天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装. | |
) | |
[1] => stdClass-Objekt | |
( | |
[Titel] => 洗车 | |
[zs] => 较适宜 | |
[tipt] => 洗车指数 | |
[des] => 较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天. | |
) | |
[2] => stdClass-Objekt | |
( | |
[Titel] => 旅游 | |
[zs] => 适宜 | |
[tipt] => 旅游指数 | |
[des] => 天气较好,但丝毫不会影响您出行的心情。温度适宜又有微风相伴,适宜旅游。 | |
) | |
[3] => stdClass-Objekt | |
( | |
[Titel] => 感冒 | |
[zs] => 少发 | |
[tipt] => 感冒指数 | |
[des] => 各项气象条件适宜, 无明显降温过程, 发生感冒机率较低. | |
) | |
[4] => stdClass-Objekt | |
( | |
[title] => Sport | |
[zs] => besser geeignet | |
[tipt] => Sportindex | |
[des] => Das Wetter ist schön, bitte achten Sie beim Training im Freien auf Sonnenschutz. Indoor-Übungen werden empfohlen. | |
) | |
[5] => stdClass-Objekt | |
( | |
[title] => UV-Intensität | |
[zs] => Schwach | |
[tipt] => UV-Intensitätsindex | |
[des] => Die Intensität der ultravioletten Strahlen ist schwach. Es wird empfohlen, vor dem Ausgehen Sonnenschutz-Hautpflegeprodukte mit Lichtschutzfaktor zwischen 12 und 15 aufzutragen. | |
) | |
) | |
[weather_data] => Array | |
( | |
[0] => stdClass-Objekt | |
( | |
[Datum] => Freitag, 23. September (Echtzeit: 26℃) | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/duoyun.png | |
[Wetter] => Bewölkt | |
[Wind] => Ostbrise | |
[Temperatur] => 27 ~ 21℃ | |
) | |
[1] => stdClass-Objekt | |
( | |
[Datum] => Samstag | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/duoyun.png | |
[Wetter] => Bewölkt | |
[Wind] => Ostbrise | |
[Temperatur] => 28 ~ 23℃ | |
) | |
[2] => stdClass-Objekt | |
( | |
[Datum] => Sonntag | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/yin.png | |
[Wetter] => Bewölkt bis bewölkt | |
[Wind] => Ostbrise | |
[Temperatur] => 28 ~ 23℃ | |
) | |
[3] => stdClass-Objekt | |
( | |
[Datum] => Montag | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/yin.png | |
[Wetter] => Bewölkt bis bewölkt | |
[Wind] => Nordöstliche Brise | |
[Temperatur] => 29 ~ 25℃ | |
) | |
) | |
) | |
) | |
) |
$arr = object_array($con); //Konvertierung in Array-Operation fortsetzen
$detail = $arr["results"][0]["weather_data"];
$city = $arr["results"][0]["currentCity"];
print_r($detail);
Array | |
( | |
[0] => Array | |
( | |
[date] => 周五 09月23日 (实时:26℃) | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/duoyun.png | |
[weather] => 多云 | |
[wind] => 东风微风 | |
[temperature] => 27 ~ 21℃ | |
) | |
[1] => Array | |
( | |
[date] => 周六 | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/duoyun.png | |
[weather] => 多云 | |
[wind] => 东风微风 | |
[temperature] => 28 ~ 23℃ | |
) | |
[2] => Array | |
( | |
[date] => 周日 | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/yin.png | |
[weather] => 多云转阴 | |
[wind] => 东风微风 | |
[temperature] => 28 ~ 23℃ | |
) | |
[3] => Array | |
( | |
[date] => 周一 | |
[dayPictureUrl] => http://api.map.baidu.com/images/weather/day/duoyun.png | |
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/yin.png | |
[weather] => 多云转阴 | |
[wind] => 东北风微风 | |
[temperature] => 29 ~ 25℃ | |
) | |
) |
//Holen Sie sich Wetterdaten und passen Sie diese an Ihre Bedürfnisse an
?>