From: qydysky Date: Sun, 20 Dec 2020 03:52:38 +0000 (+0800) Subject: ws cookie X-Git-Tag: v0.5.5~1^2~9 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=000d1667339ee17b0ca4e03d3d284ae41f629bdd;p=bili_danmu%2F.git ws cookie --- diff --git a/bili_danmu.go b/bili_danmu.go index dbded07..2335b47 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -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()//高能榜显示的是在线观众的打赏 diff --git a/demo/config/config_tts.json b/demo/config/config_tts.json index 52b02c8..f64f12a 100644 --- a/demo/config/config_tts.json +++ b/demo/config/config_tts.json @@ -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 50bc63f..2f726ce 100644 --- 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