gtoken
gtoken copied to clipboard
token decode error
gfToken.GetTokenData(r).Data
it can't get Data, show ERROR:
2024-08-18 19:53:50.279 [ERRO] {cc5af3c185d0ec17ef56120c30a510df} [GToken]token decode error NL4h2VWnkTTSPtPYrPMiuSbRzgdUobEZ tMJO1zHqXGu6boS s4T p/43Ob4WMaA base64.StdEncoding.Decode failed: illegal base64 data at input byte 32 Stack:
- github.com/goflyfox/gtoken/gtoken.(*GfToken).DecryptToken E:/test/gtoken-master/gtoken/gtoken.go:352
- github.com/goflyfox/gtoken/gtoken.(*GfToken).validToken E:/test/gtoken-master/gtoken/gtoken.go:258
- github.com/goflyfox/gtoken/gtoken.(*GfToken).authMiddleware E:/test/gtoken-master/gtoken/gtoken.go:127
// 登录前置 func LoginBefore(r *ghttp.Request) (string, interface{}) { username := r.Get("username").String() passwd := r.Get("password").String() password, err := utility.HashPassword(passwd, username) if err != nil { r.Response.WriteJsonExit(g.Map{ "state": consts.ERROR, "message": "密码加密失败!", }) } ctx := r.Context() var employee = new(entity.Employee) er := dao.Employee.Ctx(ctx).Where(g.Map{ dao.Employee.Columns().LoginName: username, dao.Employee.Columns().PasswordHash: password, }).Scan(&employee) if er != nil { r.Response.WriteJsonExit(g.Map{ "state": consts.ERROR, "message": "数据库查询错误", }) } else if employee == nil { r.Response.WriteJsonExit(g.Map{ "state": consts.ERROR, "message": "用户名或密码错误!", }) } var accountType = new(entity.AccountType) er = dao.AccountType.Ctx(ctx).WherePri(employee.TypeId).Scan(&accountType) if er != nil { r.Response.WriteJsonExit(g.Map{ "state": consts.ERROR, "message": "数据库查询错误", }) } else if accountType == nil { r.Response.WriteJsonExit(g.Map{ "state": consts.ERROR, "message": "查询账户类型表数据错误!", }) } return username, "22222" }
// 登录成功后返回token func LoginAfter(r *ghttp.Request, respData gtoken.Resp) { token := respData.GetString(gtoken.KeyToken) fmt.Println("token:", token) fmt.Println("resp:", respData.Data)
fmt.Println("data:", respData.Get("data"),"<---")
var p model.TokenInfo
err := gconv.Struct(respData.GetString("data"), &p)
if err != nil {
// 如果类型转换失败,返回错误
r.Response.WriteJsonExit(g.Map{
"state": consts.ERROR,
"message": "解析Token数据失败",
})
}
fmt.Println("employee:", p.Employee)
fmt.Println("accountType:", p.AccountType)
if respData.Success() {
r.Response.WriteJsonExit(g.Map{
"state": consts.SUCCESS,
"message": "登录成功!",
"data": g.Map{
"token": token,
"employee": p.Employee,
"accountType": p.AccountType,
},
})
} else {
r.Response.WriteJsonExit(g.Map{
"state": consts.ERROR,
"message": "登录失败!",
})
}
}
token: V4bR14kOR7oYu2chbIx7u9JWZW+vXrNQEusXqpIjVhMthexcolBbQso4KxId8N0O resp: map[token:V4bR14kOR7oYu2chbIx7u9JWZW+vXrNQEusXqpIjVhMthexcolBbQso4KxId8N0O userKey:admin uuid:efb9eb0464f20ddeac1acb7a73dd3dad] data: <---
I can't get "22222"