|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// +---------------------------------------------------------------------- |
|
4
|
|
|
// | ThinkLibrary 6.0 for ThinkPhP 6.0 |
|
5
|
|
|
// +---------------------------------------------------------------------- |
|
6
|
|
|
// | 版权所有 2017~2020 [ https://www.dtapp.net ] |
|
7
|
|
|
// +---------------------------------------------------------------------- |
|
8
|
|
|
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary |
|
9
|
|
|
// +---------------------------------------------------------------------- |
|
10
|
|
|
// | 开源协议 ( https://mit-license.org ) |
|
11
|
|
|
// +---------------------------------------------------------------------- |
|
12
|
|
|
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary |
|
13
|
|
|
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary |
|
14
|
|
|
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library |
|
15
|
|
|
// +---------------------------------------------------------------------- |
|
16
|
|
|
|
|
17
|
|
|
namespace DtApp\ThinkLibrary\service\Ip; |
|
18
|
|
|
|
|
19
|
|
|
use DtApp\ThinkLibrary\exception\DtaException; |
|
20
|
|
|
use DtApp\ThinkLibrary\Service; |
|
21
|
|
|
use DtApp\ThinkLibrary\service\curl\HttpService; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* IP - 在线查询接口 |
|
25
|
|
|
* Class OnlineService |
|
26
|
|
|
* @package DtApp\ThinkLibrary\service\ip |
|
27
|
|
|
*/ |
|
28
|
|
|
class OnlineService extends Service |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* 需要查询的IP |
|
32
|
|
|
* @var |
|
33
|
|
|
*/ |
|
34
|
|
|
private $ip; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* 查询指定IP |
|
38
|
|
|
* @param string $str |
|
39
|
|
|
* @return $this |
|
40
|
|
|
*/ |
|
41
|
|
|
public function ip(string $str): self |
|
42
|
|
|
{ |
|
43
|
|
|
$this->ip = $str; |
|
44
|
|
|
return $this; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* 哔哩哔哩ip查询接口 |
|
49
|
|
|
* @return array|bool|mixed|string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function biliBili() |
|
52
|
|
|
{ |
|
53
|
|
|
$url = "https://api.bilibili.com/x/web-interface/zone"; |
|
54
|
|
|
return HttpService::instance() |
|
55
|
|
|
->url($url) |
|
56
|
|
|
->toArray(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* batch |
|
61
|
|
|
* @param string $lang 语言 |
|
62
|
|
|
* @return array|bool|mixed|string |
|
63
|
|
|
*/ |
|
64
|
|
|
public function batch(string $lang = 'zh-CN') |
|
65
|
|
|
{ |
|
66
|
|
|
$url = "http://ip-api.com/json/?lang={$lang}"; |
|
67
|
|
|
return HttpService::instance() |
|
68
|
|
|
->url($url) |
|
69
|
|
|
->toArray(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* lookup |
|
74
|
|
|
* @return array|bool|mixed|string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function lookup() |
|
77
|
|
|
{ |
|
78
|
|
|
$url = "https://extreme-ip-lookup.com/json/"; |
|
79
|
|
|
return HttpService::instance() |
|
80
|
|
|
->url($url) |
|
81
|
|
|
->toArray(); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* 网易IP查询接口 |
|
86
|
|
|
* @return array|bool|mixed|string |
|
87
|
|
|
*/ |
|
88
|
|
|
public function netEase() |
|
89
|
|
|
{ |
|
90
|
|
|
$url = "https://ipservice.3g.163.com/ip"; |
|
91
|
|
|
return HttpService::instance() |
|
92
|
|
|
->url($url) |
|
93
|
|
|
->toArray(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* 百度搜索 |
|
98
|
|
|
* @return bool|false|mixed|string|string[] |
|
99
|
|
|
*/ |
|
100
|
|
|
public function baidu() |
|
101
|
|
|
{ |
|
102
|
|
|
if (empty($this->ip)) { |
|
103
|
|
|
$this->ip = get_ip(); |
|
104
|
|
|
} |
|
105
|
|
|
$url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$this->ip}&co=&resource_id=6006&ie=utf8&oe=utf8&cb=json"; |
|
106
|
|
|
$res = HttpService::instance() |
|
107
|
|
|
->url($url) |
|
108
|
|
|
->toArray(false); |
|
109
|
|
|
$res = str_replace("/**/json", "", $res); |
|
110
|
|
|
$res = substr($res, 1); |
|
111
|
|
|
$res = substr($res, 0, -2); |
|
112
|
|
|
$res = json_decode($res, true); |
|
113
|
|
|
return $res; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* 太平洋 |
|
118
|
|
|
* @return bool|false|mixed|string |
|
119
|
|
|
*/ |
|
120
|
|
|
public function pConLine() |
|
121
|
|
|
{ |
|
122
|
|
|
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true"; |
|
123
|
|
|
if (!empty($this->ip)) { |
|
124
|
|
|
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip={$this->ip}"; |
|
125
|
|
|
} |
|
126
|
|
|
$res = HttpService::instance() |
|
127
|
|
|
->url($url) |
|
128
|
|
|
->toArray(false); |
|
129
|
|
|
preg_match('/{.+}/', $res, $res); |
|
|
|
|
|
|
130
|
|
|
$res = iconv('gbk', 'utf-8', $res[0]); |
|
131
|
|
|
$res = json_decode($res, true); |
|
132
|
|
|
return $res; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* 新浪 |
|
137
|
|
|
* @return bool|false|mixed|string|string[] |
|
138
|
|
|
*/ |
|
139
|
|
|
public function siNa() |
|
140
|
|
|
{ |
|
141
|
|
|
if (empty($this->ip)) { |
|
142
|
|
|
$this->ip = get_ip(); |
|
143
|
|
|
} |
|
144
|
|
|
$url = "http://ip.ws.126.net/ipquery?ip={$this->ip}"; |
|
145
|
|
|
$res = HttpService::instance() |
|
146
|
|
|
->url($url) |
|
147
|
|
|
->toArray(false); |
|
148
|
|
|
$res = iconv('gbk', 'utf-8', $res); |
|
|
|
|
|
|
149
|
|
|
$res = substr($res, strpos($res, "{")); |
|
150
|
|
|
$res = substr($res, 0, -2); |
|
151
|
|
|
$res = str_replace(array("city", "province"), array('"city"', '"province"'), $res); |
|
152
|
|
|
$res = json_decode($res, true); |
|
153
|
|
|
return $res; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* 好搜 |
|
158
|
|
|
* @return bool|mixed|string |
|
159
|
|
|
*/ |
|
160
|
|
|
public function so() |
|
161
|
|
|
{ |
|
162
|
|
|
if (empty($this->ip)) { |
|
163
|
|
|
$this->ip = get_ip(); |
|
164
|
|
|
} |
|
165
|
|
|
$url = "https://open.onebox.so.com/dataApi?type=ip&src=onebox&tpl=0&num=1&query=ip&ip={$this->ip}&url=ip"; |
|
166
|
|
|
return HttpService::instance() |
|
167
|
|
|
->url($url) |
|
168
|
|
|
->toArray(); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* 搜狐 |
|
173
|
|
|
*/ |
|
174
|
|
|
public function soHu() |
|
175
|
|
|
{ |
|
176
|
|
|
$url = "http://pv.sohu.com/cityjson?ie=utf-8"; |
|
177
|
|
|
$res = HttpService::instance() |
|
178
|
|
|
->url($url) |
|
179
|
|
|
->toArray(false); |
|
180
|
|
|
$res = str_replace("var returnCitySN = ", "", $res); |
|
181
|
|
|
$res = substr($res, 0, -1); |
|
182
|
|
|
$res = json_decode($res, true); |
|
183
|
|
|
return $res; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* 淘宝 |
|
188
|
|
|
* @param string $ip IP地址 |
|
189
|
|
|
* @return bool|mixed|string |
|
190
|
|
|
*/ |
|
191
|
|
|
public function taoBao(string $ip = '') |
|
|
|
|
|
|
192
|
|
|
{ |
|
193
|
|
|
if (empty($this->ip)) { |
|
194
|
|
|
$this->ip = get_ip(); |
|
195
|
|
|
} |
|
196
|
|
|
$url = "http://ip.taobao.com/service/getIpInfo.php?ip={$this->ip}"; |
|
197
|
|
|
return HttpService::instance() |
|
198
|
|
|
->url($url) |
|
199
|
|
|
->toArray(); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* 阿里云 |
|
204
|
|
|
* @param string $appcode |
|
205
|
|
|
* @return bool|mixed|string |
|
206
|
|
|
* @throws DtaException |
|
207
|
|
|
*/ |
|
208
|
|
|
public function aliYun(string $appcode = '') |
|
209
|
|
|
{ |
|
210
|
|
|
if (empty($this->ip)) { |
|
211
|
|
|
$this->ip = get_ip(); |
|
212
|
|
|
} |
|
213
|
|
|
$host = "http://iploc.market.alicloudapi.com"; |
|
214
|
|
|
$path = "/v3/ip"; |
|
215
|
|
|
$method = "GET"; |
|
216
|
|
|
if (empty($appcode)) { |
|
217
|
|
|
throw new DtaException('请检查阿里-阿里云配置信息 appcode'); |
|
218
|
|
|
} |
|
219
|
|
|
$headers = array(); |
|
220
|
|
|
$headers[] = "Authorization:APPCODE " . $appcode; |
|
221
|
|
|
$querys = "ip={$this->ip}"; |
|
222
|
|
|
$bodys = ""; |
|
|
|
|
|
|
223
|
|
|
$url = $host . $path . "?" . $querys; |
|
224
|
|
|
|
|
225
|
|
|
$curl = curl_init(); |
|
226
|
|
|
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); |
|
227
|
|
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
228
|
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
229
|
|
|
curl_setopt($curl, CURLOPT_FAILONERROR, false); |
|
230
|
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
231
|
|
|
curl_setopt($curl, CURLOPT_HEADER, false); |
|
232
|
|
|
if (1 == strpos("$" . $host, "https://")) { |
|
233
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); |
|
234
|
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); |
|
235
|
|
|
} |
|
236
|
|
|
$content = curl_exec($curl); |
|
237
|
|
|
curl_close($curl); |
|
238
|
|
|
return json_decode($content, true); |
|
|
|
|
|
|
239
|
|
|
} |
|
240
|
|
|
} |
|
241
|
|
|
|