-
Notifications
You must be signed in to change notification settings - Fork 3
/
geetest.py
31 lines (29 loc) · 968 Bytes
/
geetest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!coding:utf8
from hashlib import md5
import time
import urllib2
class geetest(object):
"""docstring for gt"""
def __init__(self, key):
self.PRIVATE_KEY=key
def geetest_validate(self,challenge,validate,seccode):
apiserver="http://api.geetest.com/validate.php"
if validate == self.md5value(self.PRIVATE_KEY+'geetest'+challenge):
query='seccode='+seccode
backinfo=self.postvalues(apiserver,query)
if backinfo == self.md5value(seccode):
return 1
else:
return 0
else:
return 0
def postvalues(self,apiserver,data):
req = urllib2.Request(apiserver)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
response = opener.open(req, data)
backinfo = response.read()
return backinfo
def md5value(self,values):
m=md5()
m.update(values)
return m.hexdigest()