| 1 | <?php |
||
| 5 | class IpTaobaoApiQuery extends IpQueryContract |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * 淘宝 IP 库 URL |
||
| 10 | */ |
||
| 11 | const URI = 'http://ip.taobao.com/service/getIpInfo.php?ip='; |
||
| 12 | /** |
||
| 13 | * @var int 超时时间 |
||
| 14 | */ |
||
| 15 | private $outTime = 1; |
||
| 16 | |||
| 17 | |||
| 18 | 9 | public function query($ip) |
|
| 19 | { |
||
| 20 | 9 | $this->ip = $ip; |
|
| 21 | 9 | $result = $this->doGet(self::URI . $this->ip); |
|
| 22 | 9 | if ($result !== false) { |
|
| 23 | 9 | $data = json_decode($result, 1); |
|
| 24 | 9 | if ($data['code'] !== 1) { |
|
| 25 | 9 | return $data['data']; |
|
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | return false; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * 设置超时时间,单位:s |
||
| 34 | * |
||
| 35 | * @param int $outTime |
||
| 36 | * |
||
| 37 | * @return $this |
||
| 38 | */ |
||
| 39 | 9 | public function setOutTime($outTime) |
|
| 45 | |||
| 46 | 9 | private function doGet($url) |
|
| 61 | } |