From 83885fe5784976eac7a2b45fd470edb194979513 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 19 Feb 2025 12:18:36 +0800 Subject: [PATCH] =?UTF-8?q?Improve=20cookie=E5=A4=B1=E6=95=88=E6=97=B6?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E4=B8=8D=E7=99=BB=E9=99=86=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=20(#170)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- F/api.go | 37 +++++++++++++++++++++++++++---------- bili_danmu.go | 10 +++++++--- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/F/api.go b/F/api.go index 9485a3077..d9b5826aa 100644 --- a/F/api.go +++ b/F/api.go @@ -50,9 +50,9 @@ var ( `Cookie`: { //Cookie (*GetFunc).Get_cookie, }, - `Uid`: { //用戶uid - (*GetFunc).GetUid, - }, + // `Uid`: { //用戶uid + // (*GetFunc).GetUid, + // }, `UpUid`: { //主播uid (*GetFunc).getRoomBaseInfo, (*GetFunc).getInfoByRoom, @@ -140,9 +140,9 @@ var ( } checkValid = map[string]func(*GetFunc) (valid bool){ - `Uid`: func(t *GetFunc) bool { //用戶uid - return t.Uid != 0 - }, + // `Uid`: func(t *GetFunc) bool { //用戶uid + // return t.Uid != 0 + // }, `UpUid`: func(t *GetFunc) bool { //主播uid return t.UpUid != 0 }, @@ -792,9 +792,9 @@ func Get_face_src(uid string) string { } func (t *GetFunc) getPopularAnchorRank() (missKey []string) { - if t.Uid == 0 { - missKey = append(missKey, `Uid`) - } + // if t.Uid == 0 { + // missKey = append(missKey, `Cookie`) + // } if t.UpUid == 0 { missKey = append(missKey, `UpUid`) } @@ -940,6 +940,13 @@ func (t *GetFunc) Get_cookie() (missKey []string) { if e, res := biliApi.GetNav(); e != nil { apilog.L(`E: `, e) } else if res.IsLogin { + // uid + if uid, ok := t.Cookie.LoadV(`DedeUserID`).(string); ok { //cookie中无DedeUserID + if uid, e := strconv.Atoi(uid); e == nil { + t.Uid = uid + } + } + apilog.L(`I: `, `已登录`) return } @@ -947,9 +954,14 @@ func (t *GetFunc) Get_cookie() (missKey []string) { } } + t.Uid = 0 + apilog.L(`I: `, `未登录`) + if v, ok := t.K_v.LoadV(`扫码登录`).(bool); !ok || !v { apilog.L(`W: `, `配置文件已禁止扫码登录,如需登录,修改配置文件"扫码登录"为true`) return + } else { + apilog.L(`I: `, `"扫码登录"为true,开始登录`) } //获取id @@ -989,7 +1001,7 @@ func (t *GetFunc) Get_cookie() (missKey []string) { if t.K_v.LoadV(`扫码登录自动打开标签页`).(bool) { _ = open.Run(`http://127.0.0.1:` + t.Stream_url.Port() + scanPath) } - apilog.L(`W: `, `或打开链接扫码登录:`+t.Stream_url.String()+scanPath) + apilog.L(`W: `, `扫描命令行二维码或打开链接扫码登录:`+t.Stream_url.String()+scanPath) } c := qrterminal.Config{ @@ -1042,6 +1054,11 @@ func (t *GetFunc) Get_cookie() (missKey []string) { apilog.L(`E: `, err) return } + if uid, ok := t.Cookie.LoadV(`DedeUserID`).(string); ok { //cookie中无DedeUserID + if uid, e := strconv.Atoi(uid); e == nil { + t.Uid = uid + } + } apilog.L(`I: `, `登录,并保存了cookie`) return } diff --git a/bili_danmu.go b/bili_danmu.go index 1a7791ba0..72d344c21 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -81,11 +81,11 @@ func Start() { //获取cookie F.Get(c.C).Get(`Cookie`) //获取LIVE_BUVID + //获取uid F.Get(c.C).Get(`LIVE_BUVID`) //命令行操作 切换房间 发送弹幕 go Cmd.Cmd() - //获取uid - F.Get(c.C).Get(`Uid`) + // F.Get(c.C).Get(`Uid`) //兑换硬币 F.Get(c.C).Silver_2_coin() //每日签到 @@ -205,7 +205,7 @@ func Start() { cancel1() cancel() } else { - fmt.Print("房间号: ", strconv.Itoa(c.C.Roomid), "\n") + danmulog.L(`T: `, "房间号: ", strconv.Itoa(c.C.Roomid)) } if exitSign { @@ -216,6 +216,10 @@ func Start() { //如果连接中断,则等待 F.KeepConnect() + //获取cookie,检查是否登陆失效 + F.Get(c.C).Get(`Cookie`) + //获取LIVE_BUVID + F.Get(c.C).Get(`LIVE_BUVID`) // 获取房间实际id c.C.Roomid = F.GetRoomRealId(c.C.Roomid)