定制 arraypress/ipinfo 二次开发

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

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

arraypress/ipinfo

Composer 安装命令:

composer require arraypress/ipinfo

包简介

A PHP library for integrating with the IPInfo.io API in WordPress, providing geolocation, ASN data, privacy detection, and hosting information. Features plan-aware responses and WordPress transient caching.

README 文档

README

A WordPress library for IPInfo.io API integration with smart caching and plan-aware responses.

Installation

Install via Composer:

composer require arraypress/ipinfo

Requirements

  • PHP 7.4 or later
  • WordPress 6.7.1 or later
  • IPInfo.io API key

Basic Usage

use ArrayPress\IPInfo\Client;

// Initialize with your API key/token
$client = new Client( 'your-api-key-here' );

// Single IP lookup
$info = $client->get_ip_info( '8.8.8.8' );

// Get specific field only
$country = $client->get_field( '8.8.8.8', 'country' );  // Returns: "US"
$city = $client->get_field( '8.8.8.8', 'city' );       // Returns: "Mountain View"

// Get multiple specific fields
$fields = $client->get_fields( '8.8.8.8', ['country', 'city', 'org'] );
// Returns: [ 'country' => 'US', 'city' => 'Mountain View', 'org' => 'Google LLC' ]

// Batch processing multiple IPs
$ips = [ '8.8.8.8', '1.1.1.1' ];
$batch_results = $client->get_batch_info( $ips );
foreach ( $batch_results as $ip => $info ) {
    echo "$ip is located in " . $info->get_city();
}

Available Methods

Client Methods

// Initialize client with options
$client = new Client(
    'your-token-here',    // API token
    true,                 // Enable caching (optional, default: true)
    3600                  // Cache duration in seconds (optional, default: 3600)
);

// Get complete information for an IP
$info = $client->get_ip_info( '8.8.8.8' );

// Get specific field
$field = $client->get_field( '8.8.8.8', 'country' );

// Get multiple fields
$fields = $client->get_fields( '8.8.8.8', [ 'country', 'city' ] );

// Process multiple IPs (max 1000)
$results = $client->get_batch_info(
    [ '8.8.8.8', '1.1.1.1' ], // IP addresses
    1000,                     // Batch size (optional, default: 1000)
    false,                    // Filter response (optional, default: false)
    5                         // Timeout in seconds (optional, default: 5)
);

// Cache management
$client->clear_cache( '8.8.8.8' );  // Clear specific IP
$client->clear_cache();             // Clear all cached data

Response Methods

Basic Information

// Get IP address
$ip = $info->get_ip();
// Returns: "8.8.8.8"

// Get hostname (if available)
$hostname = $info->get_hostname();
// Returns: "dns.google"

// Check if IP is anycast
$is_anycast = $info->is_anycast();
// Returns: true/false

// Get city name
$city = $info->get_city();
// Returns: "Mountain View"

// Get region/state
$region = $info->get_region();
// Returns: "California"

// Get country information
$country_code = $info->get_country();      // Returns: "US"
$country_name = $info->get_country_name(); // Returns: "United States"

// Get coordinates
$coords = $info->get_coordinates();
// Returns: ['latitude' => 37.4056, 'longitude' => -122.0775]

// Individual coordinate access
$lat = $info->get_latitude();   // Returns: 37.4056
$long = $info->get_longitude(); // Returns: -122.0775

// Get postal code
$postal = $info->get_postal();
// Returns: "94043"

// Get timezone
$timezone = $info->get_timezone();
// Returns: "America/Los_Angeles"

// Get plan level
$plan = $info->get_plan();
// Returns: "Free", "Basic", "Business", or "Premium"

// Check feature availability
$has_asn = $info->has_feature( 'asn' );        // Basic plan and above
$has_privacy = $info->has_feature( 'privacy' ); // Business plan and above
$has_domains = $info->has_feature( 'domains' ); // Premium plan only

// Extended country information
$flag = $info->get_country_flag();
if ( $flag ) {
    $emoji = $flag->get_emoji();     // Returns: "🇺🇸"
    $unicode = $flag->get_unicode();  // Returns: "U+1F1FA U+1F1F8"
}

$currency = $info->get_country_currency();
if ( $currency ) {
    $code = $currency->get_code();    // Returns: "USD"
    $symbol = $currency->get_symbol(); // Returns: "$"
}

$continent = $info->get_continent();
if ( $continent ) {
    $name = $continent->get_name();   // Returns: "North America"
    $code = $continent->get_code();   // Returns: "NA"
}

$is_eu = $info->is_eu(); // Returns: true/false

