helper.py 1.7 KB

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