|
|
@@ -77,7 +77,8 @@ func CheckSign(c *gin.Context) error { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
if currentTimestamp-storedTimestamp < 0 { |
|
|
|
|
|
|
|
if isMillisecond(storedTimestamp) { |
|
|
|
//TODO::兼容客户端传毫秒 |
|
|
|
currentTimestamp = time.Now().UnixMilli() |
|
|
|
if currentTimestamp-storedTimestamp > 60*5*1000 { // 2分钟 |
|
|
@@ -85,16 +86,23 @@ func CheckSign(c *gin.Context) error { |
|
|
|
fmt.Println("storedTimestamp>>>>>:", storedTimestamp) |
|
|
|
return fmt.Errorf("签名过期~") |
|
|
|
} |
|
|
|
if currentTimestamp-storedTimestamp < -60*1000 { //避免客户端传过快时间的误差 |
|
|
|
return errors.New("签名超前~") |
|
|
|
} |
|
|
|
} else { |
|
|
|
if currentTimestamp-storedTimestamp > 60*5 { // 2分钟 |
|
|
|
fmt.Println("currentTimestamp>>>>>:", currentTimestamp) |
|
|
|
fmt.Println("storedTimestamp>>>>>:", storedTimestamp) |
|
|
|
return fmt.Errorf("签名过期!") |
|
|
|
} |
|
|
|
if currentTimestamp-storedTimestamp < -60 { //避免客户端传过快时间的误差 |
|
|
|
return errors.New("签名超前!") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if currentTimestamp-storedTimestamp < 0 { |
|
|
|
return errors.New("签名有误!") |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func isMillisecond(timestamp int64) bool { |
|
|
|
return timestamp > 1e12 && timestamp < 1e13 |
|
|
|
} |