Im.proto为主站WebSocket,主要负责私信、推送之类的。
此项目已切换至TCP连接方式,如需参考WebSocket连接方式,请查看2.2.3版本
起始位置,偏移量 | 结构 | 说明 |
---|---|---|
0, 12 | ABCD 0001 FFFF FFFF FFFF FFFF | ABCD 0001为Magic Number, 第一组FFFF FFFF为头数据长度,第二组FFFF FFFF为AES IV长度(固定为16)+ AES加密后的数据长度 |
12, 头数据长度 | PacketHeader | 具体数据结构请查看PacketHeader |
12 + 头数据长度, 16 | FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF | AES IV,加解密用 |
28 + 头数据长度, 具体数据长度 - 16 | AES加密的UpstreamPayload或DownstreamPayload | 密钥为SecurityKey或SessionKey(由PacketHeader中的encryptionMode 指定) |
前置流程
-
请求
https://live.acfun.cn
获取_did
Cookies(可用随机字符串如UUID替代) -
获取
userId
、acSecurity
和acfun.api.visitor_st
- 未登录/匿名用户发送
POST application/x-www-form-urlencoded请求
https://id.app.acfun.cn/rest/app/visitor/login
,表单数据为sid=acfun.api.visitor
- 已登录用户发送
POST application/x-www-form-urlencoded请求
https://id.app.acfun.cn/rest/web/token/get
,表单数据为sid=acfun.midground.api
- 未登录/匿名用户发送
POST application/x-www-form-urlencoded请求
-
获取
availableTickets
、liveId
和enterRoomAttach
发送POST application/x-www-form-urlencoded请求
https://api.kuaishouzt.com/rest/zt/live/web/startPlay?subBiz=mainApp&kpn=ACFUN_APP&kpf=PC_WEB&userId=[userId]&did=[_did]&acfun.api.visitor_st=[acfun.api.visitor_st/acfun.midground.api_st]
,表单数据为authorId=[主播Id]
其他请求
-
获取礼物列表
发送POST application/x-www-form-urlencoded请求
https://api.kuaishouzt.com/rest/zt/live/web/gift/list?subBiz=mainApp&kpn=ACFUN_APP&kpf=PC_WEB&userId=[userId]&did=[_did]&acfun.midground.api_st=[acfun.api.visitor_st/acfun.midground.api_st]
,表单数据为visitorId=[userId]&liveId=[liveId]
-
获取在线观众
发送POST application/x-www-form-urlencoded请求
https://api.kuaishouzt.com/rest/zt/live/web/watchingList?subBiz=mainApp&kpn=ACFUN_APP&kpf=PC_WEB&userId=[userId]&did=[_did]&acfun.midground.api_st=[acfun.api.visitor_st/acfun.midground.api_st]
,表单数据为visitorId=[userId]&liveId=[liveId]
- 建立连接
- WebSocket
[wss://klink-newproduct-ws1.kwaizt.com, wss://klink-newproduct-ws2.kwaizt.com, wss://klink-newproduct-ws3.kwaizt.com]
- TCP
slink.gifshow.com:14000
- WebSocket
- (仅限TCP连接)发送HandshakeRequest,接收HandshakeResponse
- 发送RegisterRequest(SeqId加1),
encryptionMode
为KEncryptionServiceToken
,加密密钥为acSecurity
- 接收DownStreamPayload,根据Command进行对应的处理
- Basic.Register
- 保存instanceId及sessKey,后续所有发送的
encryptionMode
为KEncryptionSessionKey
,加密密钥为sessKey
- 发送KeepAliveRequest
- SeqId + 1
- 发送EnterRoomRequest
- SeqId + 1
- 保存instanceId及sessKey,后续所有发送的
- Basic.Unregister
- 停止Heartbeat定时器
- 关闭WebSocket连接
- Basic.KeepAlive
目前无需处理,忽略即可 - Basic.Ping
目前无需处理,忽略即可 - Global.ZtLiveInteractive.CsCmd
根据CmdAckType进行对应的处理- ZtLiveCsEnterRoomAck
- 保存HeartbeatIntervalMs(目前默认10秒)
- 启动Heartbeat定时器
- 发送HeartbeatRequest
- SeqId + 1
- HeartbeatSeqId + 1
- 如果
HeartbeatSeqId % 5 == 4
,即启动Heartbeat定时器后每50秒,发送KeepAliveRequest,SeqId + 1
- ZtLiveCsHeartbeatAck
目前无需处理,忽略即可 - ZtLiveCsUserExitAck
目前无需处理,忽略即可
- ZtLiveCsEnterRoomAck
- Push.ZtLiveInteractive.Message
- 发送空的Push.ZtLiveInteractive.Message(发送的PacketHeader的SeqId为接收到的PacketHeader的SeqId)
- 根据CompressionType,决定是否需要Gzip解压缩
- 根据MessageType进行对应的处理
- ZtLiveScActionSignal
遍历Item,根据SignalType进行对应处理 - ZtLiveScStateSignal
遍历Item,根据SignalType进行对应的处理- AcfunStateSignalDisplayInfo
- CommonStateSignalDisplayInfo
- CommonStateSignalTopUsers
- CommonStateSignalRecentComment
- CommonStateSignalChatCall
- CommonStateSignalChatAccept
- CommonStateSignalChatReady
- CommonStateSignalChatEnd
- CommonStateSignalCurrentRedpackList
- CommonStateSignalAuthorChatCall
- CommonStateSignalAuthorChatAccept
- CommonStateSignalAuthorChatReady
- CommonStateSignalAuthorChatEnd
- CommonStateSignalAuthorChatChangeSoundConfig
- CommonStateSignalPKAccept
- CommonStateSignalPKInvitation
- CommonStateSignalPKReady
- CommonStateSignalPKSoundConfigChanged
- CommonStateSignalPkEnd
- CommonStateSignalPkStatistic
- CommonStateSignalWishSheetCurrentState
- ZtLiveScNotifySignal
遍历Item,根据SignalType进行对应的处理 - ZtLiveScStatusChanged
- 如果Type为LiveClosed或LiveBanned,发送UnregisterRequest
- 停止Heartbeat定时器
- 关闭WebSocket连接
- 如果Type为LiveClosed或LiveBanned,发送UnregisterRequest
- ZtLiveScTicketInvalid
- 选取之前获取的
availableTickets
中的下一个 - 发送EnterRoomRequest
- SeqId + 1
- 选取之前获取的
- ZtLiveScActionSignal
- Basic.Register
- 提交Issue
- 搜索QQ频道“AcFun开源⑨课”