中国天气网天气预报接口
2015-04-24 16:31
330 查看
全国城市天气: http://flash.weather.com.cn/baidumap/xml/china.xml ------------------------------------------------------------------------------------
function getWeatherWeather($city){include 'weather_code.php';$code=$weather_code[$city];$url="http://d1.weather.com.cn/cx_15fcall/$code.html?callback=callBack_fc15";$file=curl_get_contents($url);$file=str_replace("callBack_fc15(", "", $file);$file=str_replace(")", "", $file);$str_json=json_decode($file);$weather_arr=$str_json->weafc15;$size=count($weather_arr);for($i=0;$i< 4;$i++){$weather_arr2=$weather_arr[$i];$week=$weather_arr2->week;//星期$wea=$weather_arr2->wea;//天气情况$tem1=$weather_arr2->tem1;//温度1$tem2=$weather_arr2->tem2;//温度2$winP1=$weather_arr2->winP1;//风速1$winP2=$weather_arr2->winP2;//风速2$tianqi_tubiao_day=$weather_arr2->img;//白天天气图标$tianqi_tubiao_day=str_replace("d0", "", $tianqi_tubiao_day);$tianqi_tubiao_day='http://tianqi.911cha.com/pic/day/'. ($tianqi_tubiao_day+1).'.gif';$tianqi_tubiao_night=$weather_arr2->imgn;//晚上天气图标$tianqi_tubiao_night=str_replace("n0", "", $tianqi_tubiao_night);$tianqi_tubiao_night='http://tianqi.911cha.com/pic/day/'. ($tianqi_tubiao_night+1).'.gif';$tianqi=$tem1.'~'.$tem2.'℃ '.$wea.' '.$winP1;//就加一个风速吧。$arr[$i]=array('date'=>$week,'tianqi'=>$tianqi,'pic'=>$tianqi_tubiao_day);}return $arr;}function curl_get_contents($url){$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url); //设置访问的url地址//curl_setopt($ch, CURLOPT_POST, true);//curl_setopt($ch, CURLOPT_POSTFIELDS, "IdCard={$content}");//curl_setopt($ch,CURLOPT_HEADER,1); //是否显示头部信息curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1'); //用户访问代理 User-Agentcurl_setopt($ch, CURLOPT_REFERER,"http://www.weather.com.cn");//这个一定要加。//curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1); //跟踪301curl_setopt($ch, CURLOPT_TIMEOUT, 2); //设置超时curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回结果curl_setopt($ch, CURLOPT_COOKIE, "");$result = curl_exec($ch);curl_close($ch);return $result;}weather_code.php 文件在http://blog.csdn.net/macwhirr123/article/details/45173209中有。
相关文章推荐
- PHP 调用接口生成天气预报 三级联动城市列表 仿中国天气网界面
- 天气预报接口(中国天气网)
- 天气预报接口(中国天气网)
- 天气预报接口(中国天气网)
- 中国天气网天气预报接口
- 中国天气网免费天气预报接口API
- 中国天气网免费天气预报接口API
- 调用“中国天气网”官网数据接口显示天气预报
- 天气预报接口(中国天气网)
- 天气预报接口(中国天气网)
- 天气预报接口(中国天气网)
- 天气预报接口(中国天气网) .
- 天气预报接口IOS版OC:SmartWeather API中key的计算方法
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- 国家气象局提供的天气预报接口
- 开源免费天气预报接口API以及全国所有地区代码!!
- 天气API-----开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- 天气预报接口
- 国家气象局提供的天气预报接口及使用说明
- 百度天气预报接口