-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_card_info.py
55 lines (40 loc) · 1.2 KB
/
fetch_card_info.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
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import urllib2
import urllib
import json
import hashlib
import sys
'''
fetch bank card info
'''
card_data = {
'card_no': '62169143016218fds',
}
url='https://www..com/api/fetchCardInfo'
secret_key = 'xxxxx'
def createSign(card_data):
sorted_data = sorted(card_data.items(),key=lambda item:item[0])
str = ''
for val in sorted_data:
str += val[0] + '=' + val[1] + '&'
str = str.rstrip('&')
str += secret_key
sign = hashlib.md5(str).hexdigest()
return sign
def getCardInfo(card_data):
req = urllib2.Request(url)
data = urllib.urlencode(card_data)
#enable cookie
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
response = opener.open(req, data)
return json.loads(response.read())
if __name__ == '__main__':
print '-------- four elements check card--------'
card_data['sign'] = createSign(card_data)
print 'request data:'
for key,value in card_data.iteritems():
print "\t" + key + ' : ' + value
print '--------------------------------------------'
response = getCardInfo(card_data)
print json.dumps(response,sort_keys=True,indent=4, separators=(',', ': '))