From e8295ceed6b27f5ee0a45d98a9e861815f973263 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 25 Aug 2023 17:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=95=B0=E5=AD=97=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/basic/request_parse.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/utils/basic/request_parse.go b/utils/basic/request_parse.go index 31d75674..8b99eab7 100644 --- a/utils/basic/request_parse.go +++ b/utils/basic/request_parse.go @@ -3,6 +3,7 @@ package basic import ( "errors" "log" + "strconv" "fusenapi/shared" "fusenapi/utils/auth" @@ -56,16 +57,21 @@ func RequestParse(w http.ResponseWriter, r *http.Request, svcCtx any, LogicReque var userinfo *auth.UserInfo var err error // log.Println(io.ReadAll(r.Body)) - token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息 + token := r.Header.Get("Authorization") + userId, err := strconv.ParseInt(token, 10, 63) if err != nil { - logx.Error(err) - return nil, err - } - - if token == "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjQyOTM0NjIsImd1ZXN0X2lkIjozNiwiaWF0IjozMTUzNjAwMCwidXNlcl9pZCI6MH0.T7PuRSrinlJu7ZZ1DVqUJLWXhY_6R1lXiUHaNdw35hU" { - userinfo = info + userinfo = &auth.UserInfo{ + UserId: userId, + } } else { var secret uint64 = 0 + + token, info, err := auth.ParseJwtTokenHeader[auth.UserInfo](r) //解析Token头, 和payload信息 + if err != nil { + logx.Error(err) + return nil, err + } + if info != nil { if info.IsUser() {