You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
744 B
40 lines
744 B
package utils
|
|
|
|
import (
|
|
"GoClouds/core/comms"
|
|
"fmt"
|
|
ruisUtil "github.com/mgr9525/go-ruisutil"
|
|
"math/rand"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
func ZHTNow() time.Time {
|
|
return time.Now().In(comms.TimeZHT)
|
|
}
|
|
|
|
func GenValidateCode(width int) string {
|
|
numeric := [10]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
|
|
r := len(numeric)
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
var sb strings.Builder
|
|
for i := 0; i < width; i++ {
|
|
fmt.Fprintf(&sb, "%d", numeric[rand.Intn(r)])
|
|
}
|
|
return sb.String()
|
|
}
|
|
func HideUserName(name string) string {
|
|
if comms.RegPhone.MatchString(name) {
|
|
return name[:3] + "****" + name[7:]
|
|
}
|
|
return name
|
|
}
|
|
func CacLoginHash(s string) string {
|
|
hash := ruisUtil.Md5String(s)
|
|
ln := len(hash)
|
|
if ln > 10 {
|
|
hash = hash[ln-8:]
|
|
}
|
|
return hash
|
|
}
|