solgenpower/laravel-openweather 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

solgenpower/laravel-openweather

Composer 安装命令:

composer require solgenpower/laravel-openweather

包简介

A Laravel SDK for OpenWeather API

README 文档

README

A Laravel SDK for OpenWeather API

Installation

Install the package via composer:

composer require solgenpower/laravel-openweather

If you're interested in modifying the config file, then publish it using the following command:

php artisan vendor:publish --provider="SolgenPower\LaravelOpenWeather\OpenWeatherServiceProvider"

This is the contents of the published config file:

return [

    /**
     * API Key for Open Weather
     */
    'api-key' => env('OPENWEATHER_API_KEY', ''),

    /**
     * Endpoint for the Current Weather
     */
    'current-endpoint' => env('OPENWEATHER_CURRENT_ENDPOINT', 'https://api.openweathermap.org/data/2.5/weather/'),

    /**
     * Endpoint for the Weather Condition icons
     * Reference: https://openweathermap.org/weather-conditions
     */
    'icon-endpoint' => env('OPENWEATHER_ICON_ENDPOINT', 'https://openweathermap.org/img/wn/'),

    /**
     * Map icon code to actual icon filenames
     */
    'icon-map' => [
        /**
         * Day Icons
         */
        '01d' => '01d.png',
        '02d' => '02d.png',
        '03d' => '03d.png',
        '04d' => '04d.png',
        '09d' => '09d.png',
        '10d' => '10d.png',
        '11d' => '11d.png',
        '13d' => '13d.png',
        '50d' => '50d.png',

        /**
         * Night Icons
         */
        '01n' => '01n.png',
        '02n' => '02n.png',
        '03n' => '03n.png',
        '04n' => '04n.png',
        '09n' => '09n.png',
        '10n' => '10n.png',
        '11n' => '11n.png',
        '13n' => '13n.png',
        '50n' => '50n.png',
    ],

    /**
     * Cache duration default in seconds, 60 * 10 is 10 minutes
     */
    'cache-duration' => 60 * 10,

    /**
     * standard => Kelvin
     * imperial => Fahrenheit
     * metric => Celsius
     */
    'temperature-unit' => env('OPENWEATHER_TEMPERATURE_UNIT', 'imperial'),

];

Usage

You can get weather information by providing coordinates

$whiteHouseWeather = OpenWeather::coordinates("38.897957", "-77.036560");
echo $whiteHouseWeather->humidity; //64

or by zip code

$californiaWeather = OpenWeather::zip('90210', 'US');
echo $californiaWeather->windDirection; //N

or by city name

$pheonixWeather = OpenWeather::city('Tucson', 'AZ', 'US');
echo $pheonixWeather->feelsLike; //281.55

All these methods will return a Weather DTO that looks like this:

class Weather
{
    public function __construct(
        public readonly float $latitude,

        public readonly float $longitude,

        public readonly ?string $countryCode,
        
        public readonly ?string $city,

        public readonly string $condition,

        public readonly string $description,

        public readonly string $icon,

        public readonly float $temperature,

        public readonly ?float $feelsLike,

        public readonly ?int $pressure,

        public readonly ?int $humidity,

        public readonly ?float $windSpeed,

        public readonly ?int $windAngle,

        public readonly ?string $windDirection,

        public readonly ?int $cloudiness,

        public readonly ?int $visibility,

        /**
         * Seconds difference from UTC
         * To use with Carbon's timezone method, divide by 3600
         */
        public readonly int $timezone,

        public readonly Carbon $sunrise,

        public readonly Carbon $sunset,

        public readonly Carbon $calculatedAt
    ) {
    }
}

Testing

composer review

solgenpower/laravel-openweather 适用场景与选型建议

solgenpower/laravel-openweather 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.79k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「api」 「laravel」 「openweather」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 solgenpower/laravel-openweather 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 solgenpower/laravel-openweather 我们能提供哪些服务?
定制开发 / 二次开发

基于 solgenpower/laravel-openweather 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-09