| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import hashlib
- import json
- import time
- from requests_futures.sessions import FuturesSession
- from .langconv import *
- from .LocalToken import token
- class Helper(object):
- @staticmethod
- def async_post(url, params):
- fs_session = FuturesSession()
- t_url, t_user, t_password, t_token = token['token_url'], token['username'], token['password'], token['token']
- data = fs_session.post(url, data={"data": json.dumps(params), "token": t_token}, timeout=180).result()
- try:
- new_data = data.json()
- if new_data.get('status') == 6:
- t_data = fs_session.post(url=t_url, data={'account': t_user, 'password': t_password}).result()
- if t_data.json().get('status') == 1:
- g_token = t_data.json()['data']['token']
- token['token'] = g_token
- with open('./utils/LocalToken.py', 'w+', encoding='utf8') as f:
- f.write('token = {}'.format(token))
- except Exception as e:
- print(e)
- new_data = {"status": 0, "msg": "接口返回异常", "data": []}
- return new_data
- @staticmethod
- def genearte_MD5(params, pt=0):
- # 创建md5对象
- hl = hashlib.md5()
- pn = int(pt)
- if pn == 3:
- param = params + str(pt)
- else:
- param = params
- hl.update(param.encode(encoding='utf-8'))
- return hl.hexdigest()
- @staticmethod
- def genearte_uuid(params):
- # 简体
- line = Converter("zh-hans").convert(params).replace(' ', '')
- # 繁体
- # line = Converter("zh-hant").convert(params).replace(' ', '')
- hl = hashlib.md5()
- hl.update(line.encode(encoding='utf-8'))
- return hl.hexdigest()
- @staticmethod
- def change_time(ctime):
- time1 = time.mktime(time.strptime(ctime, '%Y-%m-%d %H:%M:%S')) + 43200
- time2 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time1))
- match_date = time2.split(" ")[0]
- match_time = time2.split(" ")[1]
- return match_date, match_time, time2
|