处理分享2
This commit is contained in:
+5
-2
@@ -9,12 +9,15 @@ import (
|
||||
type Token struct {
|
||||
UserId string `json:"user_id"` // 用户id
|
||||
Client int `json:"client"` // 客户端(1:前台 2:后台)
|
||||
QaId string `json:"qa_id"` // 知识问答id
|
||||
jwt.RegisteredClaims // v5版本新加的方法
|
||||
}
|
||||
|
||||
// NewJWT GenerateJWT 生成JWT
|
||||
func (t Token) NewJWT() (string, error) {
|
||||
ttl := time.Duration(config.C.Jwt.Ttl)
|
||||
func (t Token) NewJWT(ttl time.Duration) (string, error) {
|
||||
if ttl == 0 {
|
||||
ttl = time.Duration(config.C.Jwt.Ttl)
|
||||
}
|
||||
|
||||
t.RegisteredClaims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(ttl * time.Hour)) // 过期时间24小时
|
||||
t.RegisteredClaims.IssuedAt = jwt.NewNumericDate(time.Now()) // 签发时间
|
||||
|
||||
Reference in New Issue
Block a user