import urllib,urllib2
from urllib2 import *
import cookielib
import hashlib,math
import json
def hex_md5hash(str):
return hashlib.md5(str).hexdigest().upper()
cookies = cookielib.MozillaCookieJar()
url = 'http://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN'
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'),(
'Referer', 'http://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm-login&lang=zh_CN')]
urllib2.install_opener(opener)
data = {
'username':account,
'pwd1':hex_md5hash(password[:15]).lower(),
'pwd2':hex_md5hash(password).lower(),
'imgcode':'',
'f':'json',
}
request = urllib2.Request(url,urllib.urlencode(data))
response = urllib2.urlopen(request)
json_data = json.load(response)
print json_data
open('1.png','wb').write(urllib2.urlopen('http://mp.weixin.qq.com/cgi-bin/verifycode?username=2237746894&r='+str(int(time.time() * 1000))).read())
imgcode = raw_input('>>')
print imgcode
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
opener.addheaders = [('User-agent', 'Mozilla/5.0'),('Referer', 'http://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm-login&lang=zh_CN')
]
urllib2.install_opener(opener)
data = {
'username':account,
'pwd1':hex_md5hash(password[:15]).lower(),
'pwd2':hex_md5hash(password).lower(),
'imgcode':imgcode,
'f':'json',
}
request = urllib2.Request(url,urllib.urlencode(data))
response = urllib2.urlopen(request)
json_data = json.load(response)
print json_data