fusenapi/utils/feishu/verify.go
2023-11-07 14:19:18 +08:00

23 lines
475 B
Go

package feishu
import (
"crypto/sha256"
"fmt"
"strings"
)
// 计算签名
func CalculateFeiShuWebhookSignature(timestamp, nonce, encryptKey string, body []byte) string {
var b strings.Builder
b.WriteString(timestamp)
b.WriteString(nonce)
b.WriteString(encryptKey)
b.Write(body) //bodystring 指整个请求体,不要在反序列化后再计算
bs := []byte(b.String())
h := sha256.New()
h.Write(bs)
bs = h.Sum(nil)
sig := fmt.Sprintf("%x", bs)
return sig
}