mirror of
https://github.com/tursom/typecho-plugin-Access.git
synced 2026-08-19 08:13:27 +08:00
1.6 使用离线ip数据库,支持前端异步写入日志
This commit is contained in:
23
Action.php
23
Action.php
@@ -22,17 +22,32 @@ class Access_Action implements Widget_Interface_Do
|
||||
{
|
||||
}
|
||||
|
||||
public function writeLogs()
|
||||
{
|
||||
$this->access->writeLogs($this->request->u);
|
||||
$this->response->setStatus(206);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function ip()
|
||||
{
|
||||
$this->response->setContentType('application/json');
|
||||
try {
|
||||
$this->checkAuth();
|
||||
$ip = $this->request->get('ip');
|
||||
$response = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
|
||||
if (!$response) {
|
||||
throw new Exception('HTTP request failed');
|
||||
$response = Access_Ip::find($ip);
|
||||
if (is_array($response)) {
|
||||
$response = array(
|
||||
'code' => 0,
|
||||
'data' => implode(' ', $response),
|
||||
);
|
||||
} else {
|
||||
$response = array(
|
||||
'code' => 100,
|
||||
'message' => '解析ip失败',
|
||||
);
|
||||
}
|
||||
exit($response);
|
||||
exit(Json::encode($response));
|
||||
} catch (Exception $e) {
|
||||
exit(Json::encode(array(
|
||||
'code' => 100,
|
||||
|
||||
Reference in New Issue
Block a user