-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_dama.py
66 lines (52 loc) · 2.02 KB
/
auto_dama.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 打码兔自动打码平台
import hashlib
import urllib.request
import urllib
import json
import base64
def md5str(str): # md5加密字符串
m = hashlib.md5(str.encode(encoding="utf-8"))
return m.hexdigest()
def md5(byte): # md5加密byte
return hashlib.md5(byte).hexdigest()
class DamatuApi():
ID = '***'
KEY = '*************'
HOST = '************'
def __init__(self, username, password):
self.username = username
self.password = password
def getSign(self, param=b''):
return (md5(bytes(self.KEY, encoding="utf8") + bytes(self.username, encoding="utf8") + param))[:8]
def getPwd(self):
return md5str(self.KEY + md5str(md5str(self.username) + md5str(self.password)))
def post(self, path, params={}):
data = urllib.parse.urlencode(params).encode('utf-8')
url = self.HOST + path
response = urllib.request.Request(url, data)
return urllib.request.urlopen(response).read()
# 上传验证码 参数filePath 验证码图片路径 如d:/1.jpg type是类型,查看http://wiki.dama2.com/index.php?n=ApiDoc.Pricedesc return 是答案为成功 如果为负数 则为错误码
def decode(self, filePath, type):
f = open(filePath, 'rb')
fdata = f.read()
filedata = base64.b64encode(fdata)
f.close()
data = {'appID': self.ID,
'user': self.username,
'pwd': dmt.getPwd(),
'type': type,
'fileDataBase64': filedata,
'sign': dmt.getSign(fdata)
}
res = self.post('d2File', data)
res = str(res, encoding="utf-8")
jres = json.loads(res)
if jres['ret'] == 0:
# 注意这个json里面有ret,id,result,cookie,根据自己的需要获取
return (jres['result'])
else:
return jres['ret']
# 实例化类型 参数是打码兔用户账号和密码
dmt = DamatuApi("*****", "*****")
def auto_verification():
return dmt.decode('pic.jpg', 42)