package lib import ( "crypto/md5" "encoding/hex" "math/rand" "strings" "time" ) // #取得随机字符串:通过打乱slice来操作 func GetRandstring(length int, char string, rand_x int64) string { if length < 1 { return "" } if len(char) <= 6 || len(char) <= length { char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" } charArr := strings.Split(char, "") ran := rand.New(rand.NewSource(time.Now().Unix() + rand_x)) l := len(charArr) for i := l - 1; i > 0; i-- { r := ran.Intn(i) charArr[r], charArr[i] = charArr[i], charArr[r] } rchar := charArr[:length] return strings.Join(rchar, "") } // 返回一个32位md5加密后的字符串 func Md5(str string) string { h := md5.New() h.Write([]byte(str)) return hex.EncodeToString(h.Sum(nil)) }