微信开发中查询天气
2015-08-18 13:11
561 查看
现在网络上用的中国天气网的接口已经过期,需要付费,于是我做了个新的。
先到http://www.heweather.com/documents/api 免费申请 你的认证key
CITYID 可以根据这个网站建立数据库
先到http://www.heweather.com/documents/api 免费申请 你的认证key
$url = 'https://api.heweather.com/x3/weather?cityid='.$city_id.'&key=XXX'; $content=file_get_contents($url); $data=json_decode($content,true); // $data = $this->weather($city_id); $contentStr = "【".$area."天气情况】"."\n"; $contentStr .= "空气质量指数(AQI):"."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][co])$contentStr .= "一氧化碳CO:".$data['HeWeather data service 3.0'][0][aqi][city][co]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][no2])$contentStr .= "二氧化氮NO2:".$data['HeWeather data service 3.0'][0][aqi][city][no2]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][so2])$contentStr .= "二氧化硫SO2:".$data['HeWeather data service 3.0'][0][aqi][city][so2]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][o3])$contentStr .= "臭氧O3:".$data['HeWeather data service 3.0'][0][aqi][city][o3]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][pm10])$contentStr .= "PM10:".$data['HeWeather data service 3.0'][0][aqi][city][pm10]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][pm25])$contentStr .= "PM25:".$data['HeWeather data service 3.0'][0][aqi][city][pm25]."\n"; if($data['HeWeather data service 3.0'][0][aqi][city][qlty])$contentStr .= "空气评级:".$data['HeWeather data service 3.0'][0][aqi][city][qlty]."\n"; $contentStr .= "\n"."天气情况:"."\n"; for($x=0;$x<6;$x++){ $contentStr .=$data['HeWeather data service 3.0'][0]['daily_forecast'][$x]['date']."\n"; $contentStr .=$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][cond][txt_d]."转".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][cond][txt_n]."\n"; $contentStr .="湿度:".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][hum]."%"."\n"; $contentStr .="气压:".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][pres]."\n"; $contentStr .="温度: ".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][tmp]['min']."~".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][tmp]['max']."摄氏度"."\n"; $contentStr .="能见度:".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][vis]."KM"."\n"; $contentStr .="风力:".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x][wind][sc].", ".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x]['wind']['dir'].", 风速:".$data['HeWeather data service 3.0'][0]['daily_forecast'][$x]['wind']['spd']."\n"; } $contentStr .= "\n"."生活建议:"."\n"; $contentStr .= "舒适度:".$data['HeWeather data service 3.0'][0][suggestion][comf][brf].",".$data['HeWeather data service 3.0'][0][suggestion][comf][txt]."\n"; $contentStr .= "洗车建议:".$data['HeWeather data service 3.0'][0][suggestion][cw][brf].",".$data['HeWeather data service 3.0'][0][suggestion][cw][txt]."\n"; $contentStr .= "穿着建议:".$data['HeWeather data service 3.0'][0][suggestion][drsg][brf].",".$data['HeWeather data service 3.0'][0][suggestion][drsg][txt]."\n"; $contentStr .= "感冒指数:".$data['HeWeather data service 3.0'][0][suggestion][flu][brf].",".$data['HeWeather data service 3.0'][0][suggestion][flu][txt]."\n"; $contentStr .= "运动指数:".$data['HeWeather data service 3.0'][0][suggestion][sport][brf].",".$data['HeWeather data service 3.0'][0][suggestion][sport][txt]."\n"; $contentStr .= "旅游指数:".$data['HeWeather data service 3.0'][0][suggestion][trav][brf].",".$data['HeWeather data service 3.0'][0][suggestion][trav][txt]."\n"; $contentStr .= "辐射指数:".$data['HeWeather data service 3.0'][0][suggestion][uv][brf].",".$data['HeWeather data service 3.0'][0][suggestion][uv][txt]."\n";
CITYID 可以根据这个网站建立数据库
if(!$str_key)$str_key='上海'; $sql_tq="SELECT city_id,city_name,pro_name FROM tianqi WHERE town_name='".$str_key."'"; $result_tq=mysql_query($sql_tq,$dbconn); $count_tq = mysql_num_rows($result_tq); if($count_tq>0) { $row_tq = mysql_fetch_array($result_tq); $city_id = $row_tq['city_id']; $city_name=$row_tq['city_name']; $pro_name=$row_tq['pro_name']; if($city_name==$pro_name AND $city_name==$str_key){ $area=$str_key; } elseif($city_name==$pro_name AND $city_name!=$str_key){ $area=$city_name." ".$str_key; } else{ $area=$pro_name." ".$city_name." ".$str_key; }
相关文章推荐
- 用命令行cmd 编译小程序
- 微信JS之config:invalid url domain
- 微信企业号开发:微信用户信息和web网页的session的关系
- 支付宝和微信支付--菜鸟到入门
- Scala实战-通过微信聊天窗口实现应答式点餐 0
- 微信内置浏览器隐藏功能左上角功能选项
- wemall商城系统
- 微信无法使用支付宝?
- QQ微信号数据库 微信号采集 可区分性别地区1-100万个
- 微信公众号开发笔记(一)
- JavaScript小程序
- 小程序-----JAVA代码实现文件内容的复制
- Android 控件沿贝塞尔曲线运动(下)———仿微信掉表情包
- 使用css画出微信消息框(主要是三角形)
- 微信支付
- 微信支付
- 微信支付
- 微信扫码支付报错:curl出错,错误码:60
- 微信网页调试小记
- 微信 长按 无法 识别二维码 解决办法