]> 127.0.0.1 Git - bili_danmu/.git/commitdiff
ws cookie
authorqydysky <qydysky@foxmail.com>
Sun, 20 Dec 2020 03:52:38 +0000 (11:52 +0800)
committerqydysky <qydysky@foxmail.com>
Sun, 20 Dec 2020 03:52:38 +0000 (11:52 +0800)
bili_danmu.go
demo/config/config_tts.json
ws.go

index dbded07bf95d558f206a68e2a753e988cf96cc3f..2335b47cab9043929667e7f776290932a8dfdc68 100644 (file)
@@ -89,6 +89,18 @@ func Demo(roomid ...int) {
 
                <-change_room_chan
 
+               //cookies
+               {
+                       var q = p.Filel{
+                               Write:false,
+                       }
+                       if p.Checkfile().IsExist("cookie.txt") {
+                               q.File = "cookie.txt"
+                       }
+                       f := p.File().FileWR(q)
+                       c.Cookie = f
+               }
+
                for !exit_sign {
                        //获取房间相关信息
                        api := F.New_api(c.Roomid).Get_host_Token().Get_live()
@@ -103,7 +115,9 @@ func Demo(roomid ...int) {
                        //对每个弹幕服务器尝试
                        for _, v := range api.Url {
                                //ws启动
-                               ws := New_ws(v).Handle()
+                               ws := New_ws(v,map[string][]string{
+                                       "Cookie":[]string{c.Cookie},
+                               }).Handle()
        
                                //SendChan 传入发送[]byte
                                //RecvChan 接收[]byte
@@ -122,19 +136,10 @@ func Demo(roomid ...int) {
                                                p.Sys().MTimeoutf(500)//500ms
                                                heartbeatmsg, heartinterval := F.Heartbeat()
                                                ws.Heartbeat(1000 * heartinterval, heartbeatmsg)
-                                               
-                                               //打招呼
-                                               var q = p.Filel{
-                                                       Write:false,
-                                               }
-                                               if p.Checkfile().IsExist("cookie.txt") {
-                                                       q.File = "cookie.txt"
-                                               }
-                                               f := p.File().FileWR(q)
+
                                                //传输变量,以便响应弹幕"弹幕机在么"
                                                c.Roomid = api.Roomid
                                                c.Live = api.Live
-                                               c.Cookie = f
                                                //获取过往营收 舰长数量
                                                // go api.Get_OnlineGoldRank()//高能榜显示的是在线观众的打赏
 
index 52b02c8e8eb8277c898a3e9b4884802fbf8aa415..f64f12a4cabf5452624627065f9db54eafa0fc00 100644 (file)
@@ -1,6 +1,6 @@
 {
-       "0buyguide":"感谢{D}",
-       "0gift":"感谢{D}",
-    "0superchat":"感谢{D}",
-    "0multi":"观众:{D}"
+    "0buyguide": "感谢{D}",
+    "0gift": "感谢{D}",
+    "0superchat": "感谢{D}",
+    "0multi": "观众:{D}"
 }
\ No newline at end of file
diff --git a/ws.go b/ws.go
index 50bc63f208731a2fb14804d0b2436c77d6eb4772..2f726cebc44a6d601a91d113eb0b40f04ca1efcf 100644 (file)
--- a/ws.go
+++ b/ws.go
@@ -16,15 +16,17 @@ type ws struct {
        RecvChan chan []byte
        TO int
        url string
+       Header map[string][]string
 }
 
-func New_ws(url string) (o *ws) {
+func New_ws(url string,Header map[string][]string) (o *ws) {
        l := p.Logf().New().Base(-1, "ws.go>新建").Level(c.LogLevel).T("New_ws")
        defer l.Block()
 
        l.T("ok")
        o = new(ws)
        o.url = url
+       o.Header = Header
        o.TO = 300 * 1000
        o.SendChan = make(chan []byte, 1e4)
        o.RecvChan = make(chan []byte, 1e4)
@@ -51,7 +53,7 @@ func (i *ws) Handle() (o *ws) {
                        o.Signal.Done()
                }()
 
-               c, _, err := websocket.DefaultDialer.Dial(o.url, nil)
+               c, _, err := websocket.DefaultDialer.Dial(o.url, o.Header)
                if err != nil {
                        l.E(err)
                        return