# ip2proxy-php-api **Repository Path**: kuotong/ip2proxy-php-api ## Basic Information - **Project Name**: ip2proxy-php-api - **Description**: 这个 IP2Proxy PHP 模块 提供 API 查询IP代理地址服务器的国家,地区,城市,ISP名称和代理服务类型等。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-04-20 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # IP2Proxy PHP API 如果IP地址用作开放式代理,网页代理,虚拟专用网络匿名器和洋葱路由出口节点,此模块允许用户查询IP地址。此模块使用 **IP2Proxy API** 查找代理IP地址。 ## 入门 首先,需要一个API密钥才能使此模块正常运行。想查找更多的信息可访问 https://www.ip2location.com/ip2proxy-web-service。 ## 安装程序 将以下内容添加到您composer.json文件中: ``` { "require": { "ip2location/ip2proxy-php-api": "1.*" } } ``` ## 用法 ``` apiKey = $apiKey; $this->useSSL = $useSSL; } public function query($ip) { if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { return false; } $response = $this->get('http' . (($this->useSSL) ? 's' : '') . '://api.ip2proxy.com/?' . http_build_query([ 'key' => $this->apiKey, 'ip' => $ip, 'package' => 'PX4', 'format' => 'json', ])); if (($json = json_decode($response)) === null) { return false; } $this->response = (string) $json->response; $this->countryCode = (string) $json->countryCode; $this->countryName = (string) $json->countryName; $this->regionName = (string) $json->regionName; $this->cityName = (string) $json->cityName; $this->isp = (string) $json->isp; $this->proxyType = (string) $json->proxyType; $this->isProxy = (string) $json->isProxy; return true; } private function get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_USERAGENT, 'IP2ProxyAPI_PHP-1.0.0'); curl_setopt($ch, CURLOPT_TIMEOUT, 3); $response = curl_exec($ch); return $response; } } ?> ``` ## 响应的信息 | 名称 | 说明 | | ---------- | ------------- | | response | 如果成功就OK,否则就失败。 | | countryCode | 2位数的国家代码。 | | countryName | 国家名称。 | | regionName | 地区或州名称。 | | cityName | 城市名称。 | | isp | 服务提供商名称。 | | isProxy | 如果IP是代理服务器,则为YES。如果IP不是代理,则为NO。DCH如果IP属于主机提供商,数据中心或内容交付网络。注意:DCH仅用于PX2,PX3和PX4查询 。 | | proxyType | 代理服务器的类型。 |