user_auth_test.go 1.3 KB
package domain

import (
	"testing"

	"github.com/dgrijalva/jwt-go"
)

func TestGenerateToken(t *testing.T) {
	ut := UserAuth{
		CompanyId:  8,
		UserId:     3422185340122624,
		Phone:      "13066667710",
		PlatformId: 29,
		AdminType:  1,
	}
	tk, _ := ut.CreateAccessToken()
	t.Log(tk)
}

func TestParsetToken1(t *testing.T) {
	ut := UserAuth{}
	str := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2ODM3ODMzNTIsImlzcyI6InBlcmZvcm1hbmNlIiwidXNlcklkIjozNDIyMTg1MzQwMTIyNjI0LCJjb21wYW55SWQiOjgsImNvbXBhbnlOYW1lIjoiIiwicGhvbmUiOiIxMzA2NjY2NzcxMCIsInBsYXRmb3JtSWQiOjI5LCJuYW1lIjoiIiwiYWRtaW5UeXBlIjoxfQ.aeIeCSZ3xARmz0NBPqYATFQPhnEHfQyC_Ny219urFGk`
	tk, err := ut.ParseAccessToken(str)
	t.Logf("err:%s", err)
	t.Logf("%+v", tk)
}
func TestParsetToken2(t *testing.T) {
	ut := UserAuth{}
	str := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjM0MjYxMDAxMTcwOTM4ODgsImNvbXBhbnlJZCI6MSwiY29tcGFueU5hbWUiOiLnpo_lt57ntKDlpKnkuIvpo5_lk4HmnInpmZDlhazlj7giLCJwaG9uZSI6IjE1NjU5Mzc1OTQwIiwicGxhdGZvcm1JZCI6MjksIm5hbWUiOiLlurfkvJ_ljY4iLCJhZG1pblR5cGUiOjF9.BwJ2mLdTlFKF322y4GeqPOW6wKroIrPSI8eNyuQEMkQ`
	tk, _ := ut.ParseAccessToken(str)
	t.Logf("===》%+v", tk)
	tk.StandardClaims = jwt.StandardClaims{}
	tk.PlatformId = 29
	tkStr, _ := tk.CreateAccessToken()
	t.Logf(" ===》%v", tkStr)
}