-
Notifications
You must be signed in to change notification settings - Fork 2
/
api_internal.go
203 lines (192 loc) · 6.65 KB
/
api_internal.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
package qzone
import (
"errors"
"fmt"
"github.com/HHU-47133/qzone/models"
"github.com/tidwall/gjson"
"log"
"strconv"
"strings"
"time"
)
// GetShuoShuoCommentsRaw 从第pos条评论开始获取num条评论,num最大为20
func (m *QZone) shuoShuoCommentsRaw(num int, pos int, tid string) (comments []*models.Comment, err error) {
url := fmt.Sprintf(getCommentsURL, strconv.FormatInt(m.qq, 10), pos, num, tid, m.gtk2)
data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
"cookie": m.cookie,
})))
if err != nil {
er := errors.New("说说评论列表请求错误:" + err.Error())
log.Println("说说评论列表获取失败:", er.Error())
return nil, err
}
r := cRe.FindStringSubmatch(string(data))
if len(r) < 2 {
er := errors.New("说说评论正则解析错误:" + err.Error())
log.Println("说说评论列表获取失败:", er.Error())
return nil, er
}
jsonRaw := r[1]
// 取出评论数据
commentJsonList := gjson.Get(jsonRaw, "commentlist").Array()
for _, com := range commentJsonList {
comment := &models.Comment{
ShuoShuoID: tid,
OwnerName: com.Get("owner.name").String(),
OwnerUin: com.Get("owner.uin").Int(),
Content: com.Get("content").String(),
PicContent: make([]string, 0),
CreateTime: time.Unix(com.Get("create_time").Int(), 0),
}
// 添加图片评论的图片到结构体
for _, pic := range com.Get("rich_info").Array() {
comment.PicContent = append(comment.PicContent, pic.Get("burl").String())
}
comments = append(comments, comment)
}
return comments, nil
}
// UploadImage 上传图片
func (m *QZone) uploadImage(base64img string) (*models.UploadImageResp, error) {
uir := models.UploadImageRequest{
Filename: "filename",
Uin: m.qq,
Skey: m.skey,
Zzpaneluin: m.qq,
PUin: m.qq,
PSkey: m.pskey,
Uploadtype: "1",
Albumtype: "7",
Exttype: "0",
Refer: "shuoshuo",
OutputType: "json",
Charset: "utf-8",
OutputCharset: "utf-8",
UploadHd: "1",
HdWidth: "2048",
HdHeight: "10000",
HdQuality: "96",
BackUrls: "http://upbak.photo.qzone.qq.com/cgi-bin/upload/cgi_upload_image,http://119.147.64.75/cgi-bin/upload/cgi_upload_image",
URL: fmt.Sprintf(uploadImageURL, m.gtk2),
Base64: "1",
Picfile: base64img,
Qzreferrer: userQzoneURL + "/" + strconv.FormatInt(m.qq, 10),
}
url := fmt.Sprintf(uploadImageURL, m.gtk2)
payload := strings.NewReader(structToStr(uir))
data, err := DialRequest(NewRequest(WithMethod("POST"), WithUrl(url), WithBody(payload),
WithHeader(map[string]string{
"referer": userQzoneURL,
"origin": userQzoneURL,
"cookie": m.cookie,
})))
if err != nil {
return nil, errors.New("图片上传请求错误:" + err.Error())
}
r := cRe.FindStringSubmatch(string(data))
if len(r) < 2 {
return nil, errors.New("图片上传响应解析错误:" + string(data))
}
jsonStr := r[1]
uploadImageResp := &models.UploadImageResp{
Pre: gjson.Get(jsonStr, "data.pre").String(),
URL: gjson.Get(jsonStr, "data.url").String(),
Width: gjson.Get(jsonStr, "data.width").Int(),
Height: gjson.Get(jsonStr, "data.height").Int(),
OriginURL: gjson.Get(jsonStr, "data.origin_url").String(),
Contentlen: gjson.Get(jsonStr, "data.contentlen").Int(),
Ret: gjson.Get(jsonStr, "ret").Int(),
Albumid: gjson.Get(jsonStr, "data.albumid").String(),
Lloc: gjson.Get(jsonStr, "data.lloc").String(),
Sloc: gjson.Get(jsonStr, "data.sloc").String(),
Type: gjson.Get(jsonStr, "data.type").Int(),
}
return uploadImageResp, nil
}
// getPicBoAndRichval 获取已上传图片重要信息
func (m *QZone) getPicBoAndRichval(data *models.UploadImageResp) (picBo, richval string, err error) {
var flag bool
if data.Ret != 0 {
err = errors.New("已上传图片信息错误:fuck")
return
}
_, picBo, flag = strings.Cut(data.URL, "&bo=")
if !flag {
err = errors.New("已上传图片URL错误:" + data.URL)
return
}
richval = fmt.Sprintf(",%s,%s,%s,%d,%d,%d,,%d,%d", data.Albumid, data.Lloc, data.Sloc, data.Type, data.Height, data.Width, data.Height, data.Width)
return
}
// ShuoShuoListRaw 获取用户qq号为uin且最多num个说说列表,每个说说获取上限replynum个评论数量
func (m *QZone) shuoShuoListRaw(uin int64, num int, pos int, replynum int) ([]*models.ShuoShuoResp, error) {
mlr := models.MsgListRequest{
Uin: uin,
Ftype: "0",
Sort: "0",
Pos: strconv.Itoa(pos),
Num: strconv.Itoa(num),
Replynum: strconv.Itoa(replynum),
GTk: m.gtk2,
Callback: "_preloadCallback",
CodeVersion: "1",
Format: "json",
NeedPrivateComment: "1",
}
url := msglistURL + "?" + structToStr(mlr)
data, err := DialRequest(NewRequest(WithUrl(url), WithHeader(map[string]string{
"referer": userQzoneURL,
"origin": userQzoneURL,
"cookie": m.cookie,
})))
if err != nil {
er := errors.New("说说列表请求错误:" + err.Error())
log.Println("说说列表获取失败:", er.Error())
return nil, er
}
jsonStr := string(data)
// 判断是否有访问权限
forbid := gjson.Get(jsonStr, "message").String()
if forbid != "" {
er := errors.New("说说列表解析错误:" + forbid)
log.Println("说说列表获取失败:", er.Error())
return nil, er
}
var resLen int64
if !gjson.Get(jsonStr, "msglist.#").Exists() {
er := errors.New("说说列表解析错误:" + jsonStr)
log.Println("说说列表获取失败:", er.Error())
return nil, er
}
resLen = gjson.Get(jsonStr, "msglist.#").Int()
results := make([]*models.ShuoShuoResp, min(resLen, int64(num)))
index := 0
lists := gjson.Get(jsonStr, "msglist").Array()
for _, shuoshuo := range lists {
ss := &models.ShuoShuoResp{
Uin: shuoshuo.Get("uin").Int(),
Name: shuoshuo.Get("name").String(),
Tid: shuoshuo.Get("tid").String(),
Content: shuoshuo.Get("content").String(),
CreateTime: shuoshuo.Get("createTime").String(),
CreatedTime: shuoshuo.Get("created_time").Int(),
PicTotal: shuoshuo.Get("pictotal").Int(),
Cmtnum: shuoshuo.Get("cmtnum").Int(),
Secret: shuoshuo.Get("secret").Int(),
}
pics := shuoshuo.Get("pic").Array()
for _, pic := range pics {
ss.Pic = append(ss.Pic, models.PicResp{
PicId: pic.Get("pic_id").String(),
Url1: pic.Get("url1").String(),
Url2: pic.Get("url2").String(),
Url3: pic.Get("url3").String(),
Smallurl: pic.Get("smallurl").String(),
Curlikekey: pic.Get("curlikekey").String(),
})
}
results[index] = ss
index++
}
return results, nil
}