-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth3.py
71 lines (58 loc) · 1.87 KB
/
auth3.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
67
68
69
70
71
# -*- coding:utf-8 -*-
import hashlib
import base64
import time
import urllib.request, sys, re, os, json
from pyDes import *
url = "http://identify-auth.zztfly.com/auth/auth/sdkClientFreeLogin"
appkey = ""
appSecret = ""
token = "59616292321333248"
opToken = "opToken"
operator = "CUCC"
md5 = ""
class NoExceptionCookieProcesser(urllib.request.HTTPCookieProcessor):
def http_error_403(self, req, fp, code, msg, hdrs):
return fp
def http_error_400(self, req, fp, code, msg, hdrs):
return fp
def http_error_404(self, req, fp, code, msg, hdrs):
return fp
def http_error_500(self, req, fp, code, msg, hdrs):
return fp
def generateSign(request, secret):
if type(request) != dict or type(secret) != str:
raise Exception("type error")
ret = ""
stmp = sorted(request.items(), key=lambda d: d[0])
for i in stmp:
ret += i[0] + "=" + str(i[1]) + "&"
print(ret[:-1])
return hashlib.md5((ret[:-1] + secret).encode('utf-8')).hexdigest()
def getPhone():
opener = urllib.request.build_opener(NoExceptionCookieProcesser())
method = urllib.request.Request(url)
method.add_header('Content-Type', 'application/json')
data = {
'appkey': appkey,
'token': token,
'opToken': opToken,
'operator': operator,
'timestamp': int(time.time()*1000)
}
if md5 != "":
data['md5'] = md5
data['sign'] = generateSign(data, appSecret)
result = None;
try:
result = opener.open(method, json.dumps(data).encode('utf-8'), timeout=100)
except Exception as err:
print(err)
data = result.read()
ret = json.loads(data)
if ret['status'] == 200:
k = des(appSecret[:8], CBC, "00000000", pad=None, padmode=PAD_PKCS5)
ret['res'] = k.decrypt(base64.b64decode(ret['res']))
return data
if __name__ == "__main__":
print(getPhone())