Skip to content

Commit

Permalink
✨ feat(commClient): LiveGetGuardList
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Nov 4, 2021
1 parent 6057b52 commit 927fc5a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
29 changes: 29 additions & 0 deletions comm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,3 +1162,32 @@ func (c *CommClient) LiveGetAreaInfo() ([]*LiveAreaInfo, error) {
}
return r, nil
}

// LiveGetGuardList 获取直播间大航海列表
//
// mid: 主播mid
//
// pn: 页码
//
// ps: 每页项数
func (c *CommClient) LiveGetGuardList(roomID int64, mid int64, pn int, ps int) (*LiveGuardList, error) {
resp, err := c.RawParse(
BiliLiveURL,
"xlive/app-room/v1/guardTab/topList",
"GET",
map[string]string{
"roomid": strconv.FormatInt(roomID, 10),
"ruid": strconv.FormatInt(mid, 10),
"page": strconv.Itoa(pn),
"page_size": strconv.Itoa(ps),
},
)
if err != nil {
return nil, err
}
var r = &LiveGuardList{}
if err = json.Unmarshal(resp.Data, &r); err != nil {
return nil, err
}
return r, nil
}
14 changes: 14 additions & 0 deletions comm_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,3 +522,17 @@ func TestCommClient_LiveGetAreaInfo(t *testing.T) {
}
}
}
func TestCommClient_LiveGetGuardList(t *testing.T) {
r, err := testCommClient.LiveGetGuardList(545068, 8739477, 3, 10)
if err != nil {
t.Error(err)
t.FailNow()
}
t.Logf("total: %d,nowPage: %d,totalPage: %d", r.Info.Num, r.Info.Now, r.Info.Page)
for _, l := range r.Top3 {
t.Logf("uid: %d,uname: %s,rank: %d,level: %d", l.UID, l.Username, l.Rank, l.GuardLevel)
}
for _, l := range r.List {
t.Logf("\tuid: %d,uname: %s,rank: %d,level: %d", l.UID, l.Username, l.Rank, l.GuardLevel)
}
}
28 changes: 28 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1509,3 +1509,31 @@ type LiveAreaInfo struct {
CateID string `json:"cate_id,omitempty"`
} `json:"list"`
}
type LiveGuardList struct {
Info *struct {
Num int `json:"num"` // 大航海总数
Page int `json:"page"` // 总页数
Now int `json:"now"` // 该次请求的页数
AchievementLevel int `json:"achievement_level"`
} `json:"info"`
List []*struct {
UID int64 `json:"uid"`
RUID int64 `json:"ruid"` // 主播mid
Rank int `json:"rank"` // 在该数组中的排名
Username string `json:"username"`
Face string `json:"face"`
IsAlive int `json:"is_alive"`
GuardLevel int `json:"guard_level"` // 1:总督 2:提督 3:舰长
GuardSubLevel int `json:"guard_sub_level"`
} `json:"list"`
Top3 []*struct {
UID int `json:"uid"`
RUID int `json:"ruid"` // 主播mid
Rank int `json:"rank"` // 在该数组中的排名
Username string `json:"username"`
Face string `json:"face"`
IsAlive int `json:"is_alive"`
GuardLevel int `json:"guard_level"` // 1:总督 2:提督 3:舰长
GuardSubLevel int `json:"guard_sub_level"`
} `json:"top3"`
}

0 comments on commit 927fc5a

Please sign in to comment.