@@ -31,13 +31,15 @@ def login(self, enableCmdQR=False, picDir=None, qrCallback=None,
31
31
logger .warning ('itchat has already logged in.' )
32
32
return
33
33
while 1 :
34
- logger .info ('Getting uuid of QR code.' )
35
- while not self .get_QRuuid ():
36
- time .sleep (1 )
37
- logger .info ('Downloading QR code.' )
38
- qrStorage = self .get_QR (enableCmdQR = enableCmdQR ,
39
- picDir = picDir , qrCallback = qrCallback )
40
- logger .info ('Please scan the QR code to log in.' )
34
+ uuid = push_login (self )
35
+ if not uuid :
36
+ logger .info ('Getting uuid of QR code.' )
37
+ while not self .get_QRuuid ():
38
+ time .sleep (1 )
39
+ logger .info ('Downloading QR code.' )
40
+ qrStorage = self .get_QR (enableCmdQR = enableCmdQR ,
41
+ picDir = picDir , qrCallback = qrCallback )
42
+ logger .info ('Please scan the QR code to log in.' )
41
43
isLoggedIn = False
42
44
while not isLoggedIn :
43
45
status = self .check_login ()
@@ -53,7 +55,8 @@ def login(self, enableCmdQR=False, picDir=None, qrCallback=None,
53
55
break
54
56
if isLoggedIn :
55
57
break
56
- logger .info ('Log in time out, reloading QR code' )
58
+ logger .info ('Log in time out, reloading QR code.' )
59
+ logger .info ('Loading the contact, this may take a little while.' )
57
60
self .web_init ()
58
61
self .show_mobile_login ()
59
62
self .get_contact (True )
@@ -66,6 +69,18 @@ def login(self, enableCmdQR=False, picDir=None, qrCallback=None,
66
69
logger .info ('Login successfully as %s' % self .storageClass .nickName )
67
70
self .start_receiving (exitCallback )
68
71
72
+ def push_login (core ):
73
+ cookiesDict = core .s .cookies .get_dict ()
74
+ if 'wxuin' in cookiesDict :
75
+ url = '%s/cgi-bin/mmwebwx-bin/webwxpushloginurl?uin=%s' % (
76
+ config .BASE_URL , cookiesDict ['wxuin' ])
77
+ headers = { 'User-Agent' : config .USER_AGENT }
78
+ r = core .s .get (url , headers = headers ).json ()
79
+ if 'uuid' in r and r .get ('ret' ) in (0 , '0' ):
80
+ core .uuid = r ['uuid' ]
81
+ return r ['uuid' ]
82
+ return False
83
+
69
84
def get_QRuuid (self ):
70
85
url = '%s/jslogin' % config .BASE_URL
71
86
params = {
@@ -168,6 +183,22 @@ def web_init(self):
168
183
for item in dic ['SyncKey' ]['List' ]])
169
184
self .storageClass .userName = dic ['User' ]['UserName' ]
170
185
self .storageClass .nickName = dic ['User' ]['NickName' ]
186
+ # deal with contact list returned when init
187
+ contactList = dic .get ('ContactList' , [])
188
+ chatroomList , otherList = [], []
189
+ for m in contactList :
190
+ if m ['Sex' ] != 0 :
191
+ otherList .append (m )
192
+ elif '@@' in m ['UserName' ]:
193
+ m ['MemberList' ] = [] # don't let dirty info pollute the list
194
+ chatroomList .append (m )
195
+ elif '@' in m ['UserName' ]:
196
+ # mp will be dealt in update_local_friends as well
197
+ otherList .append (m )
198
+ if chatroomList :
199
+ update_local_chatrooms (self , chatroomList )
200
+ if otherList :
201
+ update_local_friends (self , otherList )
171
202
return dic
172
203
173
204
def show_mobile_login (self ):
@@ -195,12 +226,13 @@ def maintain_loop():
195
226
if i is None :
196
227
self .alive = False
197
228
elif i == '0' :
198
- continue
229
+ pass
199
230
else :
200
231
msgList , contactList = self .get_msg ()
201
232
if msgList :
202
233
msgList = produce_msg (self , msgList )
203
- for msg in msgList : self .msgList .put (msg )
234
+ for msg in msgList :
235
+ self .msgList .put (msg )
204
236
if contactList :
205
237
chatroomList , otherList = [], []
206
238
for contact in contactList :
0 commit comments