Documentation ¶
Overview ¶
Package live
bilibili 开放平台 cmd 协议 see https://open-live.bilibili.com/document/f9ce25be-312e-1f4a-85fd-fef21f1637f8
Index ¶
- Constants
- Variables
- func AutomaticParsingMessageCommand(payload []byte) (string, interface{}, error)
- func HmacSHA256(key string, data string) string
- func Md5(str string) (md5str string)
- func ToSortedString(payloadMap map[string]string) string
- type AnchorInfo
- type AppBatchHeartbeatRequest
- type AppBatchHeartbeatResponse
- type AppEndRequest
- type AppHeartbeatRequest
- type AppStartRequest
- type AppStartResponse
- type BaseResp
- type Client
- func (c *Client) AppBatchHeartbeat(gameIDs []string) (*AppBatchHeartbeatResponse, error)
- func (c *Client) AppEnd(gameID string) error
- func (c *Client) AppHeartbeat(gameID string) error
- func (c *Client) AppStart(code string) (*AppStartResponse, error)
- func (c *Client) DoRequest(reqJSON, reqPath, nonce string) (*BaseResp, error)
- func (c *Client) StartWebsocket(startResp *AppStartResponse, dispatcherHandleMap map[uint32]DispatcherHandle, ...) (*WsClient, error)
- func (c *Client) VerifyH5RequestSignature(req *http.Request) bool
- func (c *Client) VerifyH5RequestSignatureWithParams(h5sp *H5SignatureParams) bool
- type CmdLiveOpenPlatformDanmuData
- type CmdLiveOpenPlatformGuardData
- type CmdLiveOpenPlatformLikeData
- type CmdLiveOpenPlatformSendGiftData
- type CmdLiveOpenPlatformSuperChatData
- type CmdLiveOpenPlatformSuperChatDelData
- type CommonHeader
- type Config
- type DispatcherHandle
- type GameInfo
- type H5SignatureParams
- type WebSocketInfo
- type WsClient
- type WsClientCloseCallback
Constants ¶
const ( // CloseAuthFailed 鉴权失败 CloseAuthFailed = basic.CloseAuthFailed // CloseActively 调用者主动关闭 CloseActively = basic.CloseActively // CloseReadingConnError 读取链接错误 CloseReadingConnError = basic.CloseReadingConnError // CloseReceivedShutdownMessage 收到关闭消息 CloseReceivedShutdownMessage = basic.CloseReceivedShutdownMessage // CloseTypeUnknown 未知原因 CloseTypeUnknown = basic.CloseTypeUnknown )
const ( CmdLiveOpenPlatformDanmu = proto.CmdLiveOpenPlatformDanmu // 弹幕 CmdLiveOpenPlatformSendGift = proto.CmdLiveOpenPlatformSendGift // 礼物 CmdLiveOpenPlatformSuperChat = proto.CmdLiveOpenPlatformSuperChat // SC CmdLiveOpenPlatformSuperChatDel = proto.CmdLiveOpenPlatformSuperChatDel // SC删除 CmdLiveOpenPlatformGuard = proto.CmdLiveOpenPlatformGuard // 付费大航海 CmdLiveOpenPlatformLike = proto.CmdLiveOpenPlatformLike // 点赞 )
const ( H5QueryTimestamp = "Timestamp" H5QueryCode = "Code" H5QueryMid = "Mid" H5QueryCaller = "Caller" H5QueryCodeSign = "CodeSign" H5QueryRoomID = "RoomId" H5QueryPlugEnv = "plug_env" )
const ( AcceptHeader = "Accept" ContentTypeHeader = "Content-Type" AuthorizationHeader = "Authorization" JsonType = "application/json" BiliVersion = "1.0" HmacSha256 = "HMAC-SHA256" BiliTimestampHeader = "x-bili-timestamp" BiliSignatureMethodHeader = "x-bili-signature-method" BiliSignatureNonceHeader = "x-bili-signature-nonce" BiliAccessKeyIdHeader = "x-bili-accesskeyid" BiliSignVersionHeader = "x-bili-signature-version" BiliContentMD5Header = "x-bili-content-md5" )
const (
HostProdLiveOpen = "https://live-open.biliapi.com" // 开放平台 (线上环境)
)
Variables ¶
var ( // BilibiliRequestFailed 发生在http请求失败 BilibiliRequestFailed = errors.BilibiliRequestFailed // BilibiliResponseNotSuccess 发生在http请求成功,但响应不是success BilibiliResponseNotSuccess = errors.BilibiliResponseNotSuccess // BilibiliWebsocketAuthFailed 发生在websocket连接建立后,发送auth请求后,收到的响应不是success BilibiliWebsocketAuthFailed = errors.BilibiliWebsocketAuthFailed )
Functions ¶
func AutomaticParsingMessageCommand ¶
AutomaticParsingMessageCommand 自动解析消息命令 如果是已知的命令,data 会被解析成对应的结构体,否则 data 会被解析成 map[string]interface{} Deprecated: use proto.AutomaticParsingMessageCommand instead
func HmacSHA256 ¶
func ToSortedString ¶
Types ¶
type AnchorInfo ¶
type AppBatchHeartbeatRequest ¶
type AppBatchHeartbeatRequest struct {
GameIDs []string `json:"game_ids"`
}
type AppBatchHeartbeatResponse ¶
type AppBatchHeartbeatResponse struct {
FailedGameIds []string `json:"failed_game_ids"` // 失败的场次id
}
type AppEndRequest ¶
type AppHeartbeatRequest ¶
type AppHeartbeatRequest struct {
GameID string `json:"game_id"`
}
type AppStartRequest ¶
type AppStartResponse ¶
type AppStartResponse struct { // 主播信息 AnchorInfo AnchorInfo `json:"anchor_info"` // 场次信息 GameInfo GameInfo `json:"game_info"` // 长连信息 WebsocketInfo WebSocketInfo `json:"websocket_info"` }
func (*AppStartResponse) GetAuthBody ¶ added in v0.2.1
func (as *AppStartResponse) GetAuthBody() []byte
func (*AppStartResponse) GetLinks ¶ added in v0.2.1
func (as *AppStartResponse) GetLinks() []string
type BaseResp ¶
type BaseResp struct { Code int64 `json:"code"` Message string `json:"message"` RequestID string `json:"request_id"` Data json.RawMessage `json:"data"` }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AppBatchHeartbeat ¶
func (c *Client) AppBatchHeartbeat(gameIDs []string) (*AppBatchHeartbeatResponse, error)
AppBatchHeartbeat 批量心跳
func (*Client) AppStart ¶
func (c *Client) AppStart(code string) (*AppStartResponse, error)
AppStart 启动app
func (*Client) StartWebsocket ¶
func (c *Client) StartWebsocket(startResp *AppStartResponse, dispatcherHandleMap map[uint32]DispatcherHandle, onCloseFunc WsClientCloseCallback) (*WsClient, error)
StartWebsocket 启动websocket Deprecated: use basic.StartWebsocket instead 此方法会一键完成鉴权,心跳,消息分发 由于2024年B站决定在开发者平台启用直播间长链功能,所以重新设计了WsClient,并且将其移动到basic包中 这里仅作为兼容性处理,后续版本会废弃
func (*Client) VerifyH5RequestSignature ¶
VerifyH5RequestSignature 验证h5请求签名
func (*Client) VerifyH5RequestSignatureWithParams ¶
func (c *Client) VerifyH5RequestSignatureWithParams(h5sp *H5SignatureParams) bool
VerifyH5RequestSignatureWithParams 验证h5请求签名
type CmdLiveOpenPlatformDanmuData ¶
type CmdLiveOpenPlatformDanmuData proto.CmdDanmuData
type CmdLiveOpenPlatformGuardData ¶
type CmdLiveOpenPlatformGuardData proto.CmdGuardData
type CmdLiveOpenPlatformLikeData ¶
type CmdLiveOpenPlatformLikeData proto.CmdLikeData
type CmdLiveOpenPlatformSendGiftData ¶
type CmdLiveOpenPlatformSendGiftData proto.CmdSendGiftData
type CmdLiveOpenPlatformSuperChatData ¶
type CmdLiveOpenPlatformSuperChatData proto.CmdSuperChatData
type CmdLiveOpenPlatformSuperChatDelData ¶
type CmdLiveOpenPlatformSuperChatDelData proto.CmdSuperChatDelData
type CommonHeader ¶
type CommonHeader struct { ContentType string ContentAcceptType string Timestamp string SignatureMethod string SignatureVersion string Authorization string Nonce string AccessKeyID string ContentMD5 string }
func (*CommonHeader) CreateSignature ¶
func (h *CommonHeader) CreateSignature(accessKeySecret string) string
CreateSignature 生成签名
func (*CommonHeader) ToMap ¶
func (h *CommonHeader) ToMap() map[string]string
ToMap 所有字段转map<string, string>
func (*CommonHeader) ToSortMap ¶
func (h *CommonHeader) ToSortMap() map[string]string
ToSortMap 参与签名的字段转map<string, string>
type Config ¶
type DispatcherHandle ¶
type H5SignatureParams ¶
type H5SignatureParams struct { Timestamp string // 时间戳 Code string // 身份码 Mid string // 用户id Caller string // 调用方 CodeSign string // 签名 RoomID string // 直播间ID 调用页会携带 // 场景参数 调用页会携带 // plug_env=1显示设置项区域的场景,如插件详情页、直播姬内插件配置弹窗;plug_env=0插件实际使用的场景,如插件详情页复制链接、直播姬内使用载入的链接。 // see https://open-live.bilibili.com/document/ad4901b8-c13e-7a20-e07e-410ad182564a PlugEnv string }
func ParseH5SignatureParamsWithRequest ¶
func ParseH5SignatureParamsWithRequest(req *http.Request) *H5SignatureParams
ParseH5SignatureParamsWithRequest 从http.Request中解析出签名参数
func (H5SignatureParams) CreateSignature ¶
func (h5sp H5SignatureParams) CreateSignature(accessKeySecret string) string
CreateSignature 生成签名
func (H5SignatureParams) ToSortMap ¶
func (h5sp H5SignatureParams) ToSortMap() map[string]string
ToSortMap 参与签名的字段转map<string, string>
func (H5SignatureParams) ValidateSignature ¶
func (h5sp H5SignatureParams) ValidateSignature(accessKeySecret string) bool
ValidateSignature 验证签名
type WebSocketInfo ¶
type WsClient ¶
func NewWsClient ¶
func NewWsClient(startResp *AppStartResponse, dispatcherHandleMap map[uint32]DispatcherHandle, logger *slog.Logger) *WsClient
NewWsClient 创建一个新的WsClient Deprecated: use basic.NewWsClient instead 由于2024年B站决定在开发者平台启用直播间长链功能,所以重新设计了WsClient,并且将其移动到basic包中 请使用 basic.NewWsClient 替代 这里仅作为兼容性处理,后续版本会废弃
func (*WsClient) WithOnClose ¶
func (wsClient *WsClient) WithOnClose(onClose WsClientCloseCallback) *WsClient
type WsClientCloseCallback ¶ added in v0.1.3
type WsClientCloseCallback func(wsClient *WsClient, startResp *AppStartResponse, closeType int)