-
Notifications
You must be signed in to change notification settings - Fork 3
/
token.go
45 lines (39 loc) · 917 Bytes
/
token.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
package douyuapi
const tokenURI = "/api/thirdPart/token"
// Token ...
type Token struct {
BaseClient
}
// TokenResponse ...
type TokenResponse struct {
ErrorResponse
Data struct {
Token string `json:"token"`
Expire int `json:"expire"`
} `json:"data"`
}
// Handle ...
func (t *Token) Handle(timestamp string) (*TokenResponse, error) {
return t.do(DouYuDomain+tokenURI, timestamp)
}
// do
func (t *Token) do(url, timestamp string) (*TokenResponse, error) {
var params = map[string]string{
"aid": t.AID,
"time": timestamp,
}
params["auth"] = GetSign(t.Secret, tokenURI, params)
err := t.Client.HTTPGet(url, params)
if err != nil {
return nil, err
}
var ret, errResp = new(TokenResponse), new(ErrorResponse)
if err = t.Client.GetResponseJSON(ret, errResp); err != nil {
return nil, err
}
if errResp.Code != 0 {
ret.Code = errResp.Code
ret.Msg = errResp.Msg
}
return ret, nil
}