user_auth_test.go
1.2 KB
package domain
import (
"testing"
"github.com/dgrijalva/jwt-go"
)
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3422181461696000,
Phone: "13066667702",
PlatformId: 29,
AdminType: 1,
}
tk, _ := ut.CreateAccessToken()
t.Log(tk)
}
func TestParsetToken1(t *testing.T) {
ut := UserAuth{}
str := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjM0MjE4NDc3MjcyOTYwMDAsImNvbXBhbnlJZCI6MTAsImNvbXBhbnlOYW1lIjoi5aSp6IGU5L-h5oGv56eR5oqA5pyJ6ZmQ5YWs5Y-4IiwicGhvbmUiOiIxNTY1OTM3NTk0MCIsInBsYXRmb3JtSWQiOjI5LCJuYW1lIjoi5bq35Lyf5Y2OIiwiYWRtaW5UeXBlIjoxfQ.v4qNLvYST03XpBdGnhYTK78A9v_k5IOdZ4r-WmDwfYg`
tk, _ := ut.ParseAccessToken(str)
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)
}