mirror of
https://github.com/SocialSisterYi/bilibili-API-collect.git
synced 2024-12-29 14:00:09 +08:00
167 lines
4.3 KiB
Markdown
167 lines
4.3 KiB
Markdown
# 直播间信息流
|
||
|
||
## 数据包格式
|
||
|
||
数据包为websocket,格式为头部数据+正文数据
|
||
|
||
操作流程:
|
||
|
||
发送认证包->接收认证包回应->接收普通包&(每30秒发送心跳包->接收心跳回应)
|
||
|
||
头部格式:
|
||
|
||
| 偏移量 | 长度 | 类型 | 含义 |
|
||
| ------ | ---- | ------ | ------------------------------------------------------------ |
|
||
| 0 | 4 | uint32 | 封包总大小(头部大小+正文大小) |
|
||
| 4 | 2 | uint16 | 头部大小(一般为0x0010,16字节) |
|
||
| 6 | 2 | uint16 | 协议版本:<br />0普通包正文不使用压缩 <br />1心跳及认证包正文不使用压缩<br />2普通包正文使用zlib压缩 |
|
||
| 8 | 4 | uint32 | 操作码(封包类型) |
|
||
| 12 | 4 | uint32 | sequence,可以取常数1 |
|
||
|
||
操作码:
|
||
|
||
| 代码 | 含义 |
|
||
| ---- | -------------------- |
|
||
| 2 | 心跳包 |
|
||
| 3 | 心跳包回复(人气值) |
|
||
| 5 | 普通包(命令) |
|
||
| 7 | 认证包 |
|
||
| 8 | 认证包回复 |
|
||
|
||
### 认证包
|
||
|
||
方式:(上行)
|
||
|
||
连接成功后5秒内发送,否则强制断开连接
|
||
|
||
正文:
|
||
|
||
json格式
|
||
|
||
| 字段 | 类型 | 内容 | 备注 |
|
||
| --------- | ---- | ------------ | -------------- |
|
||
| uid | num | 用户UID | 不可为0 |
|
||
| roomid | num | 加入房间的ID | |
|
||
| protover | num | 协议版本 | 现在是2 |
|
||
| platform | str | 平台标识 | 可为"web" |
|
||
| clientver | str | 客户端版本 | 现在是"1.10.3" |
|
||
| type | num | 必须为2 | |
|
||
| key | str | 认证秘钥 | |
|
||
|
||
示例:
|
||
|
||
```
|
||
00000000 00 00 00 f0 00 10 00 01 00 00 00 07 00 00 00 01 |................|
|
||
00000010 7b 22 75 69 64 22 3a 32 39 33 37 39 33 34 33 35 |{"uid":293793435|
|
||
00000020 2c 22 72 6f 6f 6d 69 64 22 3a 32 31 36 38 36 32 |,"roomid":216862|
|
||
00000030 33 37 2c 22 70 72 6f 74 6f 76 65 72 22 3a 32 2c |37,"protover":2,|
|
||
00000040 22 70 6c 61 74 66 6f 72 6d 22 3a 22 77 65 62 22 |"platform":"web"|
|
||
00000050 2c 22 63 6c 69 65 6e 74 76 65 72 22 3a 22 31 2e |,"clientver":"1.|
|
||
00000060 31 30 2e 33 22 2c 22 74 79 70 65 22 3a 32 2c 22 |10.3","type":2,"|
|
||
00000070 6b 65 79 22 3a 22 43 6f 4b 68 5f 61 49 46 42 6c |key":"CoKh_aIFBl|
|
||
00000080 51 32 4c 57 77 64 79 4e 43 6b 2d 69 5f 42 76 72 |Q2LWwdyNCk-i_Bvr|
|
||
00000090 64 72 72 55 4d 32 78 57 6c 74 62 35 77 6b 54 50 |drrUM2xWltb5wkTP|
|
||
000000a0 4e 72 44 55 49 2d 73 46 32 41 56 56 4f 44 78 43 |NrDUI-sF2AVVODxC|
|
||
000000b0 52 42 39 69 64 76 74 34 46 32 4d 50 31 45 4a 6c |RB9idvt4F2MP1EJl|
|
||
000000c0 4d 68 49 57 6b 31 5a 69 73 67 6e 32 67 67 66 6c |MhIWk1Zisgn2ggfl|
|
||
000000d0 68 72 65 6e 4f 4b 65 39 7a 56 65 6d 78 35 7a 5f |hrenOKe9zVemx5z_|
|
||
000000e0 5a 4d 43 61 55 77 4c 31 65 70 6d 7a 5a 53 22 7d |ZMCaUwL1epmzZS"}|
|
||
```
|
||
|
||
|
||
|
||
### 认证包回复
|
||
|
||
方式:(下行)
|
||
|
||
在认证包发送成功后就会收到
|
||
|
||
json格式
|
||
|
||
| 字段 | 类型 | 内容 | 备注 |
|
||
| ---- | ---- | ------ | --------- |
|
||
| code | num | 返回值 | 0认证成功 |
|
||
|
||
示例:
|
||
|
||
```
|
||
00000000 00 00 00 1a 00 10 00 01 00 00 00 08 00 00 00 01 |................|
|
||
00000010 7b 22 63 6f 64 65 22 3a 30 7d |{"code":0}|
|
||
```
|
||
|
||
|
||
|
||
### 心跳包
|
||
|
||
方式:(上行)
|
||
|
||
30秒左右发送一次,否则60秒后会被强制断开连接
|
||
|
||
正文:
|
||
|
||
特定字符
|
||
|
||
[object Object]
|
||
|
||
示例:
|
||
|
||
```
|
||
00000000 00 00 00 1f 00 10 00 01 00 00 00 02 00 00 00 01 |................|
|
||
00000010 5b 6f 62 6a 65 63 74 20 4f 62 6a 65 63 74 5d |[object Object]|
|
||
```
|
||
|
||
### 心跳回应(人气值)
|
||
|
||
方式:(下行)
|
||
|
||
在心跳包发送成功后就会收到
|
||
|
||
正文:
|
||
|
||
uint32整数,代表房间当前的人气值
|
||
|
||
示例:
|
||
|
||
```
|
||
00000000 00 00 00 14 00 10 00 01 00 00 00 03 00 00 00 01 |................|
|
||
00000010 00 00 14 83 |....|
|
||
```
|
||
|
||
可见房间内人气值为5251人
|
||
|
||
### 普通包
|
||
|
||
方式:(下行)
|
||
|
||
#### 弹幕
|
||
|
||
|
||
|
||
#### 送礼
|
||
|
||
|
||
|
||
#### 欢迎加入房间
|
||
|
||
|
||
|
||
#### 欢迎房管加入房间
|
||
|
||
|
||
|
||
#### 系统消息
|
||
|
||
|
||
|
||
#### 主播准备中
|
||
|
||
|
||
|
||
#### 直播开始
|
||
|
||
|
||
|
||
#### 直播状态更新
|
||
|
||
|