您最多能選擇 25 個主題 主題必須以字母或數字為開頭,可包含連接號「-」且最長為 35 個字元。

164 行
3.7 KiB

2 年前
import hashlib
import platform
import random
import socket
from datetime import datetime
import sys
import os
from http.cookies import SimpleCookie
import json
import re
from tools.ModifiedBase64 import ModifiedBase64
def text_to_json(text, regex):
pattern = re.compile(regex)
text_list = re.findall(pattern, text)
_json = json.loads(text_list[0])
return _json
def remove_unused_symbol(text):
return text.replace('\n', '').replace('\r', '').replace('\t', '')
def remove_redundant_comma(text):
"""
移除json多余逗号避免json.loads报错
"""
rex = r"""(?<=[}\]"'])\s*,\s*(?!\s*[{["'])"""
return re.sub(rex, "", text, 0)
def resource_path(relative_path):
if getattr(sys, 'frozen', False):
base_path = sys._MEIPASS
else:
base_path = os.path.abspath("../..")
return os.path.join(base_path, relative_path)
def export_file_name():
return "ck-export-" + datetime.now().strftime('%Y%m%d%H%M%S') + ".txt"
def desktop_path():
if platform.system() == 'Windows':
return r"C:\Users\Administrator\Desktop"
else:
return "/Users/xiaoqingsong/Desktop"
def is_json(text):
if text is None:
return False
try:
json.loads(text)
except ValueError:
return False
return True
def getTimeStamp(time):
"""
:param time: 形如 2021-01-20 10:10:20.120
:return:
"""
ts = datetime.timestamp(datetime.strptime(time, '%Y-%m-%d %H:%M:%S.%f'))
return int(ts * 1000)
def getTimeStamp(time, format):
"""
:param format: %Y-%m-%d %H:%M:%S
:param time: 形如 2021-01-20 10:10:20
:return:
"""
ts = datetime.timestamp(datetime.strptime(time, format))
return int(ts * 1000)
def getNowTime():
return datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-7]
def getCookieFromStr(rawStr):
cookie = SimpleCookie()
cookie.load(rawStr)
# Even though SimpleCookie is dictionary-like, it internally uses a Morsel object
# which is incompatible with requests. Manually construct a dictionary instead.
cookies = {}
for key, morsel in cookie.items():
cookies[key] = morsel.value
return cookies
def get_random_number_str(length):
"""
生成随机数字字符串
:param length: 字符串长度
:return:
"""
num_str = ''.join(str(random.choice(range(10))) for _ in range(length))
return num_str
def randomUUID():
random_number = get_random_number_str(15)
random_str = hashlib.md5(random_number.encode('utf-8')).hexdigest()[:12]
return random_number + "-" + random_str
def get_host_ip():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
def mb_encrypt(str):
v = ModifiedBase64()
return v.m23207r(str)
def get_ep(ts, uuid):
area = '13_1000_40488_54435'
d_model = 'PDNM00'
wifiBssid = 'unknown'
osVersion = '11'
d_brand = 'OPPO'
screen = '2161*1080'
uuid = uuid
aid = uuid
openudid = uuid
hdid = ''
ep = {
'hdid': mb_encrypt(hdid),
'ts': ts,
'ridx': -1,
'cipher': {
'area': mb_encrypt(area),
'd_model': mb_encrypt(d_model),
'wifiBssid': mb_encrypt(wifiBssid),
'osVersion': mb_encrypt(osVersion),
'd_brand': mb_encrypt(d_brand),
'screen': mb_encrypt(screen),
'uuid': mb_encrypt(uuid),
'aid': mb_encrypt(aid),
'openudid': mb_encrypt(openudid),
},
'ciphertype': 5,
'version': '1.2.0',
'appname': 'com.jingdong.app.mall',
}
return ep