-
Notifications
You must be signed in to change notification settings - Fork 3
/
batch_get_room_info.go
66 lines (58 loc) · 1.72 KB
/
batch_get_room_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package douyuapi
import (
"github.com/birjemin/douyuapi/utils"
)
const batchGetRoomInfoURI = "/api/thirdPart/batchGetRoomInfo"
// BatchGetRoomInfo ...
type BatchGetRoomInfo struct {
BaseClient
Token string
}
// BatchGetRoomInfoResponse ...
type BatchGetRoomInfoResponse struct {
ErrorResponse
Data []struct {
RID int `json:"rid"`
RoomSrc string `json:"room_src"`
RoomSrcMax string `json:"room_src_max"`
RoomName string `json:"room_name"`
Hn int `json:"hn"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Cid1 int `json:"cid1"`
Cname1 string `json:"cname1"`
Cid2 int `json:"cid2"`
Cname2 string `json:"cname2"`
Cid3 int `json:"cid3"`
Cname3 string `json:"cname3"`
ShowStatus int `json:"show_status"`
RoomNotice string `json:"room_notice"`
IsVertical int `json:"is_vertical"`
} `json:"data"`
}
// Handle ...
func (p *BatchGetRoomInfo) Handle(postJSON, timestamp string) (*BatchGetRoomInfoResponse, error) {
return p.do(DouYuDomain+batchGetRoomInfoURI, postJSON, timestamp)
}
// do
func (p *BatchGetRoomInfo) do(url, postJSON, timestamp string) (*BatchGetRoomInfoResponse, error) {
var params = map[string]string{
"aid": p.AID,
"time": timestamp,
"token": p.Token,
}
params["auth"] = GetSign(p.Secret, batchGetRoomInfoURI, params)
url += "?" + utils.HTTPQueryBuild(params)
if err := p.Client.HTTPPostJSON(url, postJSON); err != nil {
return nil, err
}
var ret, errResp = new(BatchGetRoomInfoResponse), new(ErrorResponse)
if err := p.Client.GetResponseJSON(ret, errResp); err != nil {
return nil, err
}
if errResp.Code != 0 {
ret.Code = errResp.Code
ret.Msg = errResp.Msg
}
return ret, nil
}