Advertisement
six519

Voucher Catalogue API

Nov 22nd, 2011
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import sha
  2. from time import gmtime, strftime
  3.  
  4.  
  5. def getTPSTimeString():
  6.    
  7.     return strftime("%Y%m%d%H%M",gmtime())[0:11]
  8.  
  9. def voucher_catalogue(str_timestamp = None):
  10.    
  11.     voucherServer = 'http://tct-testing-tps.hk.kitesystems.com:8080/voucher-testing2/api/catalogue'
  12.     data = {}
  13.    
  14.     if str_timestamp is not None:
  15.         data['timestamp'] = str_timestamp
  16.        
  17.     data['app_name'] = 'WALLET_TO_VOUCHER'
  18.    
  19.     sha1 = sha.new()
  20.     if str_timestamp is not None:
  21.         sha1.update(str(str_timestamp))
  22.     else:
  23.         sha1.update(str(""))
  24.        
  25.     sha1.update('WALLET_TO_VOUCHER')
  26.     sha1.update('492DDE365315631F')
  27.     sha1.update(str(getTPSTimeString()))
  28.    
  29.     data['session_control'] = str(sha1.hexdigest())
  30.  
  31.     try:
  32.         urllib_request = urllib2.Request(voucherServer,urllib.urlencode(data))
  33.         response = urllib2.urlopen(urllib_request).read()
  34.  
  35.         catalogue = Catalogue()
  36.         catalogue.ParseFromString(response)
  37.        
  38.         if not catalogue.success:
  39.             return False
  40.         else:
  41.             return catalogue
  42.     except Exception as e:
  43.         return False
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement