update ui.
This commit is contained in:
parent
1f42f38563
commit
88f5f64969
26
ajax.js
26
ajax.js
@ -5,22 +5,34 @@ layui.use(['form'], function () {
|
|||||||
var index = layer.load(2, {tiem: 999999});
|
var index = layer.load(2, {tiem: 999999});
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "get",
|
type: "get",
|
||||||
url: "/api",
|
url: "/api/",
|
||||||
data: data.field,
|
data: data.field,
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
if (data.code == 200) {
|
if (data.status === 0) {
|
||||||
let ipInfo = "";
|
let ipInfo = "";
|
||||||
|
|
||||||
ipInfo += " <tr>\n" +
|
ipInfo += " <tr>\n" +
|
||||||
" <td>地址:<span style='margin-left: 3px'> " + data.data.ip + "</span></td>\n" +
|
" <td>IP:<span style='margin-left: 3px'> " + data.result.ip + "</span></td>\n" +
|
||||||
" </tr>\n";
|
" </tr>\n";
|
||||||
|
|
||||||
ipInfo += " <tr>\n" +
|
ipInfo += " <tr>\n" +
|
||||||
" <td>城市:<span style='margin-left: 3px'> " + data.data.country + "</span></td>\n" +
|
" <td>国:<span style='margin-left: 3px'> " + data.result.ad_info.nation + "</span></td>\n" +
|
||||||
" </tr>\n";
|
" </tr>\n";
|
||||||
|
|
||||||
ipInfo += " <tr>\n" +
|
ipInfo += " <tr>\n" +
|
||||||
" <td>区域:<span style='margin-left: 3px'> " + data.data.area + "</span></td>\n" +
|
" <td>省:<span style='margin-left: 3px'> " + data.result.ad_info.province + "</span></td>\n" +
|
||||||
|
" </tr>\n";
|
||||||
|
|
||||||
|
ipInfo += " <tr>\n" +
|
||||||
|
" <td>市:<span style='margin-left: 3px'> " + data.result.ad_info.city + "</span></td>\n" +
|
||||||
|
" </tr>\n";
|
||||||
|
|
||||||
|
ipInfo += " <tr>\n" +
|
||||||
|
" <td>区:<span style='margin-left: 3px'> " + data.result.ad_info.district + "</span></td>\n" +
|
||||||
|
" </tr>\n";
|
||||||
|
|
||||||
|
ipInfo += " <tr>\n" +
|
||||||
|
" <td>经纬度:<span style='margin-left: 3px'> " + data.result.location.lat + "," + data.result.location.lng + "</span></td>\n" +
|
||||||
" </tr>\n";
|
" </tr>\n";
|
||||||
|
|
||||||
let head = "";
|
let head = "";
|
||||||
@ -39,7 +51,7 @@ layui.use(['form'], function () {
|
|||||||
});
|
});
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
} else {
|
} else {
|
||||||
layer.msg(data.text, {icon: 2});
|
layer.msg(data.message, {icon: 2});
|
||||||
layer.close(index);
|
layer.close(index);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -13,7 +13,7 @@ function curl_get($url){
|
|||||||
curl_setopt($curl, CURLOPT_URL, $url);
|
curl_setopt($curl, CURLOPT_URL, $url);
|
||||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||||
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
|
curl_setopt($curl, CURLOPT_TIMEOUT, 1);
|
||||||
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
|
curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
|
||||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||||
@ -29,6 +29,28 @@ function curl_get($url){
|
|||||||
}
|
}
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function is_domain($domain){
|
||||||
|
$pat = "/^(\w+:\/\/)?([^\/]+)/i";
|
||||||
|
if(preg_match($pat, $domain, $matches)){
|
||||||
|
if($matches[2]){
|
||||||
|
return 1;
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$ip = isset($_GET["ip"])?$_GET["ip"]:'';
|
$ip = isset($_GET["ip"])?$_GET["ip"]:'';
|
||||||
|
if(!filter_var($ip, FILTER_VALIDATE_IP)){
|
||||||
|
//非合法IP则判断是否是域名
|
||||||
|
if(is_domain($ip)){
|
||||||
|
$ip = gethostbyname($ip); //是域名则获取该域名的IP
|
||||||
|
}else{
|
||||||
|
//既非IP也非域名,此处做错误任务处理
|
||||||
|
}
|
||||||
|
}
|
||||||
$url = sprintf("https://apis.map.qq.com/ws/location/v1/ip?ip=%s&key=%s", urlencode($ip), API_KEY);
|
$url = sprintf("https://apis.map.qq.com/ws/location/v1/ip?ip=%s&key=%s", urlencode($ip), API_KEY);
|
||||||
echo curl_get($url);
|
echo curl_get($url);
|
||||||
Loading…
Reference in New Issue
Block a user