]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
Fix 无法切换粉丝牌
authorqydysky <qydysky@foxmail.com>
Thu, 2 May 2024 02:33:27 +0000 (02:33 +0000)
committerqydysky <qydysky@foxmail.com>
Thu, 2 May 2024 02:33:27 +0000 (02:33 +0000)
F/api.go
F/biliApiInterface.go
Reply/F.go
go.mod
go.sum

index 20cf0a542902921efbed6944aad79334b83b32fe..81159fe8f3c8928a602f8bc20fdfb58e4a8eb34d 100644 (file)
--- 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 {
index 1c7f9d4bc40e87759289de2ece40dc76e1431bd7..6189cf24a2a8c0a602cd3b9f67e9cd85df300b9a 100644 (file)
@@ -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)
 }
index 784a4a184dfacbf06c60ad543351bbcb9465b3db..232a9699cf685c8fa37592eb2d3115e22bcd86a1 100644 (file)
@@ -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 2bd78249f9e9b9d688b77c12275715b6cbd23310..57e9051cc0fb154a2524df9ec31085523ee6e097 100644 (file)
--- 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 dd5a82dafbb81d85bffcc09bec30830d284a4ac5..107c3676cf4701158acfe3162d68aa0dbbdb306f 100644 (file)
--- 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=