sunsgne/weather

0.1.2 2022-05-17 04:08 UTC

This package is auto-updated.

Last update: 2024-10-06 09:40:42 UTC


README

sunsgne

高德地图 weather

🌈 基于IP获取高德开放平台的天气信息插件

安装

composer require sunsgne/weather

使用

配置

高德开放平台 注册账号,然后创建应用,获取应用的 API Key。

地理位置

$clientIp = $request->getRealIp();
sunsgne\Weather::getClientCityByIp($clientIp);

响应

array(7) {     
  ["status"]=> 
  string(1) "1"
  ["info"]=>   
  string(2) "OK"
  ["infocode"]=>
  string(5) "10000"
  ["province"]=>
  string(9) "重庆市"
  ["city"]=>
  string(9) "重庆市"
  ["adcode"]=>
  string(6) "500000"
  ["rectangle"]=>
  string(46) "106.2832832,29.36962828;106.8138242,29.7401968"
}

实时天气

$clientIp = $request->getRealIp();
sunsgne\Weather::liveWeather($clientIp);

预报天气

$clientIp = $request->getRealIp();
sunsgne\Weather::forecastsWeather($clientIp);