forked from Mrs4s/MiraiGo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.go
102 lines (95 loc) · 2.71 KB
/
web.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
package client
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"github.com/pkg/errors"
"github.com/Mrs4s/MiraiGo/client/pb/web"
"github.com/Mrs4s/MiraiGo/internal/proto"
"github.com/Mrs4s/MiraiGo/utils"
)
type UnidirectionalFriendInfo struct {
Uin int64
Nickname string
Age uint32
Source string
}
func (c *QQClient) GetUnidirectionalFriendList() (ret []*UnidirectionalFriendInfo, err error) {
webRsp := &struct {
BlockList []struct {
Uin int64 `json:"uint64_uin"`
NickBytes string `json:"bytes_nick"`
Age uint32 `json:"uint32_age"`
Sex uint32 `json:"uint32_sex"`
SourceBytes string `json:"bytes_source"`
} `json:"rpt_block_list"`
ErrorCode int32 `json:"ErrorCode"`
}{}
rsp, err := c.webSsoRequest("ti.qq.com", "OidbSvc.0xe17_0", fmt.Sprintf(`{"uint64_uin":%v,"uint64_top":0,"uint32_req_num":99,"bytes_cookies":""}`, c.Uin))
if err != nil {
return nil, err
}
if err = json.Unmarshal(utils.S2B(rsp), webRsp); err != nil {
return nil, errors.Wrap(err, "unmarshal json error")
}
if webRsp.ErrorCode != 0 {
return nil, errors.Errorf("web sso request error: %v", webRsp.ErrorCode)
}
for _, block := range webRsp.BlockList {
decodeBase64String := func(str string) string {
b, err := base64.StdEncoding.DecodeString(str)
if err != nil {
return ""
}
return utils.B2S(b)
}
ret = append(ret, &UnidirectionalFriendInfo{
Uin: block.Uin,
Nickname: decodeBase64String(block.NickBytes),
Age: block.Age,
Source: decodeBase64String(block.SourceBytes),
})
}
return
}
func (c *QQClient) DeleteUnidirectionalFriend(uin int64) error {
webRsp := &struct {
ErrorCode int32 `json:"ErrorCode"`
}{}
rsp, err := c.webSsoRequest("ti.qq.com", "OidbSvc.0x5d4_0", fmt.Sprintf(`{"uin_list":[%v]}`, uin))
if err != nil {
return err
}
if err = json.Unmarshal(utils.S2B(rsp), webRsp); err != nil {
return errors.Wrap(err, "unmarshal json error")
}
if webRsp.ErrorCode != 0 {
return errors.Errorf("web sso request error: %v", webRsp.ErrorCode)
}
return nil
}
func (c *QQClient) webSsoRequest(host, webCmd, data string) (string, error) {
s := strings.Split(host, `.`)
sub := ""
for i := len(s) - 1; i >= 0; i-- {
sub += s[i]
if i != 0 {
sub += "_"
}
}
cmd := "MQUpdateSvc_" + sub + ".web." + webCmd
req, _ := proto.Marshal(&web.WebSsoRequestBody{
Type: proto.Uint32(0),
Data: proto.Some(data),
})
rspData, err := c.sendAndWaitDynamic(c.uniPacket(cmd, req))
if err != nil {
return "", errors.Wrap(err, "send web sso request error")
}
rsp := &web.WebSsoResponseBody{}
if err = proto.Unmarshal(rspData, rsp); err != nil {
return "", errors.Wrap(err, "unmarshal response error")
}
return rsp.Data.Unwrap(), nil
}