Browse Source

优化APIKEY时间判断

zhou.xiaoning 1 year ago
parent
commit
b7d9cd3fcb
1 changed files with 2 additions and 1 deletions
  1. 2 1
      token/token.go

+ 2 - 1
token/token.go

@@ -6,6 +6,7 @@ import (
 	"encoding/hex"
 	"errors"
 	"fmt"
+	"math"
 	"mtp2_if/config"
 	"mtp2_if/global/e"
 	"mtp2_if/rediscli"
@@ -131,7 +132,7 @@ func Auth() gin.HandlerFunc {
 				c.Abort()
 				return
 			}
-			if time.Now().UnixMilli()-int64(t) > 10*1000 {
+			if math.Abs(float64(time.Now().UnixMilli()-int64(t))) > 10*1000 {
 				c.JSON(http.StatusUnauthorized, gin.H{
 					"code": e.ERROR,
 					"msg":  "apikey3",