sign.go 596 B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "crypto/md5"
  4. "fmt"
  5. "sort"
  6. "strings"
  7. )
  8. //请求参数签名校验
  9. func GetSign(postData map[string]string) (sign string) {
  10. var keys []string
  11. for k, _ := range postData {
  12. if k != "sign" {
  13. keys = append(keys, k)
  14. }
  15. }
  16. //1,根据参数名称的ASCII码表的顺序排序
  17. sort.Strings(keys)
  18. //2 根据排序后的参数名称,取出对应的值,并拼接字符串
  19. var signStr string
  20. for _, v := range keys {
  21. signStr += v + "=" + postData[v] + "&"
  22. }
  23. sign = strings.ToUpper(fmt.Sprintf("%x", md5.Sum([]byte(signStr+"secret="+ReportSecret))))
  24. return
  25. }