helper.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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:
  20. new_data = {"status": 0, "msg": "接口返回异常", "data": []}
  21. return new_data
  22. @staticmethod
  23. def genearte_MD5(params, pt):
  24. # 创建md5对象
  25. hl = hashlib.md5()
  26. pn = int(pt)
  27. if pn == 3:
  28. param = params + str(pt)
  29. else:
  30. param = params
  31. hl.update(param.encode(encoding='utf-8'))
  32. return hl.hexdigest()
  33. @staticmethod
  34. def genearte_uuid(params):
  35. hl = hashlib.md5()
  36. hl.update(params.encode(encoding='utf-8'))
  37. return hl.hexdigest()