定制 rodzadra/geolocation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rodzadra/geolocation

Composer 安装命令:

composer require rodzadra/geolocation

包简介

Simple Yii2 component to find geo client information.

README 文档

README

Simple Yii2 component to find geo client information.

Yii2

Installation

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist rodzadra/geolocation "*"

or add

"rodzadra/geolocation": "*"

to the require section of your composer.json file.

Configuration

  1. In your config/main.php
'components'=>[
    'geolocation' => [ 
        'class' => 'rodzadra\geolocation\Geolocation',
        'config' => [
            'provider' => '[PLUGIN_NAME]',
            'return_formats' =>  '[SUPORTED_PLUGIN_FORMATS]',
            'api_key' => '[YOUR_API_KEY],
        ],
    ],
],

Config params

provider - The name of plugin to use (see examples on @vendor/rodzadra/geolocation/plugins/);

return_formats - The return formats supported by the plugin

api_key - If necessary, you can pass your api key here.

Plugins

Plugins are simple PHP files, that returns an array with three vars:

  • plugin_url : URL of webservice, with three special tags:

a) {{accepted_formats}}

b) {{ip}}

c) {{api_key}}

These tags will be replaced by their respective values.

  • accepted_formats : An array with the return acceptable formats (example ['csv', 'php', 'json', 'xml'])

  • default_accepted_format : String with the default return format. (example "php")

Plugin file example

<?php

$plugin = [
            'plugin_url'                => 'http://www.geoplugin.net/{{accepted_formats}}.gp?ip={{ip}}',
            'accepted_formats'          => ['json', 'php', 'xml'],
            'default_accepted_format'   => 'php',
    ];

How to use

In your view:

<?php
  print_r(yii::$app->geolocation->getInfo());
?>

or, to find the geolocation infos from Google server, on your view.

<?php
  print_r(yii::$app->geolocation->getInfo('173.194.118.22'));
?>

To change the plugin

<?php
    yii::$app->geolocation->getPlugin('ippycox','XML');
  print_r(yii::$app->geolocation->getInfo('173.194.118.22'));
?>

What you get?

Using the geoplugin provider:

Array
(
    [geoplugin_request] => 173.194.118.22
    [geoplugin_status] => 200
    [geoplugin_credit] => Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.
    [geoplugin_city] => Mountain View
    [geoplugin_region] => CA
    [geoplugin_areaCode] => 650
    [geoplugin_dmaCode] => 807
    [geoplugin_countryCode] => US
    [geoplugin_countryName] => United States
    [geoplugin_continentCode] => NA
    [geoplugin_latitude] => 37.419201
    [geoplugin_longitude] => -122.057404
    [geoplugin_regionCode] => CA
    [geoplugin_regionName] => California
    [geoplugin_currencyCode] => USD
    [geoplugin_currencySymbol] => $
    [geoplugin_currencySymbol_UTF8] => $
    [geoplugin_currencyConverter] => 1
)

For more information, please visit http://www.geoplugin.com/

Using the freegeoip provider:

{
 "ip":"173.194.118.22",
 "country_code":"US",
 "country_name":"United States",
 "region_code":"CA",
 "region_name":"California",
 "city":"Mountain View",
 "zip_code":"94043",
 "time_zone":"America/Los_Angeles",
 "latitude":37.419,
 "longitude":-122.058,
 "metro_code":807
}

For more information, please visit https://freegeoip.net/

For another plugins infos, please use the sources. :)

统计信息

  • 总下载量: 16.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: GPL
  • 更新时间: 2015-08-18