1 Star 0 Fork 0

h79 / gothird

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sign.go 605 Bytes
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2022-08-21 22:44 . init
package sign
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
)
// Sign 计算签名
func Sign(appKey, appSecret, method string, timestamp string, paramJson string) string {
// 按给定规则拼接参数
paramPattern := "app_key" + appKey + "method" + method + "param_json" + paramJson + "timestamp" + timestamp + "v2"
signPattern := appSecret + paramPattern + appSecret
return Hmac(signPattern, appSecret)
}
// Hmac 计算hmac
func Hmac(s string, appSecret string) string {
h := hmac.New(sha256.New, []byte(appSecret))
_, _ = h.Write([]byte(s))
return hex.EncodeToString(h.Sum(nil))
}
1
https://gitee.com/h79/gothird.git
git@gitee.com:h79/gothird.git
h79
gothird
gothird
v1.8.101

搜索帮助