youtu_server/dev/generate_token.go

35 lines
655 B
Go
Raw Normal View History

2025-01-23 09:24:05 +08:00
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)
}