代码拉取完成,页面将自动刷新
package crypto
import (
"fmt"
"gitee.com/xlizy/common-go/base/config"
"gitee.com/xlizy/common-go/base/const"
"gitee.com/xlizy/common-go/utils/json"
"sort"
"time"
)
func GenSign(obj any, app string) string {
m := make(map[string]any)
keys := make([]string, 0)
jsonStr := json.ToJsonStr(obj)
json.ToObj(jsonStr, &m)
for k, _ := range m {
if k != "sign" {
keys = append(keys, k)
}
}
sort.Strings(keys)
o := ""
for _, k := range keys {
o += k
o += fmt.Sprintf("%v", m[k])
}
if config.AppSign.Sign[app] == "" {
o += "W4v0s1yoyvpYADUHeNpgbrTpu6a2cgEC"
} else {
o += config.AppSign.Sign[app]
}
return Md5(o)
}
func CheckSign(obj any, app string) bool {
m := make(map[string]any)
keys := make([]string, 0)
jsonStr := json.ToJsonStr(obj)
json.ToObj(jsonStr, &m)
for k, _ := range m {
if k != "sign" {
keys = append(keys, k)
}
}
sort.Strings(keys)
o := ""
for _, k := range keys {
o += k
o += fmt.Sprintf("%v", m[k])
}
if app == "" {
o += "W4v0s1yoyvpYADUHeNpgbrTpu6a2cgEC"
} else {
o += config.AppSign.Sign[app]
}
sign := Md5(o)
if m["timestamp"] != "" {
t, e := time.Parse(constant.DataFormat, fmt.Sprintf("%v", m["timestamp"]))
if e != nil {
return false
}
if time.Now().After(t.Add(5 * time.Minute)) {
return false
}
}
if m["sign"] == sign {
return true
}
return false
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。