mirror of
https://github.com/AynaLivePlayer/blivedm-go.git
synced 2025-12-06 11:22:50 +08:00
fix #15
This commit is contained in:
132
api/info.go
132
api/info.go
@@ -1,7 +1,9 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@@ -53,9 +55,135 @@ type DanmuInfo struct {
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func GetDanmuInfo(roomID string) (*DanmuInfo, error) {
|
||||
// UserInfo
|
||||
// api https://api.bilibili.com/x/web-interface/nav
|
||||
type UserInfo struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
TTL int `json:"ttl"`
|
||||
Data struct {
|
||||
IsLogin bool `json:"isLogin"`
|
||||
EmailVerified int `json:"email_verified"`
|
||||
Face string `json:"face"`
|
||||
FaceNft int `json:"face_nft"`
|
||||
FaceNftType int `json:"face_nft_type"`
|
||||
LevelInfo struct {
|
||||
CurrentLevel int `json:"current_level"`
|
||||
CurrentMin int `json:"current_min"`
|
||||
CurrentExp int `json:"current_exp"`
|
||||
NextExp string `json:"next_exp"`
|
||||
} `json:"level_info"`
|
||||
Mid int `json:"mid"`
|
||||
MobileVerified int `json:"mobile_verified"`
|
||||
Money float64 `json:"money"`
|
||||
Moral int `json:"moral"`
|
||||
Official struct {
|
||||
Role int `json:"role"`
|
||||
Title string `json:"title"`
|
||||
Desc string `json:"desc"`
|
||||
Type int `json:"type"`
|
||||
} `json:"official"`
|
||||
OfficialVerify struct {
|
||||
Type int `json:"type"`
|
||||
Desc string `json:"desc"`
|
||||
} `json:"officialVerify"`
|
||||
Pendant struct {
|
||||
Pid int `json:"pid"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
Expire int `json:"expire"`
|
||||
ImageEnhance string `json:"image_enhance"`
|
||||
ImageEnhanceFrame string `json:"image_enhance_frame"`
|
||||
} `json:"pendant"`
|
||||
Scores int `json:"scores"`
|
||||
Uname string `json:"uname"`
|
||||
VipDueDate int64 `json:"vipDueDate"`
|
||||
VipStatus int `json:"vipStatus"`
|
||||
VipType int `json:"vipType"`
|
||||
VipPayType int `json:"vip_pay_type"`
|
||||
VipThemeType int `json:"vip_theme_type"`
|
||||
VipLabel struct {
|
||||
Path string `json:"path"`
|
||||
Text string `json:"text"`
|
||||
LabelTheme string `json:"label_theme"`
|
||||
TextColor string `json:"text_color"`
|
||||
BgStyle int `json:"bg_style"`
|
||||
BgColor string `json:"bg_color"`
|
||||
BorderColor string `json:"border_color"`
|
||||
UseImgLabel bool `json:"use_img_label"`
|
||||
ImgLabelURIHans string `json:"img_label_uri_hans"`
|
||||
ImgLabelURIHant string `json:"img_label_uri_hant"`
|
||||
ImgLabelURIHansStatic string `json:"img_label_uri_hans_static"`
|
||||
ImgLabelURIHantStatic string `json:"img_label_uri_hant_static"`
|
||||
} `json:"vip_label"`
|
||||
VipAvatarSubscript int `json:"vip_avatar_subscript"`
|
||||
VipNicknameColor string `json:"vip_nickname_color"`
|
||||
Vip struct {
|
||||
Type int `json:"type"`
|
||||
Status int `json:"status"`
|
||||
DueDate int64 `json:"due_date"`
|
||||
VipPayType int `json:"vip_pay_type"`
|
||||
ThemeType int `json:"theme_type"`
|
||||
Label struct {
|
||||
Path string `json:"path"`
|
||||
Text string `json:"text"`
|
||||
LabelTheme string `json:"label_theme"`
|
||||
TextColor string `json:"text_color"`
|
||||
BgStyle int `json:"bg_style"`
|
||||
BgColor string `json:"bg_color"`
|
||||
BorderColor string `json:"border_color"`
|
||||
UseImgLabel bool `json:"use_img_label"`
|
||||
ImgLabelURIHans string `json:"img_label_uri_hans"`
|
||||
ImgLabelURIHant string `json:"img_label_uri_hant"`
|
||||
ImgLabelURIHansStatic string `json:"img_label_uri_hans_static"`
|
||||
ImgLabelURIHantStatic string `json:"img_label_uri_hant_static"`
|
||||
} `json:"label"`
|
||||
AvatarSubscript int `json:"avatar_subscript"`
|
||||
NicknameColor string `json:"nickname_color"`
|
||||
Role int `json:"role"`
|
||||
AvatarSubscriptURL string `json:"avatar_subscript_url"`
|
||||
TvVipStatus int `json:"tv_vip_status"`
|
||||
TvVipPayType int `json:"tv_vip_pay_type"`
|
||||
TvDueDate int `json:"tv_due_date"`
|
||||
} `json:"vip"`
|
||||
Wallet struct {
|
||||
Mid int `json:"mid"`
|
||||
BcoinBalance int `json:"bcoin_balance"`
|
||||
CouponBalance int `json:"coupon_balance"`
|
||||
CouponDueTime int `json:"coupon_due_time"`
|
||||
} `json:"wallet"`
|
||||
HasShop bool `json:"has_shop"`
|
||||
ShopURL string `json:"shop_url"`
|
||||
AllowanceCount int `json:"allowance_count"`
|
||||
AnswerStatus int `json:"answer_status"`
|
||||
IsSeniorMember int `json:"is_senior_member"`
|
||||
WbiImg struct {
|
||||
ImgURL string `json:"img_url"`
|
||||
SubURL string `json:"sub_url"`
|
||||
} `json:"wbi_img"`
|
||||
IsJury bool `json:"is_jury"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
func GetUid(cookie string) (string, error) {
|
||||
result := &UserInfo{}
|
||||
headers := &http.Header{}
|
||||
headers.Set("cookie", cookie)
|
||||
err := GetJsonWithHeader("https://api.bilibili.com/x/web-interface/nav", headers, result)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if result.Code != 0 || !result.Data.IsLogin {
|
||||
return "", errors.New("")
|
||||
}
|
||||
return strconv.Itoa(result.Data.Mid), nil
|
||||
}
|
||||
|
||||
func GetDanmuInfo(roomID string, cookie string) (*DanmuInfo, error) {
|
||||
result := &DanmuInfo{}
|
||||
err := GetJson(fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=%s&type=0", roomID), result)
|
||||
headers := &http.Header{}
|
||||
headers.Set("cookie", cookie)
|
||||
err := GetJsonWithHeader(fmt.Sprintf("https://api.live.bilibili.com/xlive/web-room/v1/index/getDanmuInfo?id=%s&type=0", roomID), headers, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
21
api/utils.go
21
api/utils.go
@@ -10,7 +10,26 @@ func GetJson(url string, result interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
if err = json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetJsonWithHeader(url string, headers *http.Header, result interface{}) error {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
req.Header = *headers
|
||||
c := &http.Client{}
|
||||
resp, err := c.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
_ = resp.Body.Close()
|
||||
}()
|
||||
if err = json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -16,9 +17,10 @@ import (
|
||||
|
||||
type Client struct {
|
||||
conn *websocket.Conn
|
||||
uid string
|
||||
roomID string
|
||||
tempID string
|
||||
Uid string
|
||||
Buvid string
|
||||
RoomID string
|
||||
Cookie string
|
||||
token string
|
||||
host string
|
||||
hostList []string
|
||||
@@ -30,11 +32,10 @@ type Client struct {
|
||||
}
|
||||
|
||||
// NewClient 创建一个新的弹幕 client
|
||||
func NewClient(roomID string, uid string) *Client {
|
||||
func NewClient(roomID string) *Client {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
return &Client{
|
||||
tempID: roomID,
|
||||
uid: uid,
|
||||
RoomID: roomID,
|
||||
retryCount: 0,
|
||||
eventHandlers: &eventHandlers{},
|
||||
customEventHandlers: &customEventHandlers{},
|
||||
@@ -43,23 +44,34 @@ func NewClient(roomID string, uid string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
// init 初始化 获取真实 roomID 和 弹幕服务器 host
|
||||
func (c *Client) SetCookie(cookie string) {
|
||||
c.Cookie = cookie
|
||||
}
|
||||
|
||||
// init 初始化 获取真实 RoomID 和 弹幕服务器 host
|
||||
func (c *Client) init() error {
|
||||
roomInfo, err := api.GetRoomInfo(c.tempID)
|
||||
// 失败降级
|
||||
if err != nil || roomInfo.Code != 0 {
|
||||
log.Errorf("room=%s init GetRoomInfo fialed, %s", c.tempID, err)
|
||||
c.roomID = c.tempID
|
||||
if c.uid == "" {
|
||||
c.uid = "208259" // 叔叔的 UID
|
||||
if c.Cookie != "" {
|
||||
uid, err := api.GetUid(c.Cookie)
|
||||
if err != nil {
|
||||
if c.Uid == "" {
|
||||
c.Uid = "0"
|
||||
}
|
||||
}
|
||||
c.Uid = uid
|
||||
re := regexp.MustCompile("_uuid=(.+?);")
|
||||
result := re.FindAllStringSubmatch(c.Cookie, -1)
|
||||
if len(result) > 0 {
|
||||
c.Buvid = result[0][1]
|
||||
}
|
||||
}
|
||||
c.roomID = strconv.Itoa(roomInfo.Data.RoomId)
|
||||
if c.uid == "" {
|
||||
c.uid = strconv.Itoa(roomInfo.Data.Uid)
|
||||
roomInfo, err := api.GetRoomInfo(c.RoomID)
|
||||
// 失败降级
|
||||
if err != nil || roomInfo.Code != 0 {
|
||||
log.Errorf("room=%s init GetRoomInfo fialed, %s", c.RoomID, err)
|
||||
}
|
||||
c.RoomID = strconv.Itoa(roomInfo.Data.RoomId)
|
||||
if c.host == "" {
|
||||
info, err := api.GetDanmuInfo(c.roomID)
|
||||
info, err := api.GetDanmuInfo(c.RoomID, c.Cookie)
|
||||
if err != nil {
|
||||
c.hostList = []string{"broadcastlv.chat.bilibili.com"}
|
||||
} else {
|
||||
@@ -85,7 +97,7 @@ retry:
|
||||
goto retry
|
||||
}
|
||||
c.conn = conn
|
||||
res.Body.Close()
|
||||
_ = res.Body.Close()
|
||||
if err = c.sendEnterPacket(); err != nil {
|
||||
log.Errorf("failed to send enter packet, retry %d times", c.retryCount)
|
||||
time.Sleep(2 * time.Second)
|
||||
@@ -162,15 +174,15 @@ func (c *Client) UseDefaultHost() {
|
||||
}
|
||||
|
||||
func (c *Client) sendEnterPacket() error {
|
||||
rid, err := strconv.Atoi(c.roomID)
|
||||
rid, err := strconv.Atoi(c.RoomID)
|
||||
if err != nil {
|
||||
return errors.New("error roomID")
|
||||
return errors.New("error RoomID")
|
||||
}
|
||||
uid, err := strconv.Atoi(c.uid)
|
||||
uid, err := strconv.Atoi(c.Uid)
|
||||
if err != nil {
|
||||
return errors.New("error UID")
|
||||
}
|
||||
pkt := packet.NewEnterPacket(uid, rid, c.token)
|
||||
pkt := packet.NewEnterPacket(uid, c.Buvid, rid, c.token)
|
||||
if err = c.conn.WriteMessage(websocket.BinaryMessage, pkt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
knownCMD = []string{"INTERACT_WORD", "HOT_RANK_SETTLEMENT", "DANMU_GIFT_LOTTERY_START", "WELCOME_GUARD", "PK_PROCESS", "PK_BATTLE_PRO_TYPE", "MATCH_TEAM_GIFT_RANK", "PK_BATTLE_CRIT", "LUCK_GIFT_AWARD_USER", "SCORE_CARD", "ONLINE_RANK_V2", "PK_BATTLE_SPECIAL_GIFT", "SEND_TOP", "SUPER_CHAT_MESSAGE_JPN", "ANIMATION", "GUARD_LOTTERY_START", "WEEK_STAR_CLOCK", "WELCOME", "WIN_ACTIVITY", "ROOM_KICKOUT", "CHANGE_ROOM_INFO", "ROOM_SKIN_MSG", "ROOM_BLOCK_MSG", "SUPER_CHAT_ENTRANCE", "PK_BATTLE_RANK_CHANGE", "ROOM_LOCK", "TV_END", "PK_PRE", "ROOM_SILENT_OFF", "SEND_GIFT", "DANMU_MSG", "ANCHOR_LOT_START", "ROOM_BOX_USER", "ONLINE_RANK_TOP3", "WIDGET_BANNER", "PK_BATTLE_START", "ACTIVITY_MATCH_GIFT", "PK_AGAIN", "PK_MATCH", "RAFFLE_START", "LIVE", "WISH_BOTTLE", "GUARD_ACHIEVEMENT_ROOM", "ONLINE_RANK_COUNT", "COMMON_NOTICE_DANMAKU", "LOL_ACTIVITY", "HOT_RANK_CHANGED", "ROOM_BLOCK_INTO", "ROOM_LIMIT", "PANEL", "RAFFLE_END", "ENTRY_EFFECT", "STOP_LIVE_ROOM_LIST", "TV_START", "WATCH_LPL_EXPIRED", "PK_BATTLE_PRE", "USER_TOAST_MSG", "BOX_ACTIVITY_START", "PK_MIC_END", "LIVE_INTERACTIVE_GAME", "ROOM_BANNER", "PK_BATTLE_GIFT", "MESSAGEBOX_USER_GAIN_MEDAL", "LITTLE_TIPS", "HOUR_RANK_AWARDS", "NOTICE_MSG", "ROOM_REAL_TIME_MESSAGE_UPDATE", "ANCHOR_LOT_END", "PREPARING", "GUARD_BUY", "ROOM_CHANGE", "room_admin_entrance", "CHASE_FRAME_SWITCH", "DANMU_GIFT_LOTTERY_AWARD", "PK_BATTLE_VOTES_ADD", "PK_BATTLE_END", "CUT_OFF", "PK_BATTLE_PROCESS", "PK_BATTLE_SETTLE_USER", "ANCHOR_LOT_AWARD", "WIN_ACTIVITY_USER", "VOICE_JOIN_STATUS", "DANMU_GIFT_LOTTERY_END", "ROOM_RANK", "SUPER_CHAT_MESSAGE", "ACTIVITY_BANNER_UPDATE_V2", "SPECIAL_GIFT", "ROOM_SILENT_ON", "WARNING", "ROOM_ADMINS", "COMBO_SEND", "HOT_RANK_SETTLEMENT_V2", "ANCHOR_LOT_CHECKSTATUS", "HOT_RANK_CHANGED_V2", "SUPER_CHAT_MESSAGE_DELETE", "PK_END", "PK_SETTLE", "ROOM_REFRESH", "PK_START", "COMBO_END", "PK_LOTTERY_START", "GUARD_WINDOWS_OPEN", "REENTER_LIVE_ROOM", "MESSAGEBOX_USER_MEDAL_CHANGE", "MESSAGEBOX_USER_MEDAL_COMPENSATION", "LITTLE_MESSAGE_BOX", "PK_BATTLE_PRE_NEW", "PK_BATTLE_START_NEW", "PK_BATTLE_PROCESS_NEW", "PK_BATTLE_FINAL_PROCESS", "PK_BATTLE_SETTLE_V2", "PK_BATTLE_SETTLE_NEW", "PK_BATTLE_PUNISH_END", "PK_BATTLE_VIDEO_PUNISH_BEGIN", "PK_BATTLE_VIDEO_PUNISH_END", "ENTRY_EFFECT_MUST_RECEIVE", "SUPER_CHAT_AUDIT", "VIDEO_CONNECTION_JOIN_START", "VIDEO_CONNECTION_JOIN_END", "VIDEO_CONNECTION_MSG", "VTR_GIFT_LOTTERY", "RED_POCKET_START", "FULL_SCREEN_SPECIAL_EFFECT", "POPULARITY_RED_POCKET_START", "POPULARITY_RED_POCKET_WINNER_LIST", "USER_PANEL_RED_ALARM", "SHOPPING_CART_SHOW", "THERMAL_STORM_DANMU_BEGIN", "THERMAL_STORM_DANMU_UPDATE", "THERMAL_STORM_DANMU_CANCEL", "THERMAL_STORM_DANMU_OVER", "MILESTONE_UPDATE_EVENT", "WEB_REPORT_CONTROL", "DANMU_TAG_CHANGE", "RANK_REM", "LIVE_PLAYER_LOG_RECYCLE", "LIVE_INTERNAL_ROOM_LOGIN", "LIVE_OPEN_PLATFORM_GAME", "WATCHED_CHANGE", "DANMU_AGGREGATION", "POPULARITY_RED_POCKET_NEW", "LIKE_INFO_V3_CLICK", "POPULAR_RANK_CHANGED"}
|
||||
knownCMD = []string{"INTERACT_WORD", "HOT_RANK_SETTLEMENT", "DANMU_GIFT_LOTTERY_START", "WELCOME_GUARD", "PK_PROCESS", "PK_BATTLE_PRO_TYPE", "MATCH_TEAM_GIFT_RANK", "PK_BATTLE_CRIT", "LUCK_GIFT_AWARD_USER", "SCORE_CARD", "ONLINE_RANK_V2", "PK_BATTLE_SPECIAL_GIFT", "SEND_TOP", "SUPER_CHAT_MESSAGE_JPN", "ANIMATION", "GUARD_LOTTERY_START", "WEEK_STAR_CLOCK", "WELCOME", "WIN_ACTIVITY", "ROOM_KICKOUT", "CHANGE_ROOM_INFO", "ROOM_SKIN_MSG", "ROOM_BLOCK_MSG", "SUPER_CHAT_ENTRANCE", "PK_BATTLE_RANK_CHANGE", "ROOM_LOCK", "TV_END", "PK_PRE", "ROOM_SILENT_OFF", "SEND_GIFT", "DANMU_MSG", "ANCHOR_LOT_START", "ROOM_BOX_USER", "ONLINE_RANK_TOP3", "WIDGET_BANNER", "PK_BATTLE_START", "ACTIVITY_MATCH_GIFT", "PK_AGAIN", "PK_MATCH", "RAFFLE_START", "LIVE", "WISH_BOTTLE", "GUARD_ACHIEVEMENT_ROOM", "ONLINE_RANK_COUNT", "COMMON_NOTICE_DANMAKU", "LOL_ACTIVITY", "HOT_RANK_CHANGED", "ROOM_BLOCK_INTO", "ROOM_LIMIT", "PANEL", "RAFFLE_END", "ENTRY_EFFECT", "STOP_LIVE_ROOM_LIST", "TV_START", "WATCH_LPL_EXPIRED", "PK_BATTLE_PRE", "USER_TOAST_MSG", "BOX_ACTIVITY_START", "PK_MIC_END", "LIVE_INTERACTIVE_GAME", "ROOM_BANNER", "PK_BATTLE_GIFT", "MESSAGEBOX_USER_GAIN_MEDAL", "LITTLE_TIPS", "HOUR_RANK_AWARDS", "NOTICE_MSG", "ROOM_REAL_TIME_MESSAGE_UPDATE", "ANCHOR_LOT_END", "PREPARING", "GUARD_BUY", "ROOM_CHANGE", "room_admin_entrance", "CHASE_FRAME_SWITCH", "DANMU_GIFT_LOTTERY_AWARD", "PK_BATTLE_VOTES_ADD", "PK_BATTLE_END", "CUT_OFF", "PK_BATTLE_PROCESS", "PK_BATTLE_SETTLE_USER", "ANCHOR_LOT_AWARD", "WIN_ACTIVITY_USER", "VOICE_JOIN_STATUS", "DANMU_GIFT_LOTTERY_END", "ROOM_RANK", "SUPER_CHAT_MESSAGE", "ACTIVITY_BANNER_UPDATE_V2", "SPECIAL_GIFT", "ROOM_SILENT_ON", "WARNING", "ROOM_ADMINS", "COMBO_SEND", "HOT_RANK_SETTLEMENT_V2", "ANCHOR_LOT_CHECKSTATUS", "HOT_RANK_CHANGED_V2", "SUPER_CHAT_MESSAGE_DELETE", "PK_END", "PK_SETTLE", "ROOM_REFRESH", "PK_START", "COMBO_END", "PK_LOTTERY_START", "GUARD_WINDOWS_OPEN", "REENTER_LIVE_ROOM", "MESSAGEBOX_USER_MEDAL_CHANGE", "MESSAGEBOX_USER_MEDAL_COMPENSATION", "LITTLE_MESSAGE_BOX", "PK_BATTLE_PRE_NEW", "PK_BATTLE_START_NEW", "PK_BATTLE_PROCESS_NEW", "PK_BATTLE_FINAL_PROCESS", "PK_BATTLE_SETTLE_V2", "PK_BATTLE_SETTLE_NEW", "PK_BATTLE_PUNISH_END", "PK_BATTLE_VIDEO_PUNISH_BEGIN", "PK_BATTLE_VIDEO_PUNISH_END", "ENTRY_EFFECT_MUST_RECEIVE", "SUPER_CHAT_AUDIT", "VIDEO_CONNECTION_JOIN_START", "VIDEO_CONNECTION_JOIN_END", "VIDEO_CONNECTION_MSG", "VTR_GIFT_LOTTERY", "RED_POCKET_START", "FULL_SCREEN_SPECIAL_EFFECT", "POPULARITY_RED_POCKET_START", "POPULARITY_RED_POCKET_WINNER_LIST", "USER_PANEL_RED_ALARM", "SHOPPING_CART_SHOW", "THERMAL_STORM_DANMU_BEGIN", "THERMAL_STORM_DANMU_UPDATE", "THERMAL_STORM_DANMU_CANCEL", "THERMAL_STORM_DANMU_OVER", "MILESTONE_UPDATE_EVENT", "WEB_REPORT_CONTROL", "DANMU_TAG_CHANGE", "RANK_REM", "LIVE_PLAYER_LOG_RECYCLE", "LIVE_INTERNAL_ROOM_LOGIN", "LIVE_OPEN_PLATFORM_GAME", "WATCHED_CHANGE", "DANMU_AGGREGATION", "POPULARITY_RED_POCKET_NEW", "LIKE_INFO_V3_CLICK", "POPULAR_RANK_CHANGED", "DM_INTERACTION", "LIKE_INFO_V3_UPDATE", "HOT_ROOM_NOTIFY"}
|
||||
knownCMDMap map[string]int
|
||||
)
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ import (
|
||||
)
|
||||
|
||||
const roomId = "8792912"
|
||||
const uid = "745493"
|
||||
|
||||
var dumps = []string{"GUARD_BUY", "USER_TOAST_MSG"}
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
c := client.NewClient(roomId, uid)
|
||||
c := client.NewClient(roomId)
|
||||
c.SetCookie("")
|
||||
for _, v := range dumps {
|
||||
vv := v
|
||||
c.RegisterCustomEventHandler(vv, func(s string) {
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
|
||||
func main() {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
c := client.NewClient("23555200", "194484313")
|
||||
c.UseDefaultHost()
|
||||
c := client.NewClient("6")
|
||||
c.SetCookie("this is a example cookie.")
|
||||
//弹幕事件
|
||||
c.OnDanmaku(func(danmaku *message.Danmaku) {
|
||||
if danmaku.Type == message.EmoticonDanmaku {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
type Enter struct {
|
||||
UID int `json:"uid"`
|
||||
Buvid string `json:"buvid"`
|
||||
RoomID int `json:"roomid"`
|
||||
ProtoVer int `json:"protover"`
|
||||
Platform string `json:"platform"`
|
||||
@@ -16,9 +17,10 @@ type Enter struct {
|
||||
|
||||
// NewEnterPacket 构造进入房间的包
|
||||
// uid 可以为 0, key 在使用 broadcastlv 服务器的时候不需要
|
||||
func NewEnterPacket(uid int, roomID int, key string) []byte {
|
||||
func NewEnterPacket(uid int, buvid string, roomID int, key string) []byte {
|
||||
ent := &Enter{
|
||||
UID: uid,
|
||||
Buvid: buvid,
|
||||
RoomID: roomID,
|
||||
ProtoVer: 3,
|
||||
Platform: "web",
|
||||
|
||||
Reference in New Issue
Block a user