This commit is contained in:
xiabin 2025-01-23 09:24:05 +08:00
parent 5e7770e955
commit 02e95503cf
5 changed files with 48 additions and 8 deletions

34
dev/generate_token.go Normal file
View File

@ -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)
}

View File

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

View File

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

View File

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

View File

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