@@ -10,6 +10,14 @@ import (
1010 "github.com/imroc/req/v3"
1111)
1212
13+ // min 辅助函数
14+ func min (a , b int ) int {
15+ if a < b {
16+ return a
17+ }
18+ return b
19+ }
20+
1321type BiliClient struct {
1422 Cookies string
1523 UID int64
@@ -469,18 +477,24 @@ func PollWebQRCodeStatus(oauthKey string) (*QRCodePollResponse, error) {
469477}
470478
471479// ExtractCookiesFromWebPollResponse 从Web端轮询响应中提取Cookie
472- func ExtractCookiesFromWebPollResponse (pollResp * QRCodePollResponse ) string {
480+ func ExtractCookiesFromWebPollResponse (pollResp * QRCodePollResponse , client * req. Client ) string {
473481 if pollResp == nil || pollResp .Data .Code != 0 {
482+ log .Printf ("[WEB_COOKIE] 登录未完成,跳过Cookie提取 - code=%d" , pollResp .Data .Code )
474483 return ""
475484 }
476485
477486 if pollResp .Data .URL == "" {
487+ log .Printf ("[WEB_COOKIE] 错误:URL为空" )
478488 return ""
479489 }
480490
491+ // Web端登录成功后,URL中包含Cookie参数
492+ log .Printf ("[WEB_COOKIE] 解析登录URL: %s" , pollResp .Data .URL [:min (100 , len (pollResp .Data .URL ))])
493+
481494 // 解析URL中的Cookie参数
482495 parts := strings .Split (pollResp .Data .URL , "?" )
483496 if len (parts ) < 2 {
497+ log .Printf ("[WEB_COOKIE] URL没有查询参数" )
484498 return ""
485499 }
486500
@@ -499,6 +513,8 @@ func ExtractCookiesFromWebPollResponse(pollResp *QRCodePollResponse) string {
499513 sid := params ["sid" ]
500514
501515 if dedeUserID == "" || sessdata == "" || biliJct == "" {
516+ log .Printf ("[WEB_COOKIE] 关键字段缺失 - DedeUserID: %v, SESSDATA: %v, bili_jct: %v" ,
517+ dedeUserID != "" , sessdata != "" , biliJct != "" )
502518 return ""
503519 }
504520
@@ -515,5 +531,9 @@ func ExtractCookiesFromWebPollResponse(pollResp *QRCodePollResponse) string {
515531 cookieStrs = append (cookieStrs , fmt .Sprintf ("sid=%s" , sid ))
516532 }
517533
518- return strings .Join (cookieStrs , "; " )
534+ result := strings .Join (cookieStrs , "; " )
535+ log .Printf ("[WEB_COOKIE] 提取成功 - DedeUserID: %s, SESSDATA长度: %d, bili_jct长度: %d" ,
536+ dedeUserID , len (sessdata ), len (biliJct ))
537+
538+ return result
519539}
0 commit comments