@@ -24,7 +24,7 @@ import (
24
24
const (
25
25
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
26
26
referer = "https://space.bilibili.com/%v"
27
- infoURL = "https://api.bilibili.com/x/space/wbi/acc/info?mid=%v&token=&platform=web&web_location=1550101 "
27
+ infoURL = "https://api.bilibili.com/x/space/wbi/acc/info?mid=%v"
28
28
)
29
29
30
30
// bdb bilibili推送数据库
@@ -77,7 +77,7 @@ func init() {
77
77
78
78
en .OnRegex (`^添加[B|b]站订阅\s?(.{1,25})$` , zero .UserOrGrpAdmin , getPara ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
79
79
buid , _ := strconv .ParseInt (ctx .State ["uid" ].(string ), 10 , 64 )
80
- name , err := getName (buid )
80
+ name , err := getName (buid , cfg )
81
81
if err != nil || name == "" {
82
82
ctx .SendChain (message .Text ("ERROR: " , err ))
83
83
return
@@ -95,7 +95,7 @@ func init() {
95
95
96
96
en .OnRegex (`^取消[B|b]站订阅\s?(.{1,25})$` , zero .UserOrGrpAdmin , getPara ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
97
97
buid , _ := strconv .ParseInt (ctx .State ["uid" ].(string ), 10 , 64 )
98
- name , err := getName (buid )
98
+ name , err := getName (buid , cfg )
99
99
if err != nil {
100
100
ctx .SendChain (message .Text ("ERROR: " , err ))
101
101
return
@@ -112,7 +112,7 @@ func init() {
112
112
})
113
113
en .OnRegex (`^取消[B|b]站动态订阅\s?(.{1,25})$` , zero .UserOrGrpAdmin , getPara ).SetBlock (true ).Handle (func (ctx * zero.Ctx ) {
114
114
buid , _ := strconv .ParseInt (ctx .State ["uid" ].(string ), 10 , 64 )
115
- name , err := getName (buid )
115
+ name , err := getName (buid , cfg )
116
116
if err != nil {
117
117
ctx .SendChain (message .Text ("ERROR: " , err ))
118
118
return
@@ -133,7 +133,7 @@ func init() {
133
133
if gid == 0 {
134
134
gid = - ctx .Event .UserID
135
135
}
136
- name , err := getName (buid )
136
+ name , err := getName (buid , cfg )
137
137
if err != nil {
138
138
ctx .SendChain (message .Text ("ERROR: " , err ))
139
139
return
@@ -200,10 +200,18 @@ func changeAtAll(gid int64, b int) (err error) {
200
200
}
201
201
202
202
// 取得uid的名字
203
- func getName (buid int64 ) (name string , err error ) {
203
+ func getName (buid int64 , cookiecfg * bz. CookieConfig ) (name string , err error ) {
204
204
var ok bool
205
205
if name , ok = upMap [buid ]; ! ok {
206
206
data , err := web .RequestDataWithHeaders (web .NewDefaultClient (), bz .SignURL (fmt .Sprintf (infoURL , buid )), "GET" , func (r * http.Request ) error {
207
+ if cookiecfg != nil {
208
+ cookie := ""
209
+ cookie , err = cookiecfg .Load ()
210
+ if err != nil {
211
+ return err
212
+ }
213
+ r .Header .Add ("Cookie" , cookie )
214
+ }
207
215
r .Header .Set ("User-Agent" , ua )
208
216
return nil
209
217
}, nil )
@@ -262,8 +270,19 @@ func unsubscribeLive(buid, groupid int64) (err error) {
262
270
return bdb .insertOrUpdateLiveAndDynamic (bpMap )
263
271
}
264
272
265
- func getUserDynamicCard (buid int64 ) (cardList []gjson.Result , err error ) {
266
- data , err := web .RequestDataWith (web .NewDefaultClient (), fmt .Sprintf (bz .SpaceHistoryURL , buid , 0 ), "GET" , referer , ua , nil )
273
+ func getUserDynamicCard (buid int64 , cookiecfg * bz.CookieConfig ) (cardList []gjson.Result , err error ) {
274
+ data , err := web .RequestDataWithHeaders (web .NewDefaultClient (), fmt .Sprintf (bz .SpaceHistoryURL , buid , 0 ), "GET" , func (req * http.Request ) error {
275
+ if cookiecfg != nil {
276
+ cookie := ""
277
+ cookie , err = cookiecfg .Load ()
278
+ if err != nil {
279
+ return err
280
+ }
281
+ req .Header .Add ("Cookie" , cookie )
282
+ }
283
+ req .Header .Add ("User-Agent" , ua )
284
+ return nil
285
+ }, nil )
267
286
if err != nil {
268
287
return
269
288
}
@@ -289,7 +308,7 @@ func sendDynamic(ctx *zero.Ctx) error {
289
308
uids := bdb .getAllBuidByDynamic ()
290
309
for _ , buid := range uids {
291
310
time .Sleep (2 * time .Second )
292
- cardList , err := getUserDynamicCard (buid )
311
+ cardList , err := getUserDynamicCard (buid , cfg )
293
312
if err != nil {
294
313
return err
295
314
}
0 commit comments