diff --git a/internal/service/lingxian/app_provider.go b/internal/service/lingxian/app_provider.go index c9fc42d..89c6745 100644 --- a/internal/service/lingxian/app_provider.go +++ b/internal/service/lingxian/app_provider.go @@ -288,7 +288,7 @@ func launchUID(cfg runtimeConfig, user gameprovider.AuthUser) string { } func launchToken(cfg runtimeConfig, user gameprovider.AuthUser) string { - return defaultIfBlank(cfg.TestToken, user.Token) + return trimTokenPadding(defaultIfBlank(cfg.TestToken, user.Token)) } func launchRoomID(cfg runtimeConfig, req gameprovider.LaunchRequest) string { @@ -307,6 +307,10 @@ func launchLang(req gameprovider.LaunchRequest) string { return defaultLaunchLang } +func trimTokenPadding(token string) string { + return strings.TrimRight(strings.TrimSpace(token), "=") +} + func launchSign(cfg runtimeConfig, gameID, uid, token, roomID string) string { sum := md5.Sum([]byte(gameID + uid + token + roomID + strings.TrimSpace(cfg.AppKey))) return hex.EncodeToString(sum[:]) diff --git a/internal/service/lingxian/catalog_test.go b/internal/service/lingxian/catalog_test.go index bada20e..d2ce6c8 100644 --- a/internal/service/lingxian/catalog_test.go +++ b/internal/service/lingxian/catalog_test.go @@ -355,7 +355,7 @@ func TestAppProviderUsesHalfURLForHalfScreenGames(t *testing.T) { Active: true, AppKey: "test-key", TestUID: "test-uid", - TestToken: "test-token", + TestToken: "test-token==", TestRoomID: "test-room", CreateTime: now, UpdateTime: now, @@ -466,6 +466,9 @@ func TestAppProviderUsesHalfURLForHalfScreenGames(t *testing.T) { if got := query.Get("token"); got != "test-token" { t.Fatalf("query token = %q, want test-token", got) } + if got := query.Get("sign"); got != launchSign(runtimeConfig{AppKey: "test-key"}, "1", "test-uid", "test-token", "test-room") { + t.Fatalf("query sign = %q, want sign with trimmed token", got) + } if got := query.Get("lang"); got != defaultLaunchLang { t.Fatalf("query lang = %q, want %s", got, defaultLaunchLang) } @@ -478,6 +481,9 @@ func TestAppProviderUsesHalfURLForHalfScreenGames(t *testing.T) { if got := launch.LaunchConfig.(map[string]any)["roomid"]; got != "test-room" { t.Fatalf("launchConfig.roomid = %v, want test-room", got) } + if got := launch.LaunchConfig.(map[string]any)["token"]; got != "test-token" { + t.Fatalf("launchConfig.token = %v, want trimmed token", got) + } if got := launch.LaunchConfig.(map[string]any)["lang"]; got != defaultLaunchLang { t.Fatalf("launchConfig.lang = %v, want %s", got, defaultLaunchLang) }