package token import ( "github.com/golang-jwt/jwt/v4" "mc-client-updater-server/pkg/conf" "mc-client-updater-server/pkg/log" "time" ) func NewToken(aud string) string { auds := make([]string, 1) auds = append(auds, aud) now := time.Now() token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{ "aud": auds, "iat": now, "nbf": now, }) tokenStr, err := token.SignedString([]byte(conf.Conf.Security.JWTSecret)) if err != nil { log.Logger.Error("生成Token失败:", err) return "" } return tokenStr }