yiicod/yii2-geo

Yii GEO 辅助/查找器

安装数: 1,175

依赖项: 0

建议者: 0

安全: 0

星标: 7

关注者: 2

分支: 0

公开问题: 0

类型:yii2-extension

1.1.0 2018-07-24 15:20 UTC

This package is auto-updated.

Last update: 2024-08-27 00:26:19 UTC


README

Latest Stable Version Total Downloads Scrutinizer Code QualityCode Climate

此扩展可以帮助您查找用户的国家和地区代码。它使用两个在线和一个离线系统来获取有关用户的信息。您无需担心将使用哪个系统,因为所有这些都将由一个组件 GeoFinder 来完成。

安装

安装此扩展的首选方式是通过 composer

您可以运行

php composer.phar require --prefer-dist yiicod/yii2-geo "*"

或者将以下内容添加到您的 composer.json 文件的 require 部分。

"yiicod/yii2-geo": "*"

前端配置

'container' => [
    'singletons' => [
        \yiicod\geo\storages\StorageInterface::class => [
            'class' => \yiicod\geo\storages\CacheStorage::class,
        ],
    ],
],
'components' => [
    'geoFinder' => [
        'class' => yiicod\geo\components\GeoFinder::class,
        'gettersList' => [
            [
                'class' => \yiicod\geo\adapters\geoIp2\GeoIp2CityAdapter::class,
                'databaseConfig' => [
                    'class' => \yiicod\geo\adapters\geoIp2\GeoIp2Database::class,
                    'databaseAlias' => '@frontend/runtime',
                ],
            ],
            [
                'class' => \yiicod\geo\adapters\ipstack\IpstackAdapter::class,
                'apiKey' => 'API-key'
            ],
            [
                'class' => \yiicod\geo\adapters\geoPlugin\GeoPluginAdapter::class,
            ],
        ],
    ],
],

用法

\yiicod\geo\GeoGetter::getCountryName($ip)
\yiicod\geo\GeoGetter::getCountryCode($ip)
\yiicod\geo\GeoGetter::getRegionName($ip),
\yiicod\geo\GeoGetter::getRegionCode($ip),
\yiicod\geo\GeoGetter::getCity($ip),
\yiicod\geo\GeoGetter::getLatitude($ip),
\yiicod\geo\GeoGetter::getLongitude($ip),