2024-08-06 05:59:24 +00:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
type Token struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
UID string `json:"uid"`
|
|
|
|
DeviceID string `json:"device_id"`
|
|
|
|
AccessToken string `json:"access_token"`
|
|
|
|
ExpiresIn int `json:"expires_in"`
|
|
|
|
AccessCreateAt time.Time `json:"access_create_at"`
|
|
|
|
RefreshToken string `json:"refresh_token"`
|
|
|
|
RefreshExpiresIn int `json:"refresh_expires_in"`
|
|
|
|
RefreshCreateAt time.Time `json:"refresh_create_at"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Token) AccessTokenExpires() time.Duration {
|
|
|
|
return time.Duration(t.ExpiresIn) * time.Second
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Token) RefreshTokenExpires() time.Duration {
|
|
|
|
return time.Duration(t.RefreshExpiresIn) * time.Second
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Token) RefreshTokenExpiresUnix() int64 {
|
|
|
|
return time.Now().Add(t.RefreshTokenExpires()).Unix()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Token) IsExpires() bool {
|
|
|
|
return t.AccessCreateAt.Add(t.AccessTokenExpires()).Before(time.Now())
|
|
|
|
}
|
|
|
|
|
2024-08-11 12:21:42 +00:00
|
|
|
func (t *Token) RedisExpiredSec() int64 {
|
|
|
|
sec := time.Unix(int64(t.ExpiresIn), 0).Sub(time.Now().UTC())
|
|
|
|
|
|
|
|
return int64(sec.Seconds())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Token) RedisRefreshExpiredSec() int64 {
|
|
|
|
sec := time.Unix(int64(t.RefreshExpiresIn), 0).Sub(time.Now().UTC())
|
|
|
|
|
|
|
|
return int64(sec.Seconds())
|
|
|
|
}
|
|
|
|
|
2024-08-06 05:59:24 +00:00
|
|
|
type UIDToken map[string]int64
|
|
|
|
|
|
|
|
type Ticket struct {
|
2024-08-10 01:52:23 +00:00
|
|
|
Data any `json:"data"`
|
|
|
|
Token Token `json:"token"`
|
2024-08-06 05:59:24 +00:00
|
|
|
}
|