ASN Information (Basic Plan and Above)

if ( $asn = $info->get_asn() ) {
    $asn_number = $asn->get_asn();      // Returns: "AS15169"
    $asn_name = $asn->get_name();       // Returns: "Google LLC"
    $asn_domain = $asn->get_domain();   // Returns: "google.com"
    $asn_route = $asn->get_route();     // Returns: "8.8.8.0/24"
    $asn_type = $asn->get_type();       // Returns: "hosting"
}

Privacy Detection (Business/Premium Plans)

if ( $privacy = $info->get_privacy() ) {
    $is_vpn = $privacy->is_vpn();         // Returns: false
    $is_proxy = $privacy->is_proxy();      // Returns: false
    $is_tor = $privacy->is_tor();          // Returns: false
    $is_relay = $privacy->is_relay();      // Returns: false
    $is_hosting = $privacy->is_hosting();  // Returns: true
    $service = $privacy->get_service();    // Returns: null or service name
}

Company Information (Business/Premium Plans)

if ( $company = $info->get_company() ) {
    $name = $company->get_name();      // Returns: "Google LLC"
    $domain = $company->get_domain();  // Returns: "google.com"
    $type = $company->get_type();      // Returns: "hosting"
}

Abuse Contact Information (Business/Premium Plans)

if ( $abuse = $info->get_abuse() ) {
    $email = $abuse->get_email();     // Returns: "network-abuse@google.com"
    $name = $abuse->get_name();       // Returns: "Google LLC"
    $phone = $abuse->get_phone();     // Returns: "+1-650-253-0000"
    $address = $abuse->get_address(); // Returns: "1600 Amphitheatre Parkway..."
    $country = $abuse->get_country(); // Returns: "US"
    $network = $abuse->get_network(); // Returns: "8.8.8.0/24"
}

Domains Information (Premium Plan Only)

if ( $domains = $info->get_domains() ) {
    $total = $domains->get_total();     // Returns: total number of domains
    $page = $domains->get_page();       // Returns: current page number
    $list = $domains->get_domains();    // Returns: array of domain names
}

Response Format Examples

Raw Data Access

// Get full raw data array
$raw_data = $info->get_all();

// Magic property access
$raw_data = $info->all;

Basic Plan Response

[
    'ip' => '8.8.8.8',
    'city' => 'Mountain View',
    'region' => 'California',
    'country' => 'US',
    'loc' => '37.4056,-122.0775',
    'org' => 'AS15169 Google LLC',
    'postal' => '94043',
    'timezone' => 'America/Los_Angeles'
]

Business Plan Additional Data

[
    // ... basic plan data ...
    'asn' => [
        'asn' => 'AS15169',
        'name' => 'Google LLC',
        'domain' => 'google.com',
        'route' => '8.8.8.0/24',
        'type' => 'hosting'
    ],
    'company' => [
        'name' => 'Google LLC',
        'domain' => 'google.com',
        'type' => 'hosting'
    ],
    'privacy' => [
        'vpn' => false,
        'proxy' => false,
        'tor' => false,
        'relay' => false,
        'hosting' => true,
        'service' => null
    ],
    'abuse' => [
        'address' => 'US, CA, Mountain View, 1600 Amphitheatre Parkway, 94043',
        'country' => 'US',
        'email' => 'network-abuse@google.com',
        'name' => 'Network Abuse',
        'network' => '8.8.8.0/24',
        'phone' => '+1-650-253-0000'
    ]
]

Premium Plan Additional Data

[
    // ... business plan data ...
    'domains' => [
        'total' => 2535948,
        'domains' => [
            'pub.dev',
            'virustotal.com',
            'blooket.com',
            'go.dev',
            'rytr.me'
        ]
    ]
]

Batch Processing Response

$batch_results = $client->get_batch_info( [ '8.8.8.8', '1.1.1.1' ] );
// Returns:
[
    '8.8.8.8' => Response Object,
    '1.1.1.1' => Response Object
]

Error Handling

The library uses WordPress's WP_Error for error handling:

$info = $client->get_ip_info( 'invalid-ip' );

if ( is_wp_error( $info ) ) {
    echo $info->get_error_message();
    // Output: "Invalid IP address: invalid-ip"
}

Common error cases:

  • Invalid IP address
  • Invalid API key/token
  • API request failure
  • Rate limit exceeded
  • Invalid response format

Contributions

Contributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug fixes or new features. Share feedback and suggestions for improvements.

License: GPLv2 or later

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

arraypress/ipinfo 适用场景与选型建议

arraypress/ipinfo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 12 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 arraypress/ipinfo 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2024-12-06