添加APP_ID生成
This commit is contained in:
parent
a9a9ecc3bd
commit
68e0ee27f2
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue