🎨 优化app端文件上传接口

This commit is contained in:
2025-07-31 02:41:39 +08:00
parent 9c51f0cbe4
commit 82c6003b4a
6 changed files with 48 additions and 22 deletions

View File

@@ -21,3 +21,16 @@ func GenerateInviteCode(userID uint) string {
}
return code
}
func GenerateRandomString(length int) string {
rand.Seed(time.Now().UnixNano())
// 拼接用户ID和随机数
data := fmt.Sprintf("%d%d", 6, rand.Intn(1000000))
hash := md5.Sum([]byte(data))
code := ""
for i := 0; i < 12; i++ {
// 取哈希的前6位每位映射到字符集
code += string(charset[int(hash[i])%len(charset)])
}
return code
}