30 lines
621 B
Go
30 lines
621 B
Go
package yunda
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"encoding/hex"
|
|
"sort"
|
|
"strings"
|
|
)
|
|
|
|
func BuildSign(appKey, appSecret string, params map[string]string) string {
|
|
values := make(map[string]string, len(params)+2)
|
|
for key, value := range params {
|
|
values[key] = value
|
|
}
|
|
values["appKey"] = appKey
|
|
values["appSecret"] = appSecret
|
|
keys := make([]string, 0, len(values))
|
|
for key := range values {
|
|
keys = append(keys, key)
|
|
}
|
|
sort.Strings(keys)
|
|
source := appKey
|
|
for _, key := range keys {
|
|
source += key + values[key]
|
|
}
|
|
source += appKey
|
|
sum := md5.Sum([]byte(source))
|
|
return strings.ToUpper(hex.EncodeToString(sum[:]))
|
|
}
|