This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
payload.go
257 lines (230 loc) · 6.98 KB
/
payload.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package botoy
import (
"encoding/json"
"net/http"
)
type payload interface {
// 返回 request_method, api_path, funcname, json_string
process() (string, string, string, string)
}
// FriendTextPayload 好友文字消息
type FriendTextPayload struct {
ToUserID int64
Text string
}
func (p *FriendTextPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 1
jsonData["SendMsgType"] = "TextMsg"
jsonData["ToUserUid"] = p.ToUserID
jsonData["Content"] = p.Text
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}
// FriendPicPayload 好友图片消息
type FriendPicPayload struct {
ToUser int64
Content string
PicURL string
PicBase64 string
FileMd5 string
Flash bool
}
func (p *FriendPicPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["sendToType"] = 1
jsonData["sendMsgType"] = "PicMsg"
jsonData["toUser"] = p.ToUser
jsonData["content"] = p.Content
jsonData["picUrl"] = p.PicURL
jsonData["picBase64Buf"] = p.PicBase64
jsonData["fileMd5"] = p.FileMd5
jsonData["flashPic"] = p.Flash
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsg", string(jsonBytes)
}
// FriendVoicePayload 好友语音消息
type FriendVoicePayload struct {
ToUser int64
VoiceURL string
VoiceBase64 string
}
func (p *FriendVoicePayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["sendToType"] = 1
jsonData["sendMsgType"] = "VoiceMsg"
jsonData["toUser"] = p.ToUser
jsonData["voiceUrl"] = p.VoiceURL
jsonData["voiceBase64Buf"] = p.VoiceBase64
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsg", string(jsonBytes)
}
// GroupTextPayload 群文字消息
type GroupTextPayload struct {
GroupID int64
Text string
}
func (p *GroupTextPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 2
jsonData["SendMsgType"] = "TextMsg"
jsonData["ToUserUid"] = p.GroupID
jsonData["Content"] = p.Text
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}
// GroupPicPayload 群图片消息
type GroupPicPayload struct {
GroupID int64
Content string
PicURL string
PicBase64 string
PicMD5s []string
PicMD5 string
Flash bool
}
func (p *GroupPicPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
// v1
jsonData["toUser"] = p.GroupID
jsonData["sendToType"] = 2
jsonData["sendMsgType"] = "PicMsg"
jsonData["content"] = p.Content
jsonData["picUrl"] = p.PicURL
jsonData["picBase64Buf"] = p.PicBase64
jsonData["fileMd5"] = p.PicMD5
jsonData["flashPic"] = p.Flash
// v2
jsonData["ToUserUid"] = p.GroupID
jsonData["SendToType"] = 2
jsonData["SendMsgType"] = "PicMsg"
jsonData["PicMd5s"] = p.PicMD5s
jsonBytes, _ := json.Marshal(jsonData)
var funcname string
if len(p.PicMD5s) > 0 {
funcname = "SendMsgV2"
} else {
funcname = "SendMsg"
}
return http.MethodPost, "v1/LuaApiCaller", funcname, string(jsonBytes)
}
// GroupVoicePayload 群语音消息
type GroupVoicePayload struct {
GroupID int64
VoiceURL string
VoiceBase64 string
}
func (p *GroupVoicePayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["sendToType"] = 2
jsonData["sendMsgType"] = "VoiceMsg"
jsonData["toUser"] = p.GroupID
jsonData["voiceUrl"] = p.VoiceURL
jsonData["voiceBase64Buf"] = p.VoiceBase64
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsg", string(jsonBytes)
}
// GroupJSONPayload 群json消息
type GroupJSONPayload struct {
GroupID int64
JSONStr string
}
func (p *GroupJSONPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 2
jsonData["SendMsgType"] = "JsonMsg"
jsonData["ToUserUid"] = p.GroupID
jsonData["Content"] = p.JSONStr
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}
// GroupXMLPayload 群XML消息
type GroupXMLPayload struct {
GroupID int64
XMLStr string
}
func (p *GroupXMLPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 2
jsonData["SendMsgType"] = "XmlMsg"
jsonData["ToUserUid"] = p.GroupID
jsonData["Content"] = p.XMLStr
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}
// GroupReplyPayload 群回复消息
type GroupReplyPayload struct {
GroupID int64
Content string
RawMsgSeq int
RawMsgTime int
RawMsgUserID int64
RawMsgContent string
}
func (p *GroupReplyPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["sendToType"] = 2
jsonData["sendMsgType"] = "ReplayMsg"
jsonData["toUser"] = p.GroupID
jsonData["content"] = p.Content
jsonData["replayInfo"] = map[string]interface{}{
"MsgSeq": p.RawMsgSeq,
"MsgTime": p.RawMsgTime,
"UserID": p.RawMsgUserID,
"RawContent": p.RawMsgContent,
}
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsg", string(jsonBytes)
}
// PrivateTextPayload 私聊文字消息
type PrivateTextPayload struct {
ToUserID int64
GroupID int64
Text string
}
func (p *PrivateTextPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 3
jsonData["SendMsgType"] = "TextMsg"
jsonData["GroupID"] = p.GroupID
jsonData["ToUserUid"] = p.ToUserID
jsonData["Content"] = p.Text
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}
// PrivatePicPayload 私聊图片消息
type PrivatePicPayload struct {
ToUserID int64
GroupID int64
PicURL string
PicBase64 string
FileMd5 string
Content string
Flash bool
}
func (p *PrivatePicPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["sendToType"] = 3
jsonData["sendMsgType"] = "PicMsg"
jsonData["groupid"] = p.GroupID
jsonData["toUser"] = p.ToUserID
jsonData["content"] = p.Content
jsonData["picUrl"] = p.PicURL
jsonData["picBase64Buf"] = p.PicBase64
jsonData["fileMd5"] = p.FileMd5
jsonData["flashPic"] = p.Flash
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsg", string(jsonBytes)
}
// PhoneTextPayload 给手机发文字消息
type PhoneTextPayload struct {
Text string
}
func (p *PhoneTextPayload) process() (string, string, string, string) {
jsonData := make(map[string]interface{})
jsonData["SendToType"] = 2
jsonData["SendMsgType"] = "PhoneMsg"
jsonData["Content"] = p.Text
jsonBytes, _ := json.Marshal(jsonData)
return http.MethodPost, "v1/LuaApiCaller", "SendMsgV2", string(jsonBytes)
}