-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathouter_chat.go
48 lines (41 loc) · 1.03 KB
/
outer_chat.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
package douyuapi
import (
"github.com/birjemin/douyuapi/utils"
)
const outerChatURI = "/api/thirdPart/outerChat"
// OuterChat ...
type OuterChat struct {
BaseClient
Token string
}
// OuterChatResponse ...
type OuterChatResponse struct {
ErrorResponse
Data string `json:"data"`
}
// Handle ...
func (p *OuterChat) Handle(chat, timestamp string) (*OuterChatResponse, error) {
return p.do(DouYuDomain+outerChatURI, chat, timestamp)
}
// do
func (p *OuterChat) do(url, chat, timestamp string) (*OuterChatResponse, error) {
var params = map[string]string{
"aid": p.AID,
"time": timestamp,
"token": p.Token,
}
params["auth"] = GetSign(p.Secret, outerChatURI, params)
url += "?" + utils.HTTPQueryBuild(params)
if err := p.Client.HTTPPostJSON(url, chat); err != nil {
return nil, err
}
var ret, errResp = new(OuterChatResponse), 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
}