1.6 使用离线ip数据库,支持前端异步写入日志

This commit is contained in:
Kokororin
2016-12-11 18:55:12 +08:00
parent a7cf66e144
commit ce3fc9e4e7
6 changed files with 186 additions and 45 deletions

View File

@@ -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,