From 68e0ee27f2955d39a85e73a683afa17bd2de754f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Fri, 1 Aug 2025 20:41:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0APP=5FID=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proto/conf.go | 16 ++++++++++++++++ service/toolService.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/proto/conf.go b/proto/conf.go index d05b414..3e728d0 100644 --- a/proto/conf.go +++ b/proto/conf.go @@ -5,6 +5,7 @@ import ( "fmt" "gorm.io/gorm" "log" + mrand "math/rand" "os" "sync" ) @@ -92,6 +93,7 @@ type ConfigStruct struct { USER_SYNC_TIME int `json:"user_sync_time"` // 用户数据同步时间,单位秒 SERVER_NAME string `json:"server_name"` // 服务器名称,用于区分不同服务器 MONITOR_SERVER_TOKEN string `json:"monitor_server_token"` // 监控服务器token,用于状态监控及邮件通知 + APP_ID string `json:"app_id"` // 应用ID,用于标识不同应用 } func WriteConfigToFile() { @@ -158,8 +160,22 @@ func ReadConfig(path string) error { } } SigningKey = []byte(Config.TOKEN_SECRET) + if Config.APP_ID == "" { + Config.APP_ID = GetRandomString(8) + log.Println("ReadConfig generated APP_ID:", Config.APP_ID) + go WriteConfigToFile() + } return err } +func GetRandomString(l int) string { + str := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + bytes := []byte(str) + var result []byte + for i := 0; i < l; i++ { + result = append(result, bytes[mrand.Intn(len(bytes))]) + } + return string(result) +} // 默认配置 func DefaultConfig() { diff --git a/service/toolService.go b/service/toolService.go index fc82c1f..3ef0332 100644 --- a/service/toolService.go +++ b/service/toolService.go @@ -280,7 +280,7 @@ func GetTokenSecretFromUserCenter() (*proto.SecretSyncSettings, error) { proto.SigningKeyRWLock.Lock() defer proto.SigningKeyRWLock.Unlock() req.SecretKeyMd5 = worker.GenerateMD5(string(proto.SigningKey)) - req.DeviceApp = "StuAcaWorksAI" + req.DeviceApp = proto.Config.APP_ID req.Timestamp = worker.GetCurrentTimestamp() req.Sign = worker.GenerateMD5(req.SecretKeyMd5 + req.DeviceApp + strconv.FormatInt(req.Timestamp, 10)) reqBytes, err2 := json.Marshal(req)