|
@@ -17,7 +17,6 @@ import (
|
|
|
"math/rand"
|
|
|
"net"
|
|
|
"os"
|
|
|
- "os/exec"
|
|
|
"regexp"
|
|
|
"sort"
|
|
|
"strconv"
|
|
@@ -25,13 +24,11 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-// 随机数种子
|
|
|
-var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
-
|
|
|
func GetRandString(size int) string {
|
|
|
allLetterDigit := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "!", "@", "#", "$", "%", "^", "&", "*"}
|
|
|
randomSb := ""
|
|
|
digitSize := len(allLetterDigit)
|
|
|
+ rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
for i := 0; i < size; i++ {
|
|
|
randomSb += allLetterDigit[rnd.Intn(digitSize)]
|
|
|
}
|
|
@@ -42,6 +39,7 @@ func GetRandStringNoSpecialChar(size int) string {
|
|
|
allLetterDigit := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
|
|
|
randomSb := ""
|
|
|
digitSize := len(allLetterDigit)
|
|
|
+ rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
for i := 0; i < size; i++ {
|
|
|
randomSb += allLetterDigit[rnd.Intn(digitSize)]
|
|
|
}
|
|
@@ -74,23 +72,6 @@ func MD5(data string) string {
|
|
|
return hex.EncodeToString(m[:])
|
|
|
}
|
|
|
|
|
|
-// 获取数字随机字符
|
|
|
-func GetRandDigit(n int) string {
|
|
|
- return fmt.Sprintf("%0"+strconv.Itoa(n)+"d", rnd.Intn(int(math.Pow10(n))))
|
|
|
-}
|
|
|
-
|
|
|
-// 获取随机数
|
|
|
-func GetRandNumber(n int) int {
|
|
|
- return rnd.Intn(n)
|
|
|
-}
|
|
|
-
|
|
|
-func GetRandInt(min, max int) int {
|
|
|
- if min >= max || min == 0 || max == 0 {
|
|
|
- return max
|
|
|
- }
|
|
|
- return rand.Intn(max-min) + min
|
|
|
-}
|
|
|
-
|
|
|
func GetToday(format string) string {
|
|
|
today := time.Now().Format(format)
|
|
|
return today
|
|
@@ -505,39 +486,6 @@ func Sha1(data string) string {
|
|
|
return hex.EncodeToString(sha1.Sum([]byte("")))
|
|
|
}
|
|
|
|
|
|
-func GetVideoPlaySeconds(videoPath string) (playSeconds float64, err error) {
|
|
|
- cmd := `ffmpeg -i ` + videoPath + ` 2>&1 | grep 'Duration' | cut -d ' ' -f 4 | sed s/,//`
|
|
|
- out, err := exec.Command("bash", "-c", cmd).Output()
|
|
|
- if err != nil {
|
|
|
- return
|
|
|
- }
|
|
|
- outTimes := string(out)
|
|
|
- fmt.Println("outTimes:", outTimes)
|
|
|
- if outTimes != "" {
|
|
|
- timeArr := strings.Split(outTimes, ":")
|
|
|
- h := timeArr[0]
|
|
|
- m := timeArr[1]
|
|
|
- s := timeArr[2]
|
|
|
- hInt, err := strconv.Atoi(h)
|
|
|
- if err != nil {
|
|
|
- return playSeconds, err
|
|
|
- }
|
|
|
-
|
|
|
- mInt, err := strconv.Atoi(m)
|
|
|
- if err != nil {
|
|
|
- return playSeconds, err
|
|
|
- }
|
|
|
- s = strings.Trim(s, " ")
|
|
|
- s = strings.Trim(s, "\n")
|
|
|
- sInt, err := strconv.ParseFloat(s, 64)
|
|
|
- if err != nil {
|
|
|
- return playSeconds, err
|
|
|
- }
|
|
|
- playSeconds = float64(hInt)*3600 + float64(mInt)*60 + float64(sInt)
|
|
|
- }
|
|
|
- return
|
|
|
-}
|
|
|
-
|
|
|
func GetMaxTradeCode(tradeCode string) (maxTradeCode string, err error) {
|
|
|
tradeCode = strings.Replace(tradeCode, "W", "", -1)
|
|
|
tradeCode = strings.Trim(tradeCode, " ")
|