diff --git a/pkg/service/cast/tag.go b/pkg/service/cast/tag.go index 1a8f625..9156c93 100644 --- a/pkg/service/cast/tag.go +++ b/pkg/service/cast/tag.go @@ -10,6 +10,7 @@ import ( "fonchain-fiee/pkg/model/login" "fonchain-fiee/pkg/service" "fonchain-fiee/pkg/utils" + "math/rand" "path/filepath" "strings" "time" @@ -212,10 +213,22 @@ func GetValidProfileKey(ctx context.Context, platformIDs []uint32) (string, erro if len(profileKeys.Data) == 0 { return "", errors.New("当前没有有效的profileKey") } - if profileKeys.Data[0].ProfileKey != "" { - return profileKeys.Data[0].ProfileKey, nil + + // 过滤出所有非空的 profileKey + validProfileKeys := make([]string, 0) + for _, item := range profileKeys.Data { + if item.ProfileKey != "" { + validProfileKeys = append(validProfileKeys, item.ProfileKey) + } } - return "", errors.New("profileKey为空") + + if len(validProfileKeys) == 0 { + return "", errors.New("profileKey为空") + } + + // 从有效的 profileKey 中随机选择一个 + randIndex := rand.Intn(len(validProfileKeys)) + return validProfileKeys[randIndex], nil } // SaveTagsToDatabase 将标签保存到数据库