Skip to content

Commit

Permalink
Update 优化 MD5 签名验证
Browse files Browse the repository at this point in the history
  • Loading branch information
xinliangnote committed Oct 8, 2019
1 parent 8eda2de commit 81355d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/route/middleware/sign/md5/md5.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func createMD5Sign(params url.Values) string {
var key []string
var str = ""
for k := range params {
if k != "sn" && k != "ts" && k != "debug" {
if k != "sn" && k != "debug" {
key = append(key, k)
}
}
Expand Down Expand Up @@ -83,8 +83,10 @@ func verifyMD5Sign(c *gin.Context) (map[string]string, error) {
}

if debug == "1" {
currentUnix := util.GetCurrentUnix()
req.Add("ts", strconv.FormatInt(currentUnix, 10))
res := map[string]string{
"ts": strconv.FormatInt(util.GetCurrentUnix(), 10),
"ts": strconv.FormatInt(currentUnix, 10),
"sn": createMD5Sign(req),
}
return res, nil
Expand All @@ -94,7 +96,7 @@ func verifyMD5Sign(c *gin.Context) (map[string]string, error) {

// 验证过期时间
timestamp := time.Now().Unix()
if ts > timestamp || timestamp - ts >= exp {
if ts > timestamp || timestamp-ts >= exp {
return nil, errors.New("ts Error")
}

Expand Down

0 comments on commit 81355d4

Please sign in to comment.