Skip to content

Commit

Permalink
Improve cookie失效时进入不登陆模式 (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
qydysky authored Feb 19, 2025
1 parent 1720439 commit 83885fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
37 changes: 27 additions & 10 deletions F/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ var (
`Cookie`: { //Cookie
(*GetFunc).Get_cookie,
},
`Uid`: { //用戶uid
(*GetFunc).GetUid,
},
// `Uid`: { //用戶uid
// (*GetFunc).GetUid,
// },
`UpUid`: { //主播uid
(*GetFunc).getRoomBaseInfo,
(*GetFunc).getInfoByRoom,
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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`)
}
Expand Down Expand Up @@ -940,16 +940,28 @@ 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
}
}
}
}

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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions bili_danmu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
//每日签到
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 83885fe

Please sign in to comment.