使用 Foxlis Geo API 通过 IP 获取用户位置:城市、国家、行政区划、大陆等

v1.0.5 2021-03-19 03:05 UTC

This package is auto-updated.

Last update: 2024-09-19 11:05:40 UTC


README

此插件使用 Foxlis Geo API.

安装

使用 composer 安装 foxliscom/geo

用法

use Foxliscom\Geo\FoxlisGeo;

// Get City
echo FoxlisGeo::location()->getCity();

// Get Country
echo FoxlisGeo::location()->getCountry();

// Get Continent
echo FoxlisGeo::location()->getContinent();

// Get Subdivisions List
$subdivisions = FoxlisGeo::location()->getSubdivisions();

// Get Location Data
$locationData = FoxlisGeo::location()->getLocation();

// Get Accuracy Radius
echo $locationData->getAccuracyRadius();

// Get Latitude
echo $locationData->getLatitude();

// Get Longitude
echo $locationData->getLongitude();

// Get Time Zone
echo $locationData->getTimeZone();

// Get Account Info
FoxlisGeo::account()->getData();

多语言示例

// Russian
echo FoxlisGeo::location()->getCity()->ru;

// Spanish
echo FoxlisGeo::location()->getCity()->es;

// English
echo FoxlisGeo::location()->getCity()->en;

// German
echo FoxlisGeo::location()->getCity()->de;

// French
echo FoxlisGeo::location()->getCity()->fr;

// Japanese
echo FoxlisGeo::location()->getCity()->ja;

// Portuguese
echo FoxlisGeo::location()->getCity()->ptBR;

// Chinese
echo FoxlisGeo::location()->getCity()->zhCN;

配置

如果您需要配置此插件,则声明一个全局函数 getFoxlisGeoConfig,其参数类似于在通用配置 src/Config/common.php 中。

function getFoxlisGeoConfig()
{
    return [
        // Your params here
    ];
}
  • foxlis_geo_field_language - 默认语言 default en
    • 英语 en
    • 中文 zh-CN
    • 法语 fr
    • 俄语 ru
    • 德语 de
    • 西班牙语 es
    • 日语 ja
    • 葡萄牙语 pt-BR
  • foxlis_geo_field_session - 保存结果到用户会话 default true
  • foxlis_geo_field_bot_filter - 不检测机器人的地理位置 default true
  • foxlis_geo_field_protocol - 协议 "http" 或 "https" default "http"
  • foxlis_geo_field_development_fake_ip_enable - 开发中使用假 IP default false
  • foxlis_geo_field_development_fake_ip - 假 IP 值 default "23.55.115.223"
  • foxlis_geo_field_account - 获取账户信息的 账户密钥
  • foxlis_geo_bots_list - 机器人列表(用于匹配 $_SERVER['HTTP_USER_AGENT'])。