Skip to content

Commit 940b69f

Browse files
authored
fix(drivers/lanzou): handle acw_sc__v2 challenge in Login function (#2876)
The Login endpoint may return an acw_sc__v2 validation page when accessed, which previously caused login failures. This change adds the same retry logic and cookie handling already used in request() to automatically solve the challenge, ensuring login success even when the anti-bot mechanism is triggered.
1 parent f2f7ee4 commit 940b69f

1 file changed

Lines changed: 36 additions & 18 deletions

File tree

drivers/lanzou/util.go

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,25 +157,43 @@ func (d *LanZou) request(url string, method string, callback base.ReqCallback, u
157157
}
158158

159159
func (d *LanZou) Login() ([]*http.Cookie, error) {
160-
resp, err := base.NewRestyClient().SetRedirectPolicy(resty.NoRedirectPolicy()).
161-
R().SetFormData(map[string]string{
162-
"task": "3",
163-
"uid": d.Account,
164-
"pwd": d.Password,
165-
"setSessionId": "",
166-
"setSig": "",
167-
"setScene": "",
168-
"setTocen": "",
169-
"formhash": "",
170-
}).Post("https://up.woozooo.com/mlogin.php")
171-
if err != nil {
172-
return nil, err
173-
}
174-
if utils.Json.Get(resp.Body(), "zt").ToInt() != 1 {
175-
return nil, fmt.Errorf("login err: %s", resp.Body())
160+
var vs string
161+
for retry := 0; retry < 3; retry++ {
162+
req := base.NewRestyClient().SetRedirectPolicy(resty.NoRedirectPolicy()).R()
163+
164+
// 如果已计算出 acw_sc__v2,通过 cookie 携带
165+
if vs != "" {
166+
req.SetHeader("cookie", "acw_sc__v2="+vs)
167+
}
168+
169+
resp, err := req.SetFormData(map[string]string{
170+
"task": "3",
171+
"uid": d.Account,
172+
"pwd": d.Password,
173+
"setSessionId": "",
174+
"setSig": "",
175+
"setScene": "",
176+
"setTocen": "",
177+
"formhash": "",
178+
}).Post("https://up.woozooo.com/mlogin.php")
179+
if err != nil {
180+
return nil, err
181+
}
182+
bodyStr := resp.String()
183+
if strings.Contains(bodyStr, "acw_sc__v2") {
184+
vs, err = CalcAcwScV2(bodyStr)
185+
if err != nil {
186+
return nil, err
187+
}
188+
continue
189+
}
190+
if utils.Json.Get(resp.Body(), "zt").ToInt() != 1 {
191+
return nil, fmt.Errorf("login err: %s", resp.Body())
192+
}
193+
d.Cookie = CookieToString(resp.Cookies())
194+
return resp.Cookies(), nil
176195
}
177-
d.Cookie = CookieToString(resp.Cookies())
178-
return resp.Cookies(), nil
196+
return nil, errors.New("acw_sc__v2 validation error")
179197
}
180198

181199
/*

0 commit comments

Comments
 (0)