feat(log): 添加QQWry IP数据库支持并实现IP地址解析功能

This commit is contained in:
1
2025-11-03 16:19:24 +00:00
parent e86e138d94
commit abaa51af38
7 changed files with 43 additions and 3 deletions

View File

@@ -2,12 +2,14 @@ package service
import (
"blazing/cool"
"fmt"
"blazing/modules/base/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/xiaoqidun/qqwry"
)
type BaseSysLogService struct {
@@ -44,7 +46,19 @@ func (s *BaseSysLogService) Record(ctx g.Ctx) {
baseSysLog.UserID = admin.UserId
baseSysLog.Action = r.Method + ":" + r.URL.Path
baseSysLog.IP = r.GetClientIp()
baseSysLog.IPAddr = r.GetClientIp()
// 从内存或缓存查询IP
location, err := qqwry.QueryIP("119.29.29.29")
if err != nil {
fmt.Printf("错误:%v\n", err)
return
}
baseSysLog.IPAddr = fmt.Sprintf("国家:%s省份%s城市%s区县%s运营商%s\n",
location.Country,
location.Province,
location.City,
location.District,
location.ISP,
)
baseSysLog.Params = r.GetBodyString()
m := cool.DBM(s.Model)
m.Insert(g.Map{
@@ -68,3 +82,11 @@ func (s *BaseSysLogService) Clear(isAll bool) (err error) {
}
return
}
func init() {
// 从文件加载IP数据库
if err := qqwry.LoadFile("public/qqwry.ipdb"); err != nil {
panic(err)
}
}