mirror of
https://github.com/tursom/typecho-plugin-Access.git
synced 2024-12-28 05:40:40 +08:00
ip查询失败后采用keycdn接口查询 (#8)
This commit is contained in:
parent
b23ee237ff
commit
e4e18109c4
37
Action.php
37
Action.php
@ -32,9 +32,9 @@ class Access_Action implements Widget_Interface_Do
|
||||
public function ip()
|
||||
{
|
||||
$this->response->setContentType('application/json');
|
||||
$ip = $this->request->get('ip');
|
||||
try {
|
||||
$this->checkAuth();
|
||||
$ip = $this->request->get('ip');
|
||||
$response = Access_Ip::find($ip);
|
||||
if (is_array($response)) {
|
||||
$response = array(
|
||||
@ -42,18 +42,27 @@ class Access_Action implements Widget_Interface_Do
|
||||
'data' => implode(' ', $response),
|
||||
);
|
||||
} else {
|
||||
throw new Exception('解析ip失败');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
try {
|
||||
$http = Typecho_Http_Client::get();
|
||||
$result = $http->send('https://tools.keycdn.com/geo.json?host=' . $ip);
|
||||
$result = Json::decode($result, true);
|
||||
if ($result['status'] == 'success') {
|
||||
$response = array(
|
||||
'code' => 0,
|
||||
'data' => $result['data']['geo']['country_name'] . ' ' . $result['data']['geo']['city'],
|
||||
);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$response = array(
|
||||
'code' => 100,
|
||||
'message' => '解析ip失败',
|
||||
'data' => '很抱歉,ipip.net查询无结果,同时你的服务器无法连接fallback接口(tools.keycdn.com)',
|
||||
);
|
||||
}
|
||||
exit(Json::encode($response));
|
||||
} catch (Exception $e) {
|
||||
exit(Json::encode(array(
|
||||
'code' => 100,
|
||||
'message' => $e->getMessage(),
|
||||
)));
|
||||
}
|
||||
exit(Json::encode($response));
|
||||
}
|
||||
|
||||
public function deleteLogs()
|
||||
@ -67,16 +76,18 @@ class Access_Action implements Widget_Interface_Do
|
||||
throw new Exception('params invalid');
|
||||
}
|
||||
$this->access->deleteLogs($data);
|
||||
exit(Json::encode(array(
|
||||
$response = array(
|
||||
'code' => 0,
|
||||
)));
|
||||
);
|
||||
|
||||
} catch (Exception $e) {
|
||||
exit(Json::encode(array(
|
||||
$response = array(
|
||||
'code' => 100,
|
||||
'message' => $e->getMessage(),
|
||||
)));
|
||||
'data' => $e->getMessage(),
|
||||
);
|
||||
}
|
||||
|
||||
exit(Json::encode($response));
|
||||
}
|
||||
|
||||
protected function checkAuth()
|
||||
|
@ -274,7 +274,7 @@ $(document).ready(function() {
|
||||
} else {
|
||||
swal({
|
||||
title: "IP查询失败",
|
||||
text: '接口返回状态码错误',
|
||||
text: data.data,
|
||||
type: "warning",
|
||||
confirmButtonText: "OK"
|
||||
});
|
||||
@ -326,12 +326,12 @@ $(document).ready(function() {
|
||||
$('.typecho-list-table tbody tr[data-id="' + elem + '"]').fadeOut(500).remove();
|
||||
});
|
||||
} else {
|
||||
swal({
|
||||
title: "错误",
|
||||
text: '发生错误了',
|
||||
type: "warning",
|
||||
confirmButtonText: "OK"
|
||||
});
|
||||
swal({
|
||||
title: "错误",
|
||||
text: '发生错误了',
|
||||
type: "warning",
|
||||
confirmButtonText: "OK"
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user