dashcode/weather

AccuWeather API 数据

1.1.0 2023-12-01 14:12 UTC

This package is auto-updated.

Last update: 2024-09-30 01:30:35 UTC


README

这是一个PHP客户端,用于连接到Accuweather API,允许您轻松地与API集成

安装

composer require dashcode/weather

设置环境变量

您可以通过 .env 文件设置环境变量,例如密钥和语言设置

ACCU_WEATHER_KEY=your key
ACCU_WEATHER_LOCALE=en-us ( default ) 

或者您也可以直接将密钥和语言设置传递给Weather类

new Weather("your accuweather key", "language");

如何使用API

通过 .env 文件设置或直接注入到类中设置完 .env 变量后

  1. 创建一个 DashCode\Weather 的天气类对象
$accuWeatherApp = new Weather();
  1. 选择Api类
1. Alert API 
$response = $accuWeatherApp->Alerts();

2. Current Condition API 
$response = $accuWeatherApp->CurrentConditions();

3. Forecast API 
$response = $accuWeatherApp->Forecast();

4. Imagery API 
$response = $accuWeatherApp->Imagery();

5. Indices API 
$response = $accuWeatherApp->Indices();

6. Locations API 
$response = $accuWeatherApp->Locations();

7. MinuteCast API 
$response = $accuWeatherApp->MinuteCast();

8. Translation API 
$response = $accuWeatherApp->Translations();

9. Tropical API 
$response = $accuWeatherApp->Tropical();

10. Weather Alart API 
$response = $accuWeatherApp->WeatherAlarms();

  1. 选择API端点,并将所需参数添加到方法中,对于 Alert API,我们可以这样做
$accuWeatherApp = new Weather();
$alertApis = $accuWeatherApp->Alerts();

$apiResponse = $alertApis->location("location key", true );

请参阅Accuweather或包方法的文档以获取所需参数

技术栈

服务器: PHP

API参考

以下列出了所有API,按模块和子模块划分,并列出了接受的必填和可选参数