benjamin-smith/php-ipify

php-ipify:ipify的PHP客户端库,一个简单的IP地址API。

1.0.0 2016-03-15 02:26 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:57:06 UTC


README

Software License Build Status Quality Score Total Downloads

此库将从ipify的API服务获取您的公网IP地址,并以字符串形式返回。

此库还有一些其他您可能关心的功能

  • 此库正确处理异常,以下的使用示例展示了如何以万无一失的方式处理错误。
  • 此库仅通过HTTPS进行API请求。

安装

通过Composer

$ composer require benjamin-smith/php-ipify

用法

echo Ipify\Ip::get();

或者,如果您想捕获任何错误

try {
    $ip = Ipify\Ip::get();    
} catch (ConnectionError $e) {
    // If you get here, it means you were unable to reach the ipify service,
    // most likely because of a network error on your end.
} catch (ServiceError $e) {
    // If you get here, it means ipify is having issues, so the request
    // couldn't be completed :(
} catch (Exception $e) {
    // Something else happened (non-ipify related).
}

变更日志

请参阅CHANGELOG了解最近有哪些变更。

测试

$ vendor/bin/phpunit

贡献

请参阅CONTRIBUTING以获取详细信息。

安全

如果您发现任何安全相关的问题,请通过ben@benjaminsmith.com发送电子邮件,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件