From 663c08b3c3630d1b1e167c103e1c39b371479a46 Mon Sep 17 00:00:00 2001 From: qydysky Date: Thu, 2 May 2024 02:33:27 +0000 Subject: [PATCH] =?utf8?q?Fix=20=E6=97=A0=E6=B3=95=E5=88=87=E6=8D=A2?= =?utf8?q?=E7=B2=89=E4=B8=9D=E7=89=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- F/api.go | 57 ++++--------------------------------------- F/biliApiInterface.go | 4 ++- Reply/F.go | 6 ++--- go.mod | 2 +- go.sum | 4 +-- 5 files changed, 14 insertions(+), 59 deletions(-) diff --git a/F/api.go b/F/api.go index 20cf0a5..81159fe 100644 --- a/F/api.go +++ b/F/api.go @@ -986,7 +986,7 @@ func Get_cookie_by_msg() { // 牌子字段 // 获取牌子信息 -func Get_list_in_room() (array []struct { +func Get_list_in_room(RoomID, TargetID int) (array []struct { TargetID int IsLighted int MedalID int @@ -1004,7 +1004,7 @@ func Get_list_in_room() (array []struct { } //getHotRank - if err, res := biliApi.GetFansMedal(); err != nil { + if err, res := biliApi.GetFansMedal(RoomID, TargetID); err != nil { apilog.L(`E: `, err) } else { return res @@ -1077,7 +1077,7 @@ func (c *GetFunc) CheckSwitch_FansMedal() (missKey []string) { var medal_id int //将要使用的牌子id //检查是否有此直播间的牌子 { - medal_list := Get_list_in_room() + medal_list := Get_list_in_room(c.Roomid, c.UpUid) for _, v := range medal_list { if v.TargetID != c.UpUid { continue @@ -1091,57 +1091,10 @@ func (c *GetFunc) CheckSwitch_FansMedal() (missKey []string) { } } } - - var ( - post_url string - post_str string - ) - { //生成佩戴信息 - csrf, _ := c.Cookie.LoadV(`bili_jct`).(string) - if csrf == `` { - apilog.L(`E: `, "Cookie错误,无bili_jct=") - return - } - - post_str = `csrf_token=` + csrf + `&csrf=` + csrf - - if medal_id == 0 { //无牌,不佩戴牌子 - post_url = `https://api.live.bilibili.com/xlive/web-room/v1/fansMedal/take_off` - } else { - post_url = `https://api.live.bilibili.com/xlive/web-room/v1/fansMedal/wear` - post_str = `medal_id=` + strconv.Itoa(medal_id) + `&` + post_str - } - } { //切换牌子 - r := c.ReqPool.Get() - defer c.ReqPool.Put(r) - if e := r.Reqf(reqf.Rval{ - Url: post_url, - PostStr: post_str, - Header: map[string]string{ - `Cookie`: reqf.Map_2_Cookies_String(Cookie), - `Content-Type`: `application/x-www-form-urlencoded; charset=UTF-8`, - `Referer`: `https://passport.bilibili.com/login`, - }, - Proxy: c.Proxy, - Timeout: 10 * 1000, - Retry: 2, - }); e != nil { - apilog.L(`E: `, e) - return - } - - var res J.FansMedal - - if e := json.Unmarshal(r.Respon, &res); e != nil { - apilog.L(`E: `, e) - return - } else if res.Code != 0 { - apilog.L(`E: `, res.Message) - return - } + err := biliApi.SetFansMedal(medal_id) - if res.Message == "佩戴成功" { + if err == nil { if medal_id == 0 { apilog.L(`I: `, `已取下粉丝牌`) } else { diff --git a/F/biliApiInterface.go b/F/biliApiInterface.go index 1c7f9d4..6189cf2 100644 --- a/F/biliApiInterface.go +++ b/F/biliApiInterface.go @@ -12,6 +12,7 @@ type biliApiInter interface { SetReqPool(pool *pool.Buf[reqf.Req]) SetProxy(proxy string) SetCookies(cookies []*http.Cookie) + GetCookie(name string) (error, string) LoginQrCode() (err error, imgUrl string, QrcodeKey string) LoginQrPoll(QrcodeKey string) (err error, cookies []*http.Cookie) @@ -87,10 +88,11 @@ type biliApiInter interface { RoomID int TargetID int }) - GetFansMedal() (err error, res []struct { + GetFansMedal(RoomID, TargetID int) (err error, res []struct { TargetID int IsLighted int MedalID int RoomID int }) + SetFansMedal(medalId int) (err error) } diff --git a/Reply/F.go b/Reply/F.go index 784a4a1..232a969 100644 --- a/Reply/F.go +++ b/Reply/F.go @@ -1009,7 +1009,7 @@ func Keep_medal_light() { flog.L(`T: `, `开始`) defer flog.L(`I: `, `完成`) - medals := F.Get_list_in_room() + medals := F.Get_list_in_room(0, 0) if len(medals) == 0 { return } @@ -1025,7 +1025,7 @@ func Keep_medal_light() { } //重试,使用点赞 - medals = F.Get_list_in_room() + medals = F.Get_list_in_room(0, 0) if len(medals) == 0 { return } @@ -1044,7 +1044,7 @@ func Keep_medal_light() { } //重试,使用历史弹幕 - medals = F.Get_list_in_room() + medals = F.Get_list_in_room(0, 0) if len(medals) == 0 { return } diff --git a/go.mod b/go.mod index 2bd7824..57e9051 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( require ( github.com/google/uuid v1.6.0 - github.com/qydysky/biliApi v0.0.0-20240501142006-df911ba3ac1f + github.com/qydysky/biliApi v0.0.0-20240502022948-a1b9a41f2a81 golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f ) diff --git a/go.sum b/go.sum index dd5a82d..107c367 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdh github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/qydysky/biliApi v0.0.0-20240501142006-df911ba3ac1f h1:n9nyaPuPV2CBSjDk7oLOO3tjzFets9PnNEV31QKpBAo= -github.com/qydysky/biliApi v0.0.0-20240501142006-df911ba3ac1f/go.mod h1:nhubuLaNo2LIkgoCt++A5KNtra53ttGPXsahjaGXCl4= +github.com/qydysky/biliApi v0.0.0-20240502022948-a1b9a41f2a81 h1:ga/7RfO/YXO7Sim+YeMZ7ndJVomXBuyBfHRLBn9tqhs= +github.com/qydysky/biliApi v0.0.0-20240502022948-a1b9a41f2a81/go.mod h1:nhubuLaNo2LIkgoCt++A5KNtra53ttGPXsahjaGXCl4= github.com/qydysky/part v0.28.20240501130702 h1:0riRs+hY628Hd3ohvxAgDN9GL0GpqgPe/G/YIPn8JiQ= github.com/qydysky/part v0.28.20240501130702/go.mod h1:VMq3GnrK1/7zUufW3foG5oLAk9dw567JmuMyKPTGswc= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= -- 2.39.2