package encryption_decryption import ( "bytes" "crypto/md5" "encoding/hex" "encoding/json" "sort" "strings" ) func MakeSign(params map[string]interface{}) string { // 排序 keys := make([]string, len(params)) i := 0 for k, _ := range params { keys[i] = k i++ } sort.Strings(keys) byteBuf := bytes.NewBuffer([]byte{}) encoder := json.NewEncoder(byteBuf) encoder.SetEscapeHTML(false) err := encoder.Encode(params) if err != nil { panic(err) } data := byteBuf.String() h := md5.New() h.Write([]byte(strings.TrimRight(data, "\n"))) return hex.EncodeToString(h.Sum(nil)) }