实现 jwt、密码加密、casbin 的接入

This commit is contained in:
2025-05-27 15:46:25 +08:00
parent 81594a8972
commit 37b4055924
43 changed files with 618 additions and 325 deletions

32
utility/openid.go Normal file
View File

@ -0,0 +1,32 @@
package utility
import (
"fmt"
"math/rand"
"strings"
"time"
)
// GenerateUserID 根据传入的用户类型生成唯一的用户ID。
// 用户ID格式为<PREFIX>_<16位数字字符串>例如QQ_2025052712345678。
// 前缀由 userType 参数指定(例如 "qq"、"wx"),自动转换为大写。
// 数字部分由当前时间戳与随机数拼接而成,确保唯一性。
//
// 参数:
// - userType: 用户类型,如 "qq" 或 "wx"
//
// 返回值:
// - string: 格式为 <大写前缀>_<16位唯一数字> 的用户ID
func GenerateUserID(userType string) string {
prefix := strings.ToUpper(userType)
timestamp := fmt.Sprintf("%d", time.Now().UnixNano())
core := timestamp[:12]
rand.Seed(time.Now().UnixNano())
suffix := fmt.Sprintf("%04d", rand.Intn(10000))
idNum := core + suffix
return fmt.Sprintf("%s_%s", prefix, idNum)
}