diff --git a/auth.go b/auth.go index a3b3b2b..2e8a94c 100644 --- a/auth.go +++ b/auth.go @@ -238,15 +238,26 @@ type qrLoginData struct { } type longPollData struct { - Code int `json:"code"` - Desc string `json:"desc"` - Location string `json:"location"` - Psecurity string `json:"psecurity"` - Nonce string `json:"nonce"` - Ssecurity string `json:"ssecurity"` - PassToken string `json:"passToken"` - UserID string `json:"userId"` - CUserID string `json:"cUserId"` + Code int `json:"code"` + Desc string `json:"desc"` + Location string `json:"location"` + Psecurity string `json:"psecurity"` + Nonce stringOrNumber `json:"nonce"` + Ssecurity string `json:"ssecurity"` + PassToken string `json:"passToken"` + UserID stringOrNumber `json:"userId"` + CUserID stringOrNumber `json:"cUserId"` +} + +type stringOrNumber string + +func (value *stringOrNumber) UnmarshalJSON(payload []byte) error { + decoded, err := decodeStringOrNumber(payload) + if err != nil { + return err + } + *value = stringOrNumber(decoded) + return nil } func (client *Client) Login(ctx context.Context) (AuthData, error) { @@ -403,11 +414,11 @@ func (client *Client) completeQRLogin(ctx context.Context, loginData qrLoginData candidate.ServiceToken = "" serviceTokenReceived := updateAuthDataFromCookies(&candidate, httpClient, response.Request.URL) candidate.Psecurity = data.Psecurity - candidate.Nonce = data.Nonce + candidate.Nonce = string(data.Nonce) candidate.Ssecurity = data.Ssecurity candidate.PassToken = data.PassToken - candidate.UserID = data.UserID - candidate.CUserID = data.CUserID + candidate.UserID = string(data.UserID) + candidate.CUserID = string(data.CUserID) if !serviceTokenReceived || !candidate.complete() { return AuthData{}, &LoginError{Code: -1, Message: "登录回调认证信息不完整"} } diff --git a/auth_test.go b/auth_test.go index 9756a1d..f68b569 100644 --- a/auth_test.go +++ b/auth_test.go @@ -28,6 +28,22 @@ func TestParseServiceResponse(t *testing.T) { } } +func TestParseLongPollResponseAcceptsNumericIdentifiers(t *testing.T) { + var result longPollData + if err := parseServiceResponse([]byte(`&&&START&&&{"code":0,"nonce":1784441289426,"userId":123456789,"cUserId":987654321}`), &result); err != nil { + t.Fatal(err) + } + if result.Nonce != "1784441289426" { + t.Fatalf("nonce = %q, want 1784441289426", result.Nonce) + } + if result.UserID != "123456789" { + t.Fatalf("userId = %q, want 123456789", result.UserID) + } + if result.CUserID != "987654321" { + t.Fatalf("cUserId = %q, want 987654321", result.CUserID) + } +} + func TestSaveAuthDataUses0600AndStableFields(t *testing.T) { directory := t.TempDir() client, err := NewClient(directory)