6060 'pt_verifysession_v1' : 'e8dd4fef1f230072429cae05732530ef5d7df5fa61660a7311235e2315409046d556365705db19ae32cd082739370abd93a5f90e5a174a5a' ,
6161}
6262
63+ qq_hash = ''
64+
6365# 保持会话
6466s = requests .session ()
6567
@@ -142,6 +144,27 @@ def check_sign(url):
142144 return response
143145
144146
147+ def get_session_id ():
148+ """
149+ 获取sessionId
150+ :return:
151+ """
152+ session_id_url = 'http://d.web2.qq.com/channel/login2'
153+ header ['Host' ] = 'd.web2.qq.com'
154+ header ['Origin' ] = 'http://d.web2.qq.com'
155+ header ['Referer' ] = 'http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2'
156+ session_id_dict = {
157+ "ptwebqq" : ptwebqq ,
158+ "clientid" : ClientID ,
159+ "psessionid" : "" ,
160+ "status" : "online"
161+ }
162+ session_id_payload = {'r' : json .dumps (session_id_dict )}
163+ response = s .post (session_id_url , data = session_id_payload , headers = header )
164+ data = json .loads (response .content )
165+ return data ['result' ]['psessionid' ]
166+
167+
145168def get_self_info ():
146169 """
147170 获取个人信息
@@ -154,6 +177,10 @@ def get_self_info():
154177
155178
156179def get_vf_web_qq ():
180+ """
181+ 获取验证令牌
182+ :return:
183+ """
157184 vf_web_qq_url = 'http://s.web2.qq.com/api/getvfwebqq'
158185 vf_web_qq_payload = {
159186 'ptwebqq' : ptwebqq , # 从cookie中获取
@@ -167,7 +194,11 @@ def get_vf_web_qq():
167194
168195
169196def get_hash (x , K ):
170- x += ""
197+ """
198+ 获取hash令牌(由js转化过来)
199+ 获取群组信息,好友信息需要用到
200+ """
201+ # x += ""
171202 N = [0 , 0 , 0 , 0 ]
172203 for T in range (0 , len (K )):
173204 N [T % 4 ] ^= ord (K [T ])
@@ -193,22 +224,57 @@ def get_hash(x, K):
193224
194225
195226def get_group_info ():
227+ """
228+ 获取群组信息
229+ """
196230 group_info_url = 'http://s.web2.qq.com/api/get_group_name_list_mask2'
197- group_info_payload = {'r' : json .dumps ({"vfwebqq" : vfwebqq , "hash" : "075E5863516A0EBD" })}
198- # todo hash值如何获得
231+ group_info_payload = {'r' : json .dumps ({"vfwebqq" : vfwebqq , "hash" : qq_hash })}
199232 header ['Host' ] = 's.web2.qq.com'
200233 header ['Origin' ] = 'http://s.web2.qq.com'
201234 header ['Referer' ] = 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1'
202235 response = s .post (group_info_url , data = group_info_payload , headers = header )
203- print json .dumps ({"vfwebqq" : vfwebqq , "hash" : "585E0863526A5ABD" })
204- print response .content
236+ print json .dumps ({"vfwebqq" : vfwebqq , "hash" : qq_hash })
205237 return json .loads (response .content )
206238
207239
240+ def get_friends_info ():
241+ friends_info_url = 'http://s.web2.qq.com/api/get_user_friends2'
242+ friends_info_payload = {'r' : json .dumps ({"vfwebqq" : vfwebqq , "hash" : qq_hash })}
243+ header ['Host' ] = 's.web2.qq.com'
244+ header ['Origin' ] = 'http://s.web2.qq.com'
245+ header ['Referer' ] = 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1'
246+ response = s .post (friends_info_url , data = friends_info_payload , headers = header )
247+ print json .dumps ({"vfwebqq" : vfwebqq , "hash" : qq_hash })
248+ return json .loads (response .content )
249+
250+
251+ def send_group_msg (group_uin , msg ):
252+ """
253+ 发送群消息
254+ """
255+ group_msg_url = 'http://d.web2.qq.com/channel/send_qun_msg2'
256+ header ['Host' ] = 'd.web2.qq.com'
257+ header ['Origin' ] = 'http://d.web2.qq.com'
258+ header ['Referer' ] = 'http://d.web2.qq.com/proxy.html?v=20130916001&callback=1&id=2'
259+ group_msg_dict = {
260+ "group_uin" : group_uin ,
261+ "content" : "[\" " + msg + "\" ,[\" font\" ,{\" name\" :\" 宋体\" ,\" size\" :10,\" style\" :[0,0,0],\" color\" :\" 000000\" }]]" ,
262+ "face" : 0 ,
263+ "clientid" : ClientID ,
264+ "msg_id" : 52880001 , # todo 这个值怎么确定?
265+ "psessionid" : PSessionID
266+ }
267+ group_msg_payload = {'r' : json .dumps (group_msg_dict )}
268+ response = s .post (group_msg_url , data = group_msg_payload , headers = header )
269+ return json .loads (response .content )
270+
271+
272+
208273if __name__ == "__main__" :
209274 # 设置账号密码
210275 NAME = 455091702
211276 PASS = '123456'
277+ PASS = '5257(@!L!^G'
212278 ClientID = 53999199
213279 AppID = 1003903
214280 PSessionID = ''
@@ -262,8 +328,15 @@ def get_group_info():
262328 vfwebqq = get_vf_web_qq ()
263329 print vfwebqq
264330
265- print get_group_info ()
331+ qq_hash = get_hash (NAME , ptwebqq )
332+
333+ group_info = get_group_info ()
334+ print json .dumps (group_info , ensure_ascii = False , indent = 4 )
335+
336+ friends_info = get_friends_info ()
337+ print json .dumps (friends_info , ensure_ascii = False , indent = 4 )
266338
339+ PSessionID = get_session_id ()
267340
268341
269342
0 commit comments