test-unicom-carmi-push.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import json
  2. import time
  3. import random
  4. import string
  5. import hashlib
  6. import requests
  7. from aes import MyHash
  8. partnerId = '108463'
  9. partnerKey = 'tdz5xjtmuymkrhbx460iwv8kyw9hasqa'
  10. nonce = ''.join(random.sample(string.ascii_letters+string.digits,32))
  11. #nonce = 'WUKRmNYGcFaqgy7Hl8dbLOMzrSQuPfZ1'
  12. #print(nonce)
  13. cardSecret = ''.join(random.sample(string.ascii_letters+string.digits,32))
  14. #cardSecret = 'GLDSZQ42eX8MB3V1fNsucghj9U5JrRlD'
  15. #key = ''.join(random.sample(string.ascii_letters+string.digits,16))
  16. #print(key)
  17. #key = 'DXH5ozwbLtPuFhnJMdyijSI824k0ExWR'
  18. key = '9lI82q3eBZhdwk7b'
  19. helo = MyHash()
  20. cardSecret = helo.My_Aes_Encrypt(key,cardSecret)
  21. #cardSecret = 'VxuJa8EW4zKfykwt92ZFqToeiLG3gsCY'
  22. facePrice = 30
  23. callbackUrl = 'http://127.0.0.1:9888'
  24. timestamp = int(time.time())
  25. pre_sign = '{}{}{}{}{}{}{}'.format(partnerId,nonce,cardSecret,facePrice,callbackUrl,timestamp,partnerKey)
  26. #print(pre_sign)
  27. sign = hashlib.md5(pre_sign.encode(encoding='UTF-8')).hexdigest()
  28. #print(sign)
  29. data = {
  30. 'partnerId': partnerId,
  31. 'nonce': nonce,
  32. 'cardSecret': cardSecret,
  33. 'facePrice':facePrice,
  34. 'callbackUrl':callbackUrl,
  35. 'timestamp':timestamp,
  36. 'sign':sign
  37. }
  38. data_json = json.dumps(data)
  39. http_header = {
  40. 'Content-Type': 'application/json',
  41. 'Connection': 'close'
  42. }
  43. s = requests.session()
  44. s.keep_alive = False
  45. r_json = requests.post("http://47.108.14.99:8086/unicom/card/secret/push.json", data=data_json, headers=http_header)
  46. #r_json = requests.post("http://localhost:8086/unicom/card/secret/push.json", data=data_json, headers=http_header)
  47. #r_json = requests.post("http://47.108.14.99:8085/sup/order/add", data=data_json, headers=http_header)
  48. print( r_json.text )