承接 jetcod/ip-intelligence 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jetcod/ip-intelligence

Composer 安装命令:

composer require jetcod/ip-intelligence

包简介

A PHP package for geolocating IP addresses and obtaining locale and language information from them.

README 文档

README

Actions Status

Latest Stable Version License

Overview

IP-Intelligence is a versatile PHP library designed for comprehensive IP address intelligence analysis. Powered by the robust MaxMind database and seamlessly integrated with the CLDR (Common Locale Data Repository) package, this library empowers you to extract a wealth of information from an IP address. Whether you need to uncover geolocation data, ASN (Autonomous System Number) information, or even detect the language and locale associated with an IP address, IP-Intelligence provides the essential tools to enrich your data analysis and decision-making processes.

Requirements

This library requires:

Once you installed Maxmind Db you will have 3 database files as follows:

  • GeoLite2-Country.mmdb
  • GeoLite2-City.mmdb
  • GeoLite2-ASN.mmdb

Keep the path to each file for further installation.

For comprehensive guidance on the installation procedure and requirements, kindly consult the documentation website.

Installation Guide

Step1: Composer Installation

Start by installing the IP-Intelligence package via Composer. Run the following command in your terminal:

composer require jetcod/ip-intelligence

This will fetch and install the necessary package files.

Step 2: Configuration

IP-Intelligence requires configuration to work effectively. This library offers an artisan command tailored for Laravel projects, streamlining the installation and configuration of necessary databases. To kickstart this process, simply execute the following artisan command:

php artisan IpIntelligence:data-install

Throughout this setup, you will be prompted to specify the paths to the Maxmind databases, and the associated environment variables will be automatically configured.

If your project falls outside the Laravel framework, you should incorporate the cldr-core package by executing:

npm install cldr-core

Subsequently, make sure to define these variables within your .env file:

Usage

IP Lookup

The primary functionality of this library is to perform IP address lookups. You can obtain various details about an IP address using the ip() method. Here's an example of how to use it:

<?php

namespace App\Http\Controllers;

use Jetcod\IpIntelligence\GeoIpLookup;

class TestController
{
    public function __invoke(GeoIpLookup $lookup)
    {
        $address = '206.47.249.128';

        try {
            $ip = $lookup->ip($address);

            // Retrieve Language Information
            $officialLanguages = $ip->language()->officials();
            // Returns an array of official languages spoken in the region, e.g., ['en', 'fr']

            $allLanguages = $ip->language()->all();
            // Returns an array of all languages spoken in the region, e.g., ['ar', 'atj', 'bla', 'bn', ...]

            $locale = $ip->language()->locale;
            // Returns the locale for the region, e.g., 'en_CA'

            // Retrieve City Information
            $cityName = $ip->city()->name;
            // Returns the name of the city, e.g., 'Toronto'

            // Retrieve Country Information
            $countryName = $ip->country()->name;
            // Returns the name of the country, e.g., 'Canada'

            dd(
                "IP Address: $address",
                "Official Languages: " . implode(', ', $officialLanguages),
                "All Languages: " . implode(', ', $allLanguages),
                "Locale: $locale",
                "City Name: $cityName",
                "Country Name: $countryName"
            );

        } catch (\Jetcod\IpIntelligence\Exceptions\InvalidIpAddressException $e) {
            // Handle the case where the provided IP address is invalid.
            echo $e->getMessage();
        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
            // Handle the case where the IP address is not found in the database.
            echo $e->getMessage();
        }
    }
}

This code demonstrates how to initialize the IpLookup class, perform an IP lookup, and retrieve information about the given IP address, including language, city, and country details. Be sure to handle exceptions as shown in the code to gracefully manage errors that may arise during the lookup process.

Language

The Language class is a component of the Jetcod IP Intelligence library and is designed to provide information about languages spoken in a specific country based on CLDR (Common Locale Data Repository) data. This class allows you to retrieve details about the languages, official languages, and the locale associated with a given country code.

Here is the usage example:

use Jetcod\IpIntelligence\Models\Language;
use Jetcod\IpIntelligence\Exceptions\LanguageNotFoundException;
use Symfony\Component\Dotenv\Dotenv;

// Create a Language instance for the United States ('US')
$language = new Language('US');

try {
    // Retrieve all languages spoken in the United States
    $allLanguages = $language->all();

    // Retrieve official and de facto official languages
    $officialLanguages = $language->officials();

    // Retrieve the locale for the first official language
    $locale = $language->locale();

    // Print the retrieved data
    print_r($allLanguages);
    print_r($officialLanguages);
    
    echo "Locale: $locale";
} catch (LanguageNotFoundException $e) {
    echo $e->getMessage();
}

This usage example demonstrates how to create a Language instance, switch the country, and retrieve language information for that country. It also handles exceptions that may occur during the process.

Contributing

If you would like to contribute to this library, please fork the repository and submit a pull request. We welcome bug fixes, feature requests, and other contributions.

License

This library is released under the MIT License. Please see the LICENSE file for more information.

jetcod/ip-intelligence 适用场景与选型建议

jetcod/ip-intelligence 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 jetcod/ip-intelligence 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-02