-
Notifications
You must be signed in to change notification settings - Fork 209
弹幕协议
METO edited this page May 6, 2018
·
1 revision
弹幕接口地址可以通过 https://api.live.bilibili.com/api/player?id=cid:23058&platform=pc&player_type=web
进行获取
...
<dm_ws_port>2244</dm_ws_port>
<dm_wss_port>2245</dm_wss_port>
<dm_port>2243</dm_port>
<dm_server>broadcastlv.chat.bilibili.com</dm_server>
<dm_server_list>119.23.41.85,118.89.14.115,broadcastlv.chat.bilibili.com</dm_server_list>
...
主要有三种接口,经过测试,三种接口协议上都类似
+-------------+-----------------------------------------+------------------+
| | PACKAGE | |
| HEADLEN +-------+-------+------------+------------+ DATA |
| | LEN | VER | OPTION | SEQUENCE | |
+-------------+-------+-------+------------+------------+------------------+
| 4 | 2 | 2 | 4 | 4 | HEADLEN - 16 |
+-------------+-------+-------+------------+------------+------------------+
name | description | value |
---|---|---|
HEADLEN | 数据包总长度 | int |
LEN | 协议包长度 | 0x10 |
VER | 协议包版本 | 0x01 |
OPTION | 行为 | int |
SEQUENCE | 协议包序号(可能没用) | 0x0001 |
DATA | 数据包内容 | string |
name | value | description |
---|---|---|
WS_OP_HEARTBEAT | 2 | 发送心跳包 |
WS_OP_HEARTBEAT_REPLY | 3 | 心跳包回复 |
WS_OP_MESSAGE | 5 | 弹幕信息 |
WS_OP_USER_AUTHENTICATION | 7 | 初始握手 |
WS_OP_CONNECT_SUCCESS | 8 | 握手成功 |
0000 00 00 00 5a 00 10 00 01 00 00 00 07 00 00 00 01 ...Z.... ........
0010 7b 22 75 69 64 22 3a 30 2c 22 72 6f 6f 6d 69 64 {"uid":0 ,"roomid
0020 22 3a 32 33 30 35 38 2c 22 70 72 6f 74 6f 76 65 ":23058, "protove
0030 72 22 3a 31 2c 22 70 6c 61 74 66 6f 72 6d 22 3a r":1,"pl atform":
0040 22 77 65 62 22 2c 22 63 6c 69 65 6e 74 76 65 72 "web","c lientver
0050 22 3a 22 31 2e 33 2e 33 22 7d ":"1.3.3 "}
DATA 部分为一个 Json 字符串
{
"uid" : 0, // 用户 id,游客为 0
"roomid" : 23058, // 直播间号
"platform" : "web",
"protover" : 1,
"clientver" : "1.3.3"
}
握手成功后会返回成功信息 WS_OP_CONNECT_SUCCESS
0000 00 00 00 10 00 10 00 01 00 00 00 08 00 00 00 01 ........ ........
0000 00 00 00 10 00 10 00 01 00 00 00 02 00 00 00 01 ........ ........
发送心跳后会接受到一个心跳回复,其中 DATA 部分为人数信息 0x25e1 = 9697
,现在应该叫做人气值
0000 00 00 00 14 00 10 00 01 00 00 00 03 00 00 00 01 ........ ........
0010 00 00 25 e1 ..%?