#weixin.py
#coding:utf-8
# !/usr/bin/env python
# coding=utf-8
#通过该程序可以发现被删除的好友
import os
import urllib, urllib2
import re
import cookielib
import time
import xml.dom.minidom
import json
import sys
import math
DEBUG = False
MAX_GROUP_NUM = 35 # 每组人数
QRImagePath = os.getcwd() + '/qrcode.jpg'
tip = 0
uuid = ''
base_uri = ''
redirect_uri = ''
skey = ''
wxsid = ''
wxuin = ''
pass_ticket = ''
deviceId = 'e000000000000000'
BaseRequest = {}
ContactList = []My = []
def getUUID():
global uuid
url = 'https://login./jslogin'
params = {
'appid': 'wx782c26e4c19acffb',
'fun': 'new',
'lang': 'zh_CN',
'_': int(time.time()),
}
request = urllib2.Request(url=url, data=urllib.urlencode(params))
response = urllib2.urlopen(request)
data = response.read()
# print data
# window.QRLogin.code = 200; window.QRLogin.uuid = "oZwt_bFfRg==";
regx = r'window.QRLogin.code = (d+); window.QRLogin.uuid = "(S+?)"'
pm = re.search(regx, data)
code = pm.group(1)
uuid = pm.group(2)
if code == '200':
return True
return False
def showQRImage():
global tip
url = 'https://login./qrcode/' + uuid
params = {
't': 'webwx',
'_': int(time.time()),
}
request = urllib2.Request(url=url, data=urllib.urlencode(params))
response = urllib2.urlopen(request)
tip = 1
f = open(QRImagePath, 'wb')
f.write(response.read())
f.close()
if sys.platform.find('darwin') >= 0:
os.system('open %s' % QRImagePath)
elif sys.platform.find('linux') >= 0:
os.system('xdg-open %s' % QRImagePath)
else:
os.system('call %s' % QRImagePath)
print '请使用微信扫描二维码以登录'
def waitForLogin():
global tip, base_uri, redirect_uri
url = 'https://login./cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s' % (tip, uuid, int(time.time()))
request = urllib2.Request(url=url)
response = urllib2.urlopen(request)
data = response.read()
# print data
# window.code=500;
regx = r'window.code=(d+);'
pm = re.search(regx, data)
code = pm.group(1)
if code == '201': # 已扫描
print '成功扫描,请在手机上点击确认以登录'
tip = 0
elif code == '200': # 已登录
print '正在登录...'
regx = r'window.redirect_uri="(S+?)";'
pm = re.search(regx, data)
redirect_uri = pm.group(1) + '&fun=new'
base_uri = redirect_uri[:redirect_uri.rfind('/')] elif code == '408': # 超时