user_auth_test.go
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package domain
import (
"testing"
"github.com/dgrijalva/jwt-go"
)
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3245763369805568,
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)
}