From 02e95503cfe1156fcef378b071c98f61c63f20bc Mon Sep 17 00:00:00 2001 From: xiabin Date: Thu, 23 Jan 2025 09:24:05 +0800 Subject: [PATCH] fix --- dev/generate_token.go | 34 +++++++++++++++++++ .../logic/douyin/douyin_code2token_logic.go | 2 ++ .../internal/logic/game/ranking_list_logic.go | 6 +++- .../logic/game/ranking_set_score_logic.go | 7 ++-- game_open_api/model/game_score_model.go | 7 ++-- 5 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 dev/generate_token.go diff --git a/dev/generate_token.go b/dev/generate_token.go new file mode 100644 index 0000000..4982a9d --- /dev/null +++ b/dev/generate_token.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "github.com/golang-jwt/jwt/v4" + "time" +) + +func main() { + + claims := make(jwt.MapClaims) + claims["exp"] = time.Now().Add(time.Hour * 24).Unix() + claims["iat"] = 86400 + type AccessToken struct { + AppId uint64 `json:"appId"` + UserId uint64 `json:"userId"` + AppIdStr string `json:"appIdStr"` + OpenId string `json:"openId"` + } + + claims["payload"] = &AccessToken{ + AppId: 2, + UserId: 59, + AppIdStr: "1", + OpenId: "1", + } + token := jwt.New(jwt.SigningMethodHS256) + token.Claims = claims + tokenStr, err := token.SignedString([]byte("youtu123!")) + if err != nil { + fmt.Println(err) + } + fmt.Println(tokenStr) +} diff --git a/game_open_api/internal/logic/douyin/douyin_code2token_logic.go b/game_open_api/internal/logic/douyin/douyin_code2token_logic.go index f462eea..b5f2a49 100644 --- a/game_open_api/internal/logic/douyin/douyin_code2token_logic.go +++ b/game_open_api/internal/logic/douyin/douyin_code2token_logic.go @@ -70,6 +70,8 @@ func (l *DouyinCode2tokenLogic) DouyinCode2token(req *types.DouyinCode2TokenRequ AppIdStr: req.AppId, OpenId: res.Openid, } + l.Logger.Debugf("payload: %+v", claims["payload"]) + token := jwt.New(jwt.SigningMethodHS256) token.Claims = claims resp.Token, err = token.SignedString([]byte(l.svcCtx.Config.Auth.AccessSecret)) diff --git a/game_open_api/internal/logic/game/ranking_list_logic.go b/game_open_api/internal/logic/game/ranking_list_logic.go index a585db8..d8667ad 100644 --- a/game_open_api/internal/logic/game/ranking_list_logic.go +++ b/game_open_api/internal/logic/game/ranking_list_logic.go @@ -29,6 +29,9 @@ func (l *RankingListLogic) RankingList(req *types.RankingListRequest) (resp *typ return nil, err } + l.Logger.Debugf("at: %+v", at) + l.Logger.Debugf("req: %+v", req) + resp.RankingData, err = l.svcCtx.GameScore.GetRankList(l.ctx, at.AppId, req.Type, req.PageBase) if err != nil { return nil, err @@ -38,7 +41,8 @@ func (l *RankingListLogic) RankingList(req *types.RankingListRequest) (resp *typ for i := range resp.RankingData { if resp.RankingData[i].UserId == at.UserId { resp.RankingData[i].Self = true - resp.RankingData = append(resp.RankingData, resp.RankingData[i]) + d := resp.RankingData[i] + resp.RankingData = append(resp.RankingData, d) flag = true break } diff --git a/game_open_api/internal/logic/game/ranking_set_score_logic.go b/game_open_api/internal/logic/game/ranking_set_score_logic.go index 85d781d..e347224 100644 --- a/game_open_api/internal/logic/game/ranking_set_score_logic.go +++ b/game_open_api/internal/logic/game/ranking_set_score_logic.go @@ -46,12 +46,15 @@ func (l *RankingSetScoreLogic) RankingSetScore(req *types.SetUserGameScoreReques oldScore.Score = req.Score err = l.svcCtx.GameScore.UpdateScore(l.ctx, oldScore) } else { - err = l.svcCtx.GameScore.CreateScore(l.ctx, &model.GameScore{ + oldScore = &model.GameScore{ AppUserId: at.UserId, AppAccount: at.AppId, Score: req.Score, - }) + } + err = l.svcCtx.GameScore.CreateScore(l.ctx, oldScore) } + l.Logger.Debugf("GameScore: %+v", oldScore) + return } diff --git a/game_open_api/model/game_score_model.go b/game_open_api/model/game_score_model.go index a25c6bc..f00be34 100644 --- a/game_open_api/model/game_score_model.go +++ b/game_open_api/model/game_score_model.go @@ -118,11 +118,8 @@ FROM WHERE game_score.t = ?) AS gs LEFT JOIN app_user ON app_user.id = gs.app_user_id - AND gs.app_account = ? -WHERE - gs.app_user_id = ? - LIMIT 1` - return conn.QueryRowsPartialCtx(ctx, v, query, t, appId, userId) + AND gs.app_account = ? AND game_score.app_user_id = ? LIMIT 1` + return conn.QueryRowsPartialCtx(ctx, v, query, t, userId, appId) }) switch { case err == nil: