Fix login to Xiaomi account with captcha #1985

This commit is contained in:
Alex X
2026-01-11 16:46:23 +03:00
parent e960f90a97
commit eb39b80883
+17 -12
View File
@@ -78,12 +78,9 @@ func (c *Cloud) Login(username, password string) error {
} }
req := Request{ req := Request{
Method: "POST", Method: "POST",
URL: "https://account.xiaomi.com/pass/serviceLoginAuth2", URL: "https://account.xiaomi.com/pass/serviceLoginAuth2",
RawBody: form.Encode(), Body: form,
Headers: url.Values{
"Content-Type": {"application/x-www-form-urlencoded"},
},
RawCookies: cookies, RawCookies: cookies,
}.Encode() }.Encode()
@@ -105,7 +102,7 @@ func (c *Cloud) Login(username, password string) error {
return err return err
} }
// save auth for two step verification // save auth for two-step verification
c.auth = map[string]string{ c.auth = map[string]string{
"username": username, "username": username,
"password": password, "password": password,
@@ -265,11 +262,17 @@ func (c *Cloud) sendTicket() error {
cookies += "; ick=" + c.auth["ick"] cookies += "; ick=" + c.auth["ick"]
} }
form := url.Values{
"_json": {"true"},
"icode": {captCode},
"retry": {"0"},
}
req = Request{ req = Request{
Method: "POST", Method: "POST",
URL: "https://account.xiaomi.com/identity/auth/send" + name + "Ticket", URL: "https://account.xiaomi.com/identity/auth/send" + name + "Ticket",
Body: form,
RawCookies: cookies, RawCookies: cookies,
RawBody: `{"retry":0,"icode":"` + captCode + `","_json":"true"}`,
}.Encode() }.Encode()
res, err = c.client.Do(req) res, err = c.client.Do(req)
@@ -531,7 +534,7 @@ type Request struct {
Method string Method string
URL string URL string
RawParams string RawParams string
RawBody string Body url.Values
Headers url.Values Headers url.Values
RawCookies string RawCookies string
} }
@@ -542,8 +545,8 @@ func (r Request) Encode() *http.Request {
} }
var body io.Reader var body io.Reader
if r.RawBody != "" { if r.Body != nil {
body = strings.NewReader(r.RawBody) body = strings.NewReader(r.Body.Encode())
} }
req, err := http.NewRequest(r.Method, r.URL, body) req, err := http.NewRequest(r.Method, r.URL, body)
@@ -554,7 +557,9 @@ func (r Request) Encode() *http.Request {
if r.Headers != nil { if r.Headers != nil {
req.Header = http.Header(r.Headers) req.Header = http.Header(r.Headers)
} }
if r.Body != nil {
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
if r.RawCookies != "" { if r.RawCookies != "" {
req.Header.Set("Cookie", r.RawCookies) req.Header.Set("Cookie", r.RawCookies)
} }