fuhrmann/larageo-plugin

一个使用 geoPlugin 网络服务从 IP 地址获取信息的 Laravel 包。

dev-master 2015-11-09 10:42 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:06:32 UTC


README

一个使用 geoPlugin 网络服务从 IP 地址获取信息的 Laravel 包。它将 IP 信息存储在缓存中,并将在一周后过期。

安装

通过 Composer 安装此包。在你的 composer.json 文件中添加:

    "fuhrmann/larageo-plugin": "dev-master"

然后,运行 Composer 更新命令

$ composer update

在 app/config/app.php 文件中添加服务提供者到 providers 数组中。

    'providers' => array(
        // ...
        'Fuhrmann\LarageoPlugin\ServiceProvider',
    ),

在同一文件 config/app.php 中添加别名

    'aliases' => array(
        //...
        'LarageoPlugin'   => 'Fuhrmann\LarageoPlugin\Facade',
    ),

使用方法

你可以指定一个 IP

    $info = LarageoPlugin::getInfo('177.34.13.248'); // get info from a IP
    var_dump($info);

或者无参数使用它

    $info = LarageoPlugin::getInfo(); // get info from the IP of the user acessing the page
    var_dump($info);

这是输出结果

    object(stdClass)[155]
      public 'geoplugin_request' => string '177.34.13.248' (length=13)
      public 'geoplugin_status' => int 200
      public 'geoplugin_credit' => string 'Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\'http://www.maxmind.com\'>http://www.maxmind.com</a>.' (length=145)
      public 'geoplugin_city' => string 'Campo Grande' (length=12)
      public 'geoplugin_region' => string 'Mato Grosso do Sul' (length=18)
      public 'geoplugin_areaCode' => string '0' (length=1)
      public 'geoplugin_dmaCode' => string '0' (length=1)
      public 'geoplugin_countryCode' => string 'BR' (length=2)
      public 'geoplugin_countryName' => string 'Brazil' (length=6)
      public 'geoplugin_continentCode' => string 'SA' (length=2)
      public 'geoplugin_latitude' => string '-20.450001' (length=10)
      public 'geoplugin_longitude' => string '-54.616699' (length=10)
      public 'geoplugin_regionCode' => string '11' (length=2)
      public 'geoplugin_regionName' => string 'Mato Grosso do Sul' (length=18)
      public 'geoplugin_currencyCode' => string 'BRL' (length=3)
      public 'geoplugin_currencySymbol' => string '&#82;&#36;' (length=10)
      public 'geoplugin_currencySymbol_UTF8' => string 'R$' (length=2)
      public 'geoplugin_currencyConverter' => float 2.383

另一个有用的示例:你还可以在一次调用中只返回一个字段,例如 city

    $userCity = LarageoPlugin::getInfo()->geoplugin_city; // get the city from the user IP
    var_dump($userCity);

输出

    string 'Campo Grande' (length=12)

更多信息

如果你想了解更多关于 geoPlugin 网络服务的信息,点击这里