2024-04-08 10:13:01 +00:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/golang-jwt/jwt/v5"
|
|
|
|
)
|
|
|
|
|
|
|
|
type VestMoreClaims struct {
|
|
|
|
CustomerId int64 `json:"customer_id"`
|
|
|
|
Version string `json:"version"`
|
|
|
|
jwt.RegisteredClaims
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestSignTokenAndParseToken(t *testing.T) {
|
|
|
|
pwdhash := "123131"
|
|
|
|
vm := &VestMoreClaims{
|
|
|
|
RegisteredClaims: jwt.RegisteredClaims{
|
|
|
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
2024-04-11 09:21:44 +00:00
|
|
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), // 设置过期时间为当前时间加24小时
|
2024-04-08 10:13:01 +00:00
|
|
|
Issuer: "vermore",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
tstr, err := SignToken(pwdhash, vm)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
log.Println(tstr)
|
|
|
|
vmr := &VestMoreClaims{}
|
|
|
|
log.Println(ParseToken(tstr, pwdhash, vmr))
|
|
|
|
log.Println(vmr)
|
|
|
|
}
|