serverking/weather
最新稳定版本:v1.0.1
Composer 安装命令:
composer require serverking/weather
包简介
a weather sdk
README 文档
README
一个laravel weather扩展包
使用帮助
1、首先安装serverking/weather
composer require serverking/weather -vvv
2、发布配置文件,运行如下命令后会生成/config/weathers.php配置文件
php artisan vendor:publish --provider="Serverking\Weather\ServiceProvider" --tag="weathers"
3、编辑.env文件,添加如下配置
WEATHER_API_KEY="高德开放接口中天气预报的key密钥"
4、调用方式
//注入方式:
public function index(Request $request, Weather $weather, $city){
return $weather->getWeather($city,'base');
}
//容器方式:
public function index(Request $request, Weather $weather, $city){
return app('weather')->getWeather($city,'base');
}
5、添加路由
Route::get('/weather/{city}', [\App\Http\Controllers\WeatherController::class, 'index']);
6、方问接口进行读取接口
//访问接口:
http://localhost/weather/上海
http://localhost/weather/上海区号
//返回的数据:
{"status":"1","count":"1","info":"OK","infocode":"10000","lives":[{"province":"上海","city":"上海市","adcode":"310000","weather":"多云","temperature":"35","winddirection":"北","windpower":"≤3","humidity":"51","reporttime":"2025-08-08 16:01:17","temperature_float":"35.0","humidity_float":"51.0"}]}
License
MIT
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-08