diff --git a/ajax.js b/ajax.js
index 85959e4..9a3f55e 100644
--- a/ajax.js
+++ b/ajax.js
@@ -5,22 +5,34 @@ layui.use(['form'], function () {
var index = layer.load(2, {tiem: 999999});
$.ajax({
type: "get",
- url: "/api",
+ url: "/api/",
data: data.field,
dataType: "json",
success: function (data) {
- if (data.code == 200) {
+ if (data.status === 0) {
let ipInfo = "";
-
ipInfo += "
\n" +
- " | 地址: " + data.data.ip + " | \n" +
+ " IP: " + data.result.ip + " | \n" +
"
\n";
ipInfo += " \n" +
- " | 城市: " + data.data.country + " | \n" +
+ " 国: " + data.result.ad_info.nation + " | \n" +
"
\n";
+
ipInfo += " \n" +
- " | 区域: " + data.data.area + " | \n" +
+ " 省: " + data.result.ad_info.province + " | \n" +
+ "
\n";
+
+ ipInfo += " \n" +
+ " | 市: " + data.result.ad_info.city + " | \n" +
+ "
\n";
+
+ ipInfo += " \n" +
+ " | 区: " + data.result.ad_info.district + " | \n" +
+ "
\n";
+
+ ipInfo += " \n" +
+ " | 经纬度: " + data.result.location.lat + "," + data.result.location.lng + " | \n" +
"
\n";
let head = "";
@@ -39,7 +51,7 @@ layui.use(['form'], function () {
});
layer.close(index);
} else {
- layer.msg(data.text, {icon: 2});
+ layer.msg(data.message, {icon: 2});
layer.close(index);
}
},
diff --git a/api/index.php b/api/index.php
index d05f0ed..14273d7 100644
--- a/api/index.php
+++ b/api/index.php
@@ -13,7 +13,7 @@ function curl_get($url){
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
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_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
@@ -29,6 +29,28 @@ function curl_get($url){
}
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"]:'';
+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);
echo curl_get($url);
\ No newline at end of file
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..0a82f18
--- /dev/null
+++ b/readme.md
@@ -0,0 +1 @@
+# 腾讯ip查询
\ No newline at end of file