add admin

This commit is contained in:
2026-08-07 15:40:17 +08:00
parent 10424d23d8
commit 56674a850e
28 changed files with 2066 additions and 569 deletions
+103
View File
@@ -75,3 +75,106 @@ func HmacSha256ToHex(key string, data string) string {
func HmacSha256ToBase64(key string, data string) string {
return base64.URLEncoding.EncodeToString(HmacSha256(key, data))
}
func EncryptPhone(phone string) (string, Error) {
// 提取各部分
prefix := phone[NumberZero:NumberThree] // 前三位
middle := phone[NumberThree:NumberSeven] // 中四位
suffix := phone[NumberSeven:NumberEleven] // 尾四位
newPhone := StringEmpty
username, cErr := Crypto{}.AESEncryptECB(prefix)
if cErr != nil {
return StringEmpty, cErr
}
newPhone = username
username, cErr = Crypto{}.AESEncryptECB(middle)
if cErr != nil {
return StringEmpty, cErr
}
newPhone += username
username, cErr = Crypto{}.AESEncryptECB(suffix)
if cErr != nil {
return StringEmpty, cErr
}
newPhone += username
return newPhone, nil
}
func DecryptPhone(phone string) (string, Error) {
// 提取各部分
prefix := phone[NumberZero:24] // 前三位
middle := phone[24:48] // 中四位
suffix := phone[48:72] // 尾四位
newPhone := StringEmpty
username, cErr := Crypto{}.AESDecryptECB(prefix)
if cErr != nil {
return StringEmpty, cErr
}
newPhone = username
username, cErr = Crypto{}.AESDecryptECB(middle)
if cErr != nil {
return StringEmpty, cErr
}
newPhone += username
username, cErr = Crypto{}.AESDecryptECB(suffix)
if cErr != nil {
return StringEmpty, cErr
}
newPhone += username
return newPhone, nil
}
func getSearchPhone(mobile string) string {
phone := StringEmpty
if len(mobile) == 11 {
prefix := mobile[NumberZero:3] // 前三位
username, cErr := Crypto{}.AESEncryptECB(prefix)
if cErr == nil {
phone = username
}
prefix = mobile[NumberThree:NumberSeven] // 中四位
username, cErr = Crypto{}.AESEncryptECB(prefix)
if cErr == nil {
phone += username
}
prefix = mobile[NumberSeven:NumberEleven] // 尾四位
username, cErr = Crypto{}.AESEncryptECB(prefix)
if cErr == nil {
phone += username
}
} else if len(mobile) > NumberTwo {
prefix := mobile[NumberZero:NumberThree] //前三位
if len(mobile) == NumberFour {
prefix = mobile[NumberZero:NumberFour] // 前四位
}
username, cErr := Crypto{}.AESEncryptECB(prefix)
if cErr == nil {
phone = username
}
if len(mobile) > NumberFour {
prefix = mobile[NumberThree:] // 中四位
username, cErr = Crypto{}.AESEncryptECB(prefix)
if cErr == nil {
phone += username
}
}
}
return phone
}
// GetRandstring 取得随机字符串:使用字符串拼接
func GetRandstring(length int) string {
if length < 1 {
return StringEmpty
}
char := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
charArr := strings.Split(char, StringEmpty)
charlen := len(charArr)
ran := rand.New(rand.NewSource(time.Now().Unix()))
var rchar string = StringEmpty
for i := 1; i <= length; i++ {
rchar = rchar + charArr[ran.Intn(charlen)]
}
return rchar
}