承接 thank-song/weather 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

thank-song/weather

最新稳定版本:V1.0.0

Composer 安装命令:

composer require thank-song/weather

包简介

Laravel package for OpenWeather API.

README 文档

README

这是一个用于获取天气数据的 Laravel 扩展包,支持通过城市名称、经纬度等方式调用 OpenWeather 接口。

安装

composer require thank-song/weather

配置发布

可选步骤,发布配置文件以便修改 API Key:

php artisan vendor:publish --tag=config

发布后会在 config/openweather.php 中看到配置项。 需要配置 api_key 项。 参见:OpenWeather API

使用方式

方式一:使用 Facade

use Weather;
//通过城市名称获取天气数据
$response = Weather::getByCity('Hangzhou');

//通过经纬度获取天气数据
//$response = Weather::getByCoords(30.2711, 120.1555);

//通过城市ID获取天气数据
//$response = Weather::getByCityId(1831806);

//通过邮编获取天气数据
//$response = Weather::getByZip(310000);

// $response 为一个Response对象,可用方法如下:

echo $response->getTemp();
echo $response->getMinTemp();

var_dump($response->getWeather());
var_dump($response->getMain());
//...

方式二:使用容器解析

$weather = app('weather');
$response = $weather::getByCity('Hangzhou');

可用字段

  • $response->getTemp():当前温度
  • $response->getMinTemp():最低温度
  • $response->getMaxTemp():最高温度
  • $response->getWeather()[0]['description']:天气描述

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-04