fix: 追加签名时,data是字符串时,特殊处理

master v1.0.1
wujianhua 2 years ago
parent 612c892688
commit 9b75360c69
  1. 22
      sign.go

@ -17,8 +17,6 @@ func CheckSign(appID, appKey, random, sign string, ts int, data interface{}) boo
return false return false
} }
v, _ := json.Marshal(data)
m := md5.New() m := md5.New()
sb := strings.Builder{} sb := strings.Builder{}
@ -26,7 +24,14 @@ func CheckSign(appID, appKey, random, sign string, ts int, data interface{}) boo
sb.WriteByte('-') sb.WriteByte('-')
sb.WriteString(cast.ToString(ts)) sb.WriteString(cast.ToString(ts))
sb.WriteByte('-') sb.WriteByte('-')
sb.Write(v)
if val, ok := data.(string); ok {
sb.WriteString(val)
} else {
val, _ := json.Marshal(data)
sb.Write(val)
}
sb.WriteByte('-') sb.WriteByte('-')
sb.WriteString(random) sb.WriteString(random)
sb.WriteByte('-') sb.WriteByte('-')
@ -44,8 +49,6 @@ func Sign(appID, appKey string, data interface{}) (sign string, random string, t
ts = int(time.Now().Unix()) ts = int(time.Now().Unix())
v, _ := json.Marshal(data)
m := md5.New() m := md5.New()
sb := strings.Builder{} sb := strings.Builder{}
@ -53,7 +56,14 @@ func Sign(appID, appKey string, data interface{}) (sign string, random string, t
sb.WriteByte('-') sb.WriteByte('-')
sb.WriteString(cast.ToString(ts)) sb.WriteString(cast.ToString(ts))
sb.WriteByte('-') sb.WriteByte('-')
sb.Write(v)
if val, ok := data.(string); ok {
sb.WriteString(val)
} else {
val, _ := json.Marshal(data)
sb.Write(val)
}
sb.WriteByte('-') sb.WriteByte('-')
sb.WriteString(random) sb.WriteString(random)
sb.WriteByte('-') sb.WriteByte('-')

Loading…
Cancel
Save