helper.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import hashlib
  2. import json
  3. # import requests
  4. from requests_futures.sessions import FuturesSession
  5. class Helper(object):
  6. @staticmethod
  7. def async_post(url, params):
  8. # try:
  9. # fs_session = FuturesSession()
  10. # data = fs_session.post(url, data={"data": json.dumps(params), "token": "u4Gdf015662654065d5b503ea2517"}, timeout=180).result()
  11. # if data:
  12. # return data.content.decode('utf-8')
  13. # except requests.exceptions.RequestException as e:
  14. # print(e)
  15. fs_session = FuturesSession()
  16. data = fs_session.post(url, data={"data": json.dumps(params), "token": "u4Gdf015662654065d5b503ea2517"}, timeout=180).result()
  17. try:
  18. new_data = data.json()
  19. except Exception as e:
  20. print(e)
  21. new_data = {"status": 0, "msg": "接口返回异常", "data": []}
  22. return new_data
  23. @staticmethod
  24. def genearte_MD5(params, pt):
  25. # 创建md5对象
  26. hl = hashlib.md5()
  27. pn = int(pt)
  28. if pn == 3:
  29. param = params + str(pt)
  30. else:
  31. param = params
  32. hl.update(param.encode(encoding='utf-8'))
  33. return hl.hexdigest()
  34. @staticmethod
  35. def genearte_uuid(params):
  36. hl = hashlib.md5()
  37. hl.update(params.encode(encoding='utf-8'))
  38. return hl.hexdigest()