package tencentNlu import ( "crypto/hmac" "crypto/md5" "crypto/sha256" "fmt" "io" "math/rand" "time" ) //用appkey、appSceret和HMAC-SHA256(mac, secremacSHA256SecrettKey)三个字符串拼接,以":"作为分隔符,再做md5生成guid func ComputerMd5(orginStr string) string { data := []byte(orginStr) hash := md5.Sum(data) md5Str := fmt.Sprintf("%x", hash) return md5Str } func ComputeHmac256(message string, secret string) string { h := hmac.New(sha256.New, []byte(secret)) io.WriteString(h, message) return fmt.Sprintf("%x", h.Sum(nil)) } func getRandom(count int) int { r := rand.New(rand.NewSource(time.Now().UnixNano())) return r.Intn(count) } // 是否包含 func IsContain(source string, targetList []string) bool { for i := 0; i < len(targetList); i++ { if source == targetList[i] { return true } } return false }