diff --git a/api/service/Public.go b/api/service/Public.go index 8bd62af..d529e36 100644 --- a/api/service/Public.go +++ b/api/service/Public.go @@ -8,6 +8,7 @@ import ( "hepa-calc-api/extend/aliyun" "hepa-calc-api/global" "math/rand" + "net/http" "strconv" "time" ) @@ -121,3 +122,12 @@ func (r *PublicService) GetIndex(userId int64) (g *dto.IndexDto, err error) { return g, nil } + +// GetUserIP 获取用户ip +func (r *PublicService) GetUserIP(h *http.Request) string { + forwarded := h.Header.Get("X-FORWARDED-FOR") + if forwarded != "" { + return forwarded + } + return h.RemoteAddr +}