处理分享2

This commit is contained in:
2024-09-29 16:55:00 +08:00
parent 6431aa890b
commit c7daf18830
12 changed files with 302 additions and 96 deletions
+5 -2
View File
@@ -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()) // 签发时间