-
Notifications
You must be signed in to change notification settings - Fork 3
/
types.go
79 lines (63 loc) · 1.59 KB
/
types.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
67
68
69
70
71
72
73
74
75
76
77
78
79
package weiyunsdkgo
import (
"encoding/json"
"fmt"
)
type RespHeader struct {
Retcode int `json:"retcode"`
Retmsg string `json:"retmsg"`
Cmd int `json:"cmd"`
CmdName string `json:"cmdName"`
Uin int64 `json:"uin"`
Type int `json:"type"`
// flag
ZipFlag int `json:"zip_flag"`
Encrypt int `json:"encrypt"`
Seq int64 `json:"seq"`
}
type Resp struct {
Code int `json:"ret"`
Msg string `json:"msg"`
Data *struct {
RspHeader RespHeader `json:"rsp_header"`
RspBody struct {
RspMsgBody json.RawMessage `json:"RspMsg_body"`
} `json:"rsp_body"`
} `json:"data"`
}
func (r *Resp) HasError() bool {
return r.Data.RspHeader.Retcode != 0 || r.Code != 0
}
func (r *Resp) Error() string {
if r.Msg != "" {
return fmt.Sprintf("errcode:%d, errmsg:%s", r.Code, r.Msg)
}
return fmt.Sprintf("cmd:%d, cmdName:%s, seq:%d, errcode:%d, errmsg:%s",
r.Data.RspHeader.Cmd,
r.Data.RspHeader.CmdName,
r.Data.RspHeader.Seq,
r.Data.RspHeader.Retcode,
r.Data.RspHeader.Retmsg)
}
func (r *Resp) GetHeader() RespHeader {
return r.Data.RspHeader
}
func (r *Resp) GetBody() json.RawMessage {
return r.Data.RspBody.RspMsgBody
}
type OpenApiErron struct {
ErrCode int `json:"err_code"`
ErrMsg string `json:"err_msg"`
}
func (e *OpenApiErron) IsError() bool {
return e.ErrCode != 0
}
func (e *OpenApiErron) Error() string {
return fmt.Sprintf("code:%d, msg:%s", e.ErrCode, e.ErrMsg)
}
type OpenApiToken struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
RefreshToken string `json:"refresh_token"`
TokenType string `json:"token_type"`
}