天天看點

php根據城市擷取天氣預報,根據浏覽者ip擷取城市,然後在擷取城市天氣預報

public function getCity() {

$ip = $_SERVER["REMOTE_ADDR"];

$city = $this->getUrl('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.$ip);

$cityarr = json_decode($city,true);

//城市名稱

$cityname = $cityarr['city'];

return $cityname;

}

public function getWeatherinfo() {

$cityname = $this->getCity();

$data = $this->getUrl('http://www.sojson.com/open/api/weather/json.shtml?city='.$cityname);

$weatherdata =json_decode($data,true);

天氣預報接口來自

新浪擷取經城市接口http://int.dpool.sina.com.cn