fix: normalize lingxian launch token

This commit is contained in:
hy001 2026-05-12 11:19:40 +08:00
parent ab8f711169
commit 47a7725b33
2 changed files with 12 additions and 2 deletions

View File

@ -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[:])

View File

@ -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)
}