This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
online_push.go
118 lines (109 loc) · 3.22 KB
/
online_push.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
package client
import (
"context"
"fmt"
"strconv"
"github.com/elap5e/go-mobileqq-api/encoding/uni"
"github.com/elap5e/go-mobileqq-api/mobileqq/codec"
"github.com/elap5e/go-mobileqq-api/util"
)
type OnlinePushRequest struct {
Uin int64 `jce:",0" json:"uin,omitempty"`
Time int64 `jce:",1" json:"time,omitempty"`
Messages []*Message `jce:",2" json:"messages,omitempty"`
ServerIP Uint32IPType `jce:",3" json:"server_ip,omitempty"`
SyncCookie []byte `jce:",4" json:"sync_cookie,omitempty"`
UinPairMessages []*UinPairMessage `jce:",5" json:"uin_pair_messages,omitempty"`
Previews map[string][]byte `jce:",6" json:"previews,omitempty"`
UserActive int32 `jce:",7" json:"user_active,omitempty"`
GeneralFlag int32 `jce:",12" json:"general_flag,omitempty"`
}
type OnlinePushResponse struct {
Type int32 `jce:",1" json:"type,omitempty"`
Seq int64 `jce:",2" json:"seq,omitempty"`
Buffer []byte `jce:",3" json:"buffer,omitempty"`
}
func NewOnlinePushMessageResponse(
ctx context.Context,
username string,
items []MessageDelete,
serverIP Uint32IPType,
seq int32,
) (*codec.ClientToServerMessage, error) {
if len(items) == 0 {
return nil, fmt.Errorf("zero length")
}
uin, err := strconv.ParseInt(username, 10, 64)
if err != nil {
return nil, err
}
resp := OnlinePushMessageResponse{
Uin: uin,
Items: items,
ServerIP: serverIP,
}
buf, err := uni.Marshal(ctx, &uni.Message{
Version: 0x0003,
PacketType: 0x00,
MessageType: 0x00000000,
RequestID: seq,
ServantName: "OnlinePush",
FuncName: "SvcRespPushMsg",
Buffer: []byte{},
Timeout: 0x00000000,
Context: map[string]string{},
Status: map[string]string{},
}, map[string]interface{}{
"resp": resp,
})
if err != nil {
return nil, err
}
return &codec.ClientToServerMessage{
Username: username,
Seq: uint32(seq),
ServiceMethod: ServiceMethodOnlinePushResponse,
Buffer: buf,
Simple: false,
}, nil
}
func (c *Client) handleOnlinePushRequest(
ctx context.Context,
s2c *codec.ServerToClientMessage,
) (*codec.ClientToServerMessage, error) {
msg := uni.Message{}
push := OnlinePushRequest{}
if err := uni.Unmarshal(ctx, s2c.Buffer, &msg, map[string]interface{}{
"req": &push,
}); err != nil {
return nil, err
}
util.DumpServerToClientMessage(s2c, &push)
uin, _ := strconv.ParseUint(s2c.Username, 10, 64)
items := []MessageDelete{}
for _, msg := range push.Messages {
switch msg.MessageType {
case 0x0210:
body, err := c.decodeMessageType0210Jce(uin, msg.MessageBytes)
if err != nil {
return nil, err
} else if body != nil {
util.DumpServerToClientMessage(s2c, &body)
}
case 0x02DC:
body, err := c.decodeMessageType02DC(uin, msg.MessageBytes)
if err != nil {
return nil, err
} else if body != nil {
util.DumpServerToClientMessage(s2c, &body)
}
}
items = append(items, MessageDelete{
FromUin: msg.FromUin,
MessageTime: msg.MessageTime,
MessageSeq: msg.MessageSeq,
MessageCookie: msg.MessageCookie,
})
}
return NewOnlinePushMessageResponse(ctx, s2c.Username, items, push.ServerIP, int32(s2c.Seq))
}