weijiajia/ip-address
Composer 安装命令:
composer require weijiajia/ip-address
包简介
IP address information query system, integrating multiple IP geographic location services
关键字:
README 文档
README
Ip Address 是一个 IP 地址信息查询系统,集成了多个 IP 地理位置服务
支持平台
特性
- 支持多个 IP 地理位置服务提供商 (目前支持 ip138 和 pconline)
- 标准化的响应格式
- 灵活的日志记录功能
- 错误处理
要求
- PHP 8.2+
- Composer
安装
通过 Composer 安装:
composer require weijiajia/ip-address
首先,发布配置文件:
php artisan vendor:publish --provider="Weijiajia\IpAddress\IpAddressServiceProvider"
这将在 config/http-proxy-manager.php 创建配置文件。
使用方法
使用 pconline
use Weijiajia\IpConnector; use Weijiajia\Requests\PconLineRequest; $connector = new IpConnector(); // 可选: 设置日志 $logger = new YourLoggerImplementation(); // 替换为您的实际日志实现 $connector->withLogger($logger); //可选:设置超时 $connector->config()->add('timeout',30); $request = new PconLineRequest('your ip address'); $response = $connector->send($request); $ipInfo = $response->dto(); echo $ipInfo->getCity(); // 输出城市信息 echo $ipInfo->getAddr(); // 输出详细地址
使用 Ip138Request
use Weijiajia\IpConnector; use Weijiajia\Requests\Ip138Request; $connector = new IpConnector(); $request = new Ip138Request($token, 'your ip address'); $response = $connector->send($request); $ipInfo = $response->dto(); echo $ipInfo->getCity(); // 输出城市信息 echo $ipInfo->getAddr(); // 输出详细地址
错误处理
use Weijiajia\IpConnector; use Weijiajia\Requests\PconLineRequest; use Weijiajia\Exceptions\IpLookupException; $connector = new IpConnector(); try { $request = new PconLineRequest('invalid_ip'); $response = $connector->send($request); $ipInfo = $response->dto(); } catch (IpLookupException $e) { echo "IP 查询失败: " . $e->getMessage(); } catch (\Exception $e) { echo "发生错误: " . $e->getMessage(); }
扩展
要添加新的 IP 地理位置服务提供商,只需创建一个新的 Request 类并实现必要的方法。例如:
namespace Weijiajia\Requests; use Saloon\Enums\Method; use Saloon\Http\Request; class NewProviderRequest extends Request { protected Method $method = Method::GET; public function __construct(protected string $ip) { } public function resolveEndpoint(): string { return 'https://api.newprovider.com/ip-lookup'; } // 实现必要的方法... public function createDtoFromResponse(Response $response): IpResponse { $json = $response->json(); return new IpResponse([ 'city' => $response->json('city'), 'addr' => $response->json('addr'), 'ip' => $response->json('ip'), ... ]); } } // 使用新的 IP 地理位置服务提供商 $connector = new IpConnector(); $request = new NewProviderRequest('your ip address'); $response = $connector->send($request); $ipInfo = $response->dto(); echo $ipInfo->getCity(); // 输出城市信息 echo $ipInfo->getAddr(); // 输出详细地址
参考文档
贡献指南
我们欢迎并感谢任何形式的贡献。以下是一些贡献的方式:
- 报告 Bug
- 提交功能请求
- 提交代码改进
- 改进文档
提交 Pull Request
- Fork 本仓库
- 创建您的特性分支 (
git checkout -b feature/AmazingFeature) - 提交您的改动 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 创建一个 Pull Request
许可证
IP Address 是开源软件,基于 MIT 许可证。
weijiajia/ip-address 适用场景与选型建议
weijiajia/ip-address 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ip address」 「IP Info」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 weijiajia/ip-address 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 weijiajia/ip-address 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 weijiajia/ip-address 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
(ru) language pack for the Static Info Tables providing localized names for countries, currencies and so on.
Maps in minutes. Powered by the Google Maps API.
Redirects TYPO3 visitors automatic or with a suggestlink to another language and/or root page.
Module adding custom shipping attribute for what3words address
Turkish (tr) language pack for the Static Info Tables providing localized names for countries.
laravel geo location, ip services, proxy and vpn detected
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-03