dwr/open-weather 问题修复 & 功能扩展

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

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

dwr/open-weather

Composer 安装命令:

composer require dwr/open-weather

包简介

Simply web widget showing weather in defined location based on Open Weather API

README 文档

README

Latest Stable Version Software License Build Status Coverage Status Scrutinizer Code Quality Total Downloads

DwrOpenWeather

DwrOpenWeather is a simply wrapper for Open Weather API.
In order to start please generate your personal ApiKey first.
You can do it here.

Installation and usage

When you have ApiKey, installation and usage is very easy.

Step 1: Download DwrOpenWeather using composer

Add DwrOpenWeather in your composer.json:

    {
        "require": {
            "dwr/open-weather": "1.0.0"
        }
    }

or download it by running the command:

    $ php composer.phar require dwr/open-weather

Step 2: Use it in your application

GET Weather

    // errors reporting
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

    require __DIR__ . '/vendor/autoload.php';
    
    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;
    
    $apiKey = YOURS-API-KEY; //consider keeping api key in environment variable: getenv('OPEN_WEATHER_API_KEY'); 
    $openWeatherConfig = new Configuration($apiKey);
    
    $openWeather = new OpenWeather('Weather', $openWeatherConfig);
    $weather = $openWeather->getByCityName('London');
    
    var_dump($weather);

You can get weather from OpenWeather API by using:

  • getByCityName('London')
  • getByCityId('2643743')
    List of city ID city.list.json.gz can be downloaded here
  • getByGeographicCoordinates(-0.12574, 51.50853)

GET Forecast

    // errors reporting
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
        
    require __DIR__ . '/vendor/autoload.php';
    
    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;
    
    $apiKey = YOURS-API-KEY; 
   
    //Consider keeping api key in environment variable.
    //$apiKey = getenv('OPEN_WEATHER_API_KEY');
    
    $openWeatherConfig = new Configuration($apiKey);
    
    $openWeather = new OpenWeather('Forecast', $openWeatherConfig);
    $forecast = $openWeather->getByCityName('London');
    
    var_dump($forecast);

You can get forecast from OpenWeather API by using:

  • getByCityName('London')
  • getByCityId('2643743')
    List of city ID city.list.json.gz can be downloaded here
  • getByGeographicCoordinates(-0.12574, 51.50853)

Configuration (Optional)

You may configure library on your own if you like. There are several variables which you can set by yourself:

  • baseUri,
  • version,
  • timeout,
  • httpClient
  • apiKey;
    require __DIR__ . '/../vendor/autoload.php';
    
    use Dwr\OpenWeather\Configuration;
    use Dwr\OpenWeather\OpenWeather;
    
    $apiKey = YOURS-API-KEY;
    
    //Consider keeping api key in environment variable.
    //$apiKey = getenv('OPEN_WEATHER_API_KEY');
        
    $openWeatherConfig = new Configuration($apiKey);
    
    //CONFIGURATION DwrOpenWeather
    $openWeatherConfig->setBaseUri(NEW-BASE-URI);
    $openWeatherConfig->setVersion(NEW-API-VERSION);
    $openWeatherConfig->setTimeout(NEW-TIMEOUT);
    $openWeatherConfig->setHttpClient(NEW-HTTP-CLIENT); //Has to implement GuzzleHttp\ClientInterface
    $openWeatherConfig->setApiKey(NEW-API-URI);
    
    $openWeather = new OpenWeather('Weather', $openWeatherConfig);

Examples

Take a moment and check examples directory in DwrOpenWeather. Maybe you will find there a solution which you like.

weather-basic-small

weather-basic-small

weather-basic-medium

weather-basic-medium

weather-basic-large

weather-basic-large

forecast-chart

forecast-chart

forecast-basic

forecast-basic

License

The MIT License (MIT). Please see License File for more information.

dwr/open-weather 适用场景与选型建议

dwr/open-weather 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 02 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dwr/open-weather 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-14