当前位置:Gxlcms > PHP教程 > 百度天气接口非常简单

百度天气接口非常简单

时间:2021-07-01 10:21:17 帮助过:11人阅读

注意地区要转码的
百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key
  1. $city="嘉兴";
  2. $content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");
  3. print_r(json_decode($content));
  1. {
  2. error: 0,
  3. status: "success",
  4. date: "2014-04-18",
  5. results: [
  6. {
  7. currentCity: "嘉兴",
  8. weather_data: [
  9. {
  10. date: "今天(周三)",
  11. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  12. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  13. weather: "多云",
  14. wind: "微风",
  15. temperature: "23℃"
  16. },
  17. {
  18. date: "明天(周四)",
  19. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
  20. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
  21. weather: "雷阵雨转中雨",
  22. wind: "微风",
  23. temperature: "29~22℃"
  24. },
  25. {
  26. date: "后天(周五)",
  27. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
  28. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  29. weather: "阴转多云",
  30. wind: "微风",
  31. temperature: "31~23℃"
  32. },
  33. {
  34. date: "大后天(周六)",
  35. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  36. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  37. weather: "多云",
  38. wind: "微风",
  39. temperature: "31~24℃"
  40. }
  41. ]
  42. },
  43. {
  44. currentCity: "合肥市",
  45. weather_data: [
  46. {
  47. date: "今天(周三)",
  48. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  49. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  50. weather: "多云",
  51. wind: "东风3-4级",
  52. temperature: "27℃"
  53. },
  54. {
  55. date: "明天(周四)",
  56. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  57. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  58. weather: "多云",
  59. wind: "东北风3-4级",
  60. temperature: "35~27℃"
  61. },
  62. {
  63. date: "后天(周五)",
  64. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  65. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  66. weather: "多云",
  67. wind: "南风",
  68. temperature: "35~27℃"
  69. },
  70. {
  71. date: "大后天(周六)",
  72. dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
  73. nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
  74. weather: "多云",
  75. wind: "东风",
  76. temperature: "34~27℃"
  77. }
  78. ]
  79. }
  80. ]
  81. }

人气教程排行