Skip to content

Commit 22deb4d

Browse files
authored
fix(lanzou): auto handle acw_sc__v2 and down_ip=1 for all requests, improve secondary validation (#1394)
* Refactor upload and request handling in util.go 重构请求部分以避免偶现failed link: failed get link:的情况 Signed-off-by: HG-ha <[email protected]> * Format and clean up code in util.go Signed-off-by: HG-ha <[email protected]> * go fmt util.go --------- Signed-off-by: HG-ha <[email protected]>
1 parent da0c734 commit 22deb4d

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed

drivers/lanzou/util.go

Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,36 +95,66 @@ func (d *LanZou) _post(url string, callback base.ReqCallback, resp interface{},
9595
}
9696
}
9797

98+
// 修复点:所有请求都自动处理 acw_sc__v2 验证和 down_ip=1
9899
func (d *LanZou) request(url string, method string, callback base.ReqCallback, up bool) ([]byte, error) {
99100
var req *resty.Request
100-
if up {
101-
once.Do(func() {
102-
upClient = base.NewRestyClient().SetTimeout(120 * time.Second)
103-
})
104-
req = upClient.R()
105-
} else {
106-
req = base.RestyClient.R()
107-
}
101+
var vs string
102+
for retry := 0; retry < 3; retry++ {
103+
if up {
104+
once.Do(func() {
105+
upClient = base.NewRestyClient().SetTimeout(120 * time.Second)
106+
})
107+
req = upClient.R()
108+
} else {
109+
req = base.RestyClient.R()
110+
}
108111

109-
req.SetHeaders(map[string]string{
110-
"Referer": "https://pc.woozooo.com",
111-
"User-Agent": d.UserAgent,
112-
})
112+
req.SetHeaders(map[string]string{
113+
"Referer": "https://pc.woozooo.com",
114+
"User-Agent": d.UserAgent,
115+
})
113116

114-
if d.Cookie != "" {
115-
req.SetHeader("cookie", d.Cookie)
116-
}
117+
// 下载直链时需要加 down_ip=1
118+
if strings.Contains(url, "/file/") {
119+
cookie := d.Cookie
120+
if cookie != "" {
121+
cookie += "; "
122+
}
123+
cookie += "down_ip=1"
124+
if vs != "" {
125+
cookie += "; acw_sc__v2=" + vs
126+
}
127+
req.SetHeader("cookie", cookie)
128+
} else if d.Cookie != "" {
129+
cookie := d.Cookie
130+
if vs != "" {
131+
cookie += "; acw_sc__v2=" + vs
132+
}
133+
req.SetHeader("cookie", cookie)
134+
} else if vs != "" {
135+
req.SetHeader("cookie", "acw_sc__v2="+vs)
136+
}
117137

118-
if callback != nil {
119-
callback(req)
120-
}
138+
if callback != nil {
139+
callback(req)
140+
}
121141

122-
res, err := req.Execute(method, url)
123-
if err != nil {
124-
return nil, err
142+
res, err := req.Execute(method, url)
143+
if err != nil {
144+
return nil, err
145+
}
146+
bodyStr := res.String()
147+
log.Debugf("lanzou request: url=>%s ,stats=>%d ,body => %s\n", res.Request.URL, res.StatusCode(), bodyStr)
148+
if strings.Contains(bodyStr, "acw_sc__v2") {
149+
vs, err = CalcAcwScV2(bodyStr)
150+
if err != nil {
151+
return nil, err
152+
}
153+
continue
154+
}
155+
return res.Body(), err
125156
}
126-
log.Debugf("lanzou request: url=>%s ,stats=>%d ,body => %s\n", res.Request.URL, res.StatusCode(), res.String())
127-
return res.Body(), err
157+
return nil, errors.New("acw_sc__v2 validation error")
128158
}
129159

130160
func (d *LanZou) Login() ([]*http.Cookie, error) {
@@ -445,7 +475,7 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
445475
SetCookie(&http.Cookie{
446476
Name: "acw_sc__v2",
447477
Value: vs,
448-
}).Get(downloadUrl)
478+
}).SetHeader("cookie", "down_ip=1").Get(downloadUrl)
449479
if err != nil {
450480
return nil, err
451481
}
@@ -494,6 +524,7 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
494524
for i := 0; i < 3; i++ {
495525
data, err = d.post(fmt.Sprint(baseUrl, "/ajax.php"), func(req *resty.Request) {
496526
req.SetFormData(param)
527+
req.SetHeader("cookie", "down_ip=1")
497528
if vs != "" {
498529
req.SetCookie(&http.Cookie{
499530
Name: "acw_sc__v2",

0 commit comments

Comments
 (0)