金沙官网线上:php使用百度天气接口示例_php实例

注意地区要转码的百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key

返回的数据为:

复制代码 代码如下:{ error: 0, status: "success", date: "2014-04-18", results: [ { currentCity: "嘉兴", weather_data: [ { 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: "23℃" }, { date: "明天", dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png", nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png", weather: "雷阵雨转中雨", wind: "微风", temperature: "29~22℃" }, { date: "后天", dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png", nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png", weather: "阴转多云", wind: "微风", temperature: "31~23℃" }, { 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: "31~24℃" } ] }, { currentCity: "合肥市", weather_data: [ { 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: "东风3-4级", temperature: "27℃" }, { 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: "东北风3-4级", temperature: "35~27℃" }, { 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: "35~27℃" }, { 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: "34~27℃" } ] } ]}

网上关于AFNetworking的代码,基本上都是使用ObjectC语言。以下是swift2.0版本的获取天气信息的小程序,供初学者参考:

$city="嘉兴";$content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");print_r);

http://www.cnblogs.com/GarveyCalvin/p/4123642.html

复制代码 代码如下:

{"resultcode":"200","reason":"successed!","result":{"sk":{"temp":"13","wind_direction":"北风","wind_strength":"3级","humidity":"48%","time":"11:04"},"today":{"temperature":"13℃~17℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期五","city":"深圳","date_y":"2016年12月30日","dressing_index":"较冷","dressing_advice":"建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。","uv_index":"弱","comfort_index":"","wash_index":"较适宜","travel_index":"较适宜","exercise_index":"较适宜","drying_index":""},"future":{"day_20161230":{"temperature":"13℃~17℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期五","date":"20161230"},"day_20161231":{"temperature":"16℃~22℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期六","date":"20161231"},"day_20170101":{"temperature":"17℃~21℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期日","date":"20170101"},"day_20170102":{"temperature":"19℃~24℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期一","date":"20170102"},"day_20170103":{"temperature":"19℃~26℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期二","date":"20170103"},"day_20170104":{"temperature":"17℃~21℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期三","date":"20170104"},"day_20170105":{"temperature":"17℃~21℃","weather":"多云","weather_id":{"fa":"01","fb":"01"},"wind":"微风","week":"星期四","date":"20170105"}}},"error_code":0}

里面的示例,使用的是旧版的AFNetworking。如果你使用的是AFNetworking3,请忽略里面的示例,直接使用我上面的例子。

本文由金沙官网线上发布于编程,转载请注明出处:金沙官网线上:php使用百度天气接口示例_php实例

您可能还会对下面的文章感兴趣: