helper.py 1.6 KB

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