dengbiao 5 days ago
parent
commit
2a9fc608a1
1 changed files with 12 additions and 4 deletions
  1. +12
    -4
      app/lib/aes/check.go

+ 12
- 4
app/lib/aes/check.go View File

@@ -77,7 +77,8 @@ func CheckSign(c *gin.Context) error {
if err != nil { if err != nil {
return err return err
} }
if currentTimestamp-storedTimestamp < 0 {

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


if currentTimestamp-storedTimestamp < 0 {
return errors.New("签名有误!")
}
return nil return nil
} }

func isMillisecond(timestamp int64) bool {
return timestamp > 1e12 && timestamp < 1e13
}

Loading…
Cancel
Save