From ce71fbdcc39233548f8e95ac91f38d4d3bb54abd Mon Sep 17 00:00:00 2001 From: qydysky Date: Fri, 15 Dec 2023 19:51:55 +0800 Subject: [PATCH] =?utf8?q?Fix=20=20=E6=89=AB=E7=A0=81=E7=99=BB=E5=BD=95?= =?utf8?q?=E6=8E=A5=E5=8F=A3=E5=A4=B1=E6=95=88=20#92?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 58 ++++++++++++++++----------------------------- Json/qrcodeLogin.go | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 Json/qrcodeLogin.go diff --git a/F/api.go b/F/api.go index 92e6ee6..305af04 100644 --- a/F/api.go +++ b/F/api.go @@ -1312,7 +1312,7 @@ func (t *GetFunc) Get_cookie() (missKey []string) { r := t.ReqPool.Get() defer t.ReqPool.Put(r) if e := r.Reqf(reqf.Rval{ - Url: `https://passport.bilibili.com/qrcode/getLoginUrl`, + Url: `https://passport.bilibili.com/x/passport-login/web/qrcode/generate?source=main-fe-header`, Proxy: t.Proxy, Timeout: 10 * 1000, Retry: 2, @@ -1320,14 +1320,7 @@ func (t *GetFunc) Get_cookie() (missKey []string) { apilog.L(`E: `, e) return } - var res struct { - Code int `json:"code"` - Status bool `json:"status"` - Data struct { - Url string `json:"url"` - OauthKey string `json:"oauthKey"` - } `json:"data"` - } + var res J.QrcodeLogin if e := json.Unmarshal(r.Respon, &res); e != nil { apilog.L(`E: `, e) return @@ -1336,22 +1329,18 @@ func (t *GetFunc) Get_cookie() (missKey []string) { apilog.L(`E: `, `code != 0`) return } - if !res.Status { - apilog.L(`E: `, `status == false`) - return - } - if res.Data.Url == `` { - apilog.L(`E: `, `Data.Urls == ""`) + if res.Data.URL == `` { + apilog.L(`E: `, `Data.URL == ""`) return } else { - img_url = res.Data.Url + img_url = res.Data.URL } - if res.Data.OauthKey == `` { - apilog.L(`E: `, `Data.OauthKey == ""`) + if res.Data.QrcodeKey == `` { + apilog.L(`E: `, `Data.QrcodeKey == ""`) return } else { - oauth = res.Data.OauthKey + oauth = res.Data.QrcodeKey } } @@ -1387,7 +1376,7 @@ func (t *GetFunc) Get_cookie() (missKey []string) { BlackChar: ` `, WhiteChar: `OO`, }) - apilog.L(`W: `, `手机扫命令行二维码登录。如不登录,修改配置文件"扫码登录"为false`) + apilog.L(`I: `, `手机扫命令行二维码登录。如不登录,修改配置文件"扫码登录"为false`) time.Sleep(time.Second) } @@ -1405,7 +1394,7 @@ func (t *GetFunc) Get_cookie() (missKey []string) { r := t.ReqPool.Get() defer t.ReqPool.Put(r) - for { + for pollC := 10; pollC > 0; pollC-- { //3s刷新查看是否通过 time.Sleep(time.Duration(3) * time.Second) @@ -1415,12 +1404,9 @@ func (t *GetFunc) Get_cookie() (missKey []string) { } if e := r.Reqf(reqf.Rval{ - Url: `https://passport.bilibili.com/qrcode/getLoginInfo`, - PostStr: `oauthKey=` + oauth, + Url: `https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=` + oauth + `&source=main-fe-header`, Header: map[string]string{ - `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`, - `Referer`: `https://passport.bilibili.com/login`, - `Cookie`: reqf.Map_2_Cookies_String(Cookie), + `Cookie`: reqf.Map_2_Cookies_String(Cookie), }, Proxy: t.Proxy, Timeout: 10 * 1000, @@ -1430,28 +1416,24 @@ func (t *GetFunc) Get_cookie() (missKey []string) { return } - var res struct { - Status bool `josn:"status"` - Message string `json:"message"` - } + var res J.QrcodeLoginPoll if e := json.Unmarshal(r.Respon, &res); e != nil { apilog.L(`E: `, e.Error(), string(r.Respon)) } - if !res.Status { - if res.Message == `Can't Match oauthKey~` { - apilog.L(`W: `, `登录超时`) - return - } - } else { - apilog.L(`W: `, `登录,并保存了cookie`) + if res.Code != 0 { + apilog.L(`W: `, res.Message) + return + } else if res.Data.Code == 0 { + apilog.L(`I: `, `登录,并保存了cookie`) if e := save_cookie(r.Response.Cookies()); e != nil { apilog.L(`E: `, e) } - break + return } } + apilog.L(`W: `, `扫码超时`) } return } diff --git a/Json/qrcodeLogin.go b/Json/qrcodeLogin.go new file mode 100644 index 0000000..3819547 --- /dev/null +++ b/Json/qrcodeLogin.go @@ -0,0 +1,24 @@ +package part + +type QrcodeLogin struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data struct { + URL string `json:"url"` + QrcodeKey string `json:"qrcode_key"` + } `json:"data"` +} + +type QrcodeLoginPoll struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data struct { + URL string `json:"url"` + RefreshToken string `json:"refresh_token"` + Timestamp int `json:"timestamp"` + Code int `json:"code"` + Message string `json:"message"` + } `json:"data"` +} -- 2.39.2