forked from eatmoreapple/openwechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitems.go
169 lines (145 loc) · 3.33 KB
/
items.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package openwechat
import (
"errors"
"strconv"
)
/*
一些网络返回信息的封装
*/
// LoginInfo 登录信息
type LoginInfo struct {
Ret int `xml:"ret"`
WxUin int64 `xml:"wxuin"`
IsGrayScale int `xml:"isgrayscale"`
Message string `xml:"message"`
SKey string `xml:"skey"`
WxSid string `xml:"wxsid"`
PassTicket string `xml:"pass_ticket"`
}
func (l LoginInfo) Ok() bool {
return l.Ret == 0
}
func (l LoginInfo) Err() error {
if l.Ok() {
return nil
}
return errors.New(l.Message)
}
// BaseRequest 初始的请求信息
// 几乎所有的请求都要携带该参数
type BaseRequest struct {
Uin int64
Sid, Skey, DeviceID string
}
type SyncKey struct {
Count int
List []struct{ Key, Val int64 }
}
// WebInitResponse 初始化的相应信息
type WebInitResponse struct {
Count int
ClientVersion int
GrayScale int
InviteStartCount int
MPSubscribeMsgCount int
ClickReportInterval int
SystemTime int64
ChatSet string
SKey string
BaseResponse BaseResponse
SyncKey SyncKey
User User
MPSubscribeMsgList []MPSubscribeMsg
ContactList []User
}
// MPSubscribeMsg 公众号的订阅信息
type MPSubscribeMsg struct {
MPArticleCount int
Time int64
UserName string
NickName string
MPArticleList []struct {
Title string
Cover string
Digest string
Url string
}
}
type UserDetailItem struct {
UserName string
EncryChatRoomId string
}
type UserDetailItemList []UserDetailItem
func NewUserDetailItemList(members Members) UserDetailItemList {
var list = make(UserDetailItemList, len(members))
for index, member := range members {
item := UserDetailItem{UserName: member.UserName, EncryChatRoomId: member.EncryChatRoomId}
list[index] = item
}
return list
}
type SyncCheckResponse struct {
RetCode string
Selector string
}
func (s SyncCheckResponse) Success() bool {
return s.RetCode == "0"
}
func (s SyncCheckResponse) NorMal() bool {
return s.Success() && s.Selector == "0"
}
func (s SyncCheckResponse) Err() error {
if s.Success() {
return nil
}
i, err := strconv.ParseInt(s.RetCode, 16, 10)
if err != nil {
return errors.New("sync check unknown error")
}
return errors.New(Ret(i).String())
}
type WebWxSyncResponse struct {
AddMsgCount int
ContinueFlag int
DelContactCount int
ModChatRoomMemberCount int
ModContactCount int
Skey string
SyncCheckKey SyncKey
SyncKey SyncKey
BaseResponse BaseResponse
ModChatRoomMemberList Members
AddMsgList []*Message
}
type WebWxContactResponse struct {
MemberCount int
Seq int64
BaseResponse BaseResponse
MemberList []*User
}
type WebWxBatchContactResponse struct {
Count int
BaseResponse BaseResponse
ContactList []*User
}
type CheckLoginResponse struct {
Code string
Raw []byte
}
type MessageResponse struct {
BaseResponse BaseResponse
LocalID string
MsgID string
}
type UploadResponse struct {
BaseResponse BaseResponse
MediaId string
}
type PushLoginResponse struct {
Ret string `json:"ret"`
Msg string `json:"msg"`
UUID string `json:"uuid"`
}
func (p PushLoginResponse) Ok() bool {
return p.Ret == "0" && p.UUID != ""
}