@@ -264,19 +264,27 @@ def update_local_uin(core, msg):
264
264
def get_contact (self , update = False ):
265
265
if not update :
266
266
return utils .contact_deep_copy (self , self .chatroomList )
267
- url = '%s/webwxgetcontact?r=%s&seq=0&skey=%s' % (self .loginInfo ['url' ],
268
- int (time .time ()), self .loginInfo ['skey' ])
269
- headers = {
270
- 'ContentType' : 'application/json; charset=UTF-8' ,
271
- 'User-Agent' : config .USER_AGENT , }
272
- try :
273
- r = self .s .get (url , headers = headers )
274
- except :
275
- logger .info ('Failed to fetch contact, that may because of the amount of your chatrooms' )
276
- return []
277
- tempList = json .loads (r .content .decode ('utf-8' , 'replace' ))['MemberList' ]
267
+ def _get_contact (seq = 0 ):
268
+ url = '%s/webwxgetcontact?r=%s&seq=%s&skey=%s' % (self .loginInfo ['url' ],
269
+ int (time .time ()), seq , self .loginInfo ['skey' ])
270
+ headers = {
271
+ 'ContentType' : 'application/json; charset=UTF-8' ,
272
+ 'User-Agent' : config .USER_AGENT , }
273
+ try :
274
+ r = self .s .get (url , headers = headers )
275
+ except :
276
+ logger .info ('Failed to fetch contact, that may because of the amount of your chatrooms' )
277
+ return 0 , []
278
+ j = json .loads (r .content .decode ('utf-8' , 'replace' ))
279
+ return j .get ('Seq' , 0 ), j .get ('MemberList' )
280
+ seq , memberList = 0 , []
281
+ while 1 :
282
+ seq , batchMemberList = _get_contact (seq )
283
+ memberList .extend (batchMemberList )
284
+ if seq == 0 :
285
+ break
278
286
chatroomList , otherList = [], []
279
- for m in tempList :
287
+ for m in memberList :
280
288
if m ['Sex' ] != 0 :
281
289
otherList .append (m )
282
290
elif '@@' in m ['UserName' ]:
@@ -356,14 +364,15 @@ def add_friend(self, userName, status=2, verifyContent='', autoUpdate=True):
356
364
'VerifyUserTicket' : '' , }],
357
365
'VerifyContent' : verifyContent ,
358
366
'SceneListCount' : 1 ,
359
- 'SceneList' : 33 , # [33]
367
+ 'SceneList' : [33 ],
360
368
'skey' : self .loginInfo ['skey' ], }
361
369
headers = {
362
370
'ContentType' : 'application/json; charset=UTF-8' ,
363
371
'User-Agent' : config .USER_AGENT }
364
372
r = self .s .post (url , headers = headers ,
365
373
data = json .dumps (data , ensure_ascii = False ).encode ('utf8' , 'replace' ))
366
- if autoUpdate : self .update_friend (userName )
374
+ if autoUpdate :
375
+ self .update_friend (userName )
367
376
return ReturnValue (rawResponse = r )
368
377
369
378
def get_head_img (self , userName = None , chatroomUserName = None , picDir = None ):
0 commit comments