数据采集
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

11 kuukautta sitten
12345678910111213141516171819202122232425262728293031
  1. package utils
  2. import (
  3. "crypto/sha1"
  4. "encoding/hex"
  5. "sort"
  6. "strings"
  7. )
  8. // CheckSignature 微信公众号签名检查
  9. func CheckSignature(signature, timestamp, nonce, token string) bool {
  10. arr := []string{timestamp, nonce, token}
  11. // 字典序排序
  12. sort.Strings(arr)
  13. n := len(timestamp) + len(nonce) + len(token)
  14. var b strings.Builder
  15. b.Grow(n)
  16. for i := 0; i < len(arr); i++ {
  17. b.WriteString(arr[i])
  18. }
  19. return Sha1(b.String()) == signature
  20. }
  21. // 进行Sha1编码
  22. func Sha1(str string) string {
  23. h := sha1.New()
  24. h.Write([]byte(str))
  25. return hex.EncodeToString(h.Sum(nil))
  26. }