Skip to content

Commit cba1a16

Browse files
committed
fix
1 parent 447a743 commit cba1a16

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

server/internal/bili/client.go

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -453,23 +453,46 @@ func PollWebQRCodeStatus(oauthKey string) (*QRCodePollResponse, error) {
453453
return nil, fmt.Errorf("轮询状态失败: %w", err)
454454
}
455455

456+
// 打印原始响应用于调试
457+
rawBody := resp.String()
458+
log.Printf("[WEB_POLL_DEBUG] 原始响应: %s", rawBody)
459+
456460
if err := resp.UnmarshalJson(&pollResp); err != nil {
457461
return nil, fmt.Errorf("解析轮询响应失败: %w", err)
458462
}
459463

460-
// 处理状态码
464+
// 参考 gobup 项目的状态码处理逻辑:
465+
// status=true: 登录成功
466+
// data.code=-4: 未扫码
467+
// data.code=-5: 已扫码待确认
468+
// data.code=-2: 二维码已过期
469+
log.Printf("[WEB_POLL] 原始响应 - status: %v, data.code: %d, data.message: %s",
470+
pollResp.Status, pollResp.Data.Code, pollResp.Data.Message)
471+
472+
// 优先判断 status 字段
461473
if pollResp.Status {
474+
// 登录成功
462475
pollResp.Data.Code = 0
476+
log.Printf("[WEB_POLL] 登录成功 - url=%s", pollResp.Data.URL)
463477
} else {
464-
var rawData map[string]interface{}
465-
resp.Unmarshal(&rawData)
466-
if data, ok := rawData["data"].(map[string]interface{}); ok {
467-
if codeVal, ok := data["code"].(float64); ok {
468-
pollResp.Data.Code = int(codeVal)
469-
}
470-
}
471-
if pollResp.Data.Code == 0 {
478+
// 根据 data.code 字段判断状态
479+
switch pollResp.Data.Code {
480+
case -4:
481+
// 二维码未失效,等待扫码
482+
pollResp.Data.Code = 86101
483+
log.Printf("[WEB_POLL] 等待扫码")
484+
case -5:
485+
// 已扫码,等待确认
486+
pollResp.Data.Code = 86090
487+
log.Printf("[WEB_POLL] 已扫码,等待确认")
488+
case -2:
489+
// 二维码已失效
490+
pollResp.Data.Code = 86038
491+
log.Printf("[WEB_POLL] 二维码已过期")
492+
default:
493+
// 其他未知状态,默认为等待扫码
472494
pollResp.Data.Code = 86101
495+
log.Printf("[WEB_POLL] 未知状态 code=%d,默认等待扫码", pollResp.Data.Code)
473496
}
474497
}
475498

0 commit comments

Comments
 (0)