fix: accept numeric login identifiers

This commit is contained in:
2026-07-19 20:43:49 +08:00
parent 4755655859
commit 9dcdf9a227
2 changed files with 39 additions and 12 deletions
+23 -12
View File
@@ -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: "登录回调认证信息不完整"}
}
+16
View File
@@ -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)