1. TODO: guest_id 2. jwt的封装

This commit is contained in:
eson
2023-06-12 19:52:11 +08:00
parent b6095d67ad
commit bdaa3bf48b
9 changed files with 100 additions and 88 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/golang-jwt/jwt"
"github.com/google/uuid"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -47,6 +48,14 @@ func GenerateJwtToken(accessSecret string, accessExpire, nowSec int64, userid in
claims["exp"] = nowSec + accessExpire
claims["iat"] = nowSec
claims["userid"] = userid
if userid == 0 {
u, err := uuid.NewUUID()
if err != nil {
logx.Error(err)
return "", err
}
claims["guestid"] = u.String() // TODO: 未完成
}
token := jwt.New(jwt.SigningMethodHS256)
token.Claims = claims
return token.SignedString([]byte(accessSecret))