Files
bl/modules/blazing/service/login.go
昔念 3298bad0f2 refactor(blazing): 重构登录模块并移除示例代码
- 重构了登录控制器和登录服务,使用了cool框架的控制器和服务结构
- 移除了注册相关代码和不必要的示例代码
- 更新了登录服务,关联了服务器列表模型
- 删除了与示例相关的模型和服务文件
2025-06-28 16:16:28 +08:00

66 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"context"
"encoding/binary"
"encoding/hex"
"fmt"
"math/rand"
"strings"
"time"
"github.com/gogf/gf/v2/os/gctx"
"github.com/google/uuid"
)
type LoginService struct {
*cool.Service
}
func NewLoginServiceService() *LoginService {
return &LoginService{
&cool.Service{
Model: model.NewServerList(),
},
}
}
func (s *LoginService) SaveSessionId(session string, userid string) error {
cool.CacheManager.Set(gctx.New(), strings.Trim(session, " "), userid, time.Hour*24)
// gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
t, err := cool.CacheManager.Contains(context.Background(), strings.Trim(session, " "))
fmt.Println("前端获取", session, t, err)
return nil
}
func (s *LoginService) GetSessionId(accountID uint) (string, string, error) {
t1, _ := uuid.NewV7()
tt := strings.Replace(t1.String(), "-", "", -1)
rand.NewSource(time.Now().UnixNano())
// 生成4个随机字节
bytes := make([]byte, 4)
for i := range bytes {
bytes[i] = byte(rand.Intn(256)) // 生成0-255之间的随机数
}
buf2 := make([]byte, 4) // 创建4字节的缓冲区
binary.BigEndian.PutUint32(buf2, uint32(accountID))
//fmt.Printf("小端序: %v (十六进制: %x)\n", buf2, buf2) // 输出: [252 255 255 255] (0xFCFFFFFF)
//fmt.Println(bytes, "随机字节")
ret := append(bytes, hex.EncodeToString([]byte(tt))...)
ret = append(ret, bytes...)
return string(ret), tt, nil
// /t1.
// 以上过程只需全局一次且应在生成ID之前完成。
}