|
@@ -1,17 +1,15 @@
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
-# 高复用性函数封装到CommonService类
|
|
|
import base64
|
|
|
import datetime
|
|
|
+import ipdb
|
|
|
import time
|
|
|
from base64 import encodebytes
|
|
|
from pathlib import Path
|
|
|
from random import Random
|
|
|
-from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
import OpenSSL.crypto as ct
|
|
|
-import ipdb
|
|
|
import requests
|
|
|
import simplejson as json
|
|
|
+from dateutil.relativedelta import relativedelta
|
|
|
from django.core import serializers
|
|
|
from django.utils import timezone
|
|
|
from pyipip import IPIPDatabase
|
|
@@ -19,15 +17,17 @@ from pyipip import IPIPDatabase
|
|
|
from Ansjer.config import BASE_DIR, SERVER_DOMAIN_SSL, CONFIG_INFO, CONFIG_TEST, CONFIG_CN, SERVER_DOMAIN_TEST, \
|
|
|
SERVER_DOMAIN_CN, SERVER_DOMAIN_US, CONFIG_US, CONFIG_EUR, SERVER_DOMAIN_LIST, SERVER_DOMAIN_EUR
|
|
|
from Controller.CheckUserData import RandomStr
|
|
|
-from Model.models import iotdeviceInfoModel, Device_Info, CountryModel, RegionModel, UIDModel
|
|
|
+from Model.models import iotdeviceInfoModel, Device_Info, UIDModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
|
|
|
|
|
|
class CommonService:
|
|
|
- # 添加模糊搜索
|
|
|
+ # 高复用性函数类
|
|
|
+
|
|
|
@staticmethod
|
|
|
def get_kwargs(data=None):
|
|
|
+ # 添加模糊搜索
|
|
|
if data is None:
|
|
|
data = {}
|
|
|
kwargs = {}
|
|
@@ -36,10 +36,9 @@ class CommonService:
|
|
|
kwargs[k + '__icontains'] = v
|
|
|
return kwargs
|
|
|
|
|
|
- # 定义静态方法
|
|
|
- # 格式化query_set转dict
|
|
|
@staticmethod
|
|
|
def qs_to_dict(query_set):
|
|
|
+ # 格式化query_set转dict
|
|
|
sqlJSON = serializers.serialize('json', query_set)
|
|
|
sqlList = json.loads(sqlJSON)
|
|
|
sqlDict = dict(zip(["datas"], [sqlList]))
|
|
@@ -265,43 +264,37 @@ class CommonService:
|
|
|
return str
|
|
|
|
|
|
@staticmethod
|
|
|
- def decode_data(content, start=1, end=4):
|
|
|
+ def encode_data(content, start=1, end=4):
|
|
|
+ """
|
|
|
+ 数据加密
|
|
|
+ @param content: 数据内容
|
|
|
+ @param start: 起始长度
|
|
|
+ @param end: 结束长度
|
|
|
+ @return content: 加密的数据
|
|
|
+ """
|
|
|
if not content:
|
|
|
return ''
|
|
|
- try:
|
|
|
- for i in range(start, end):
|
|
|
- if i == 1:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[1:-1]
|
|
|
- if i == 2:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[2:-2]
|
|
|
- if i == 3:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[3:-3]
|
|
|
-
|
|
|
- return content
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return None
|
|
|
+ for i in range(start, end):
|
|
|
+ length = end - start
|
|
|
+ content = RandomStr(length, False) + content + RandomStr(length, False)
|
|
|
+ content = base64.b64encode(str(content).encode('utf-8')).decode('utf8')
|
|
|
+ return content
|
|
|
|
|
|
@staticmethod
|
|
|
- def encode_data(content, start=1, end=4):
|
|
|
+ def decode_data(content, start=1, end=4):
|
|
|
+ """
|
|
|
+ 数据解密
|
|
|
+ @param content: 数据内容
|
|
|
+ @param start: 起始长度
|
|
|
+ @param end: 结束长度
|
|
|
+ @return content: 解密的数据
|
|
|
+ """
|
|
|
if not content:
|
|
|
return ''
|
|
|
for i in range(start, end):
|
|
|
- if i == 1:
|
|
|
- content = RandomStr(3, False) + content + RandomStr(3, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
- if i == 2:
|
|
|
- content = RandomStr(2, False) + str(content) + RandomStr(2, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
- if i == 3:
|
|
|
- content = RandomStr(1, False) + str(content) + RandomStr(1, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
+ content = base64.b64decode(content)
|
|
|
+ content = content.decode('utf-8')
|
|
|
+ content = content[i:-i]
|
|
|
return content
|
|
|
|
|
|
# 把格式化时间转换成时间戳
|
|
@@ -347,6 +340,7 @@ class CommonService:
|
|
|
else:
|
|
|
now_month += 1
|
|
|
|
|
|
+ timestamps = 0
|
|
|
for is_format in range(4):
|
|
|
try:
|
|
|
date_format = '{now_year}-{now_month}-{now_day} {now_hour}:{now_min}:{now_second}' \
|
|
@@ -369,11 +363,6 @@ class CommonService:
|
|
|
second = int(macArray[4], 16)
|
|
|
three = int(macArray[3], 16)
|
|
|
|
|
|
- # print(macArray)
|
|
|
- # print(first)
|
|
|
- # print(second)
|
|
|
- # print(three)
|
|
|
-
|
|
|
if first == 255 and second == 255 and three == 255:
|
|
|
return None
|
|
|
|
|
@@ -390,53 +379,10 @@ class CommonService:
|
|
|
macArray[3] = three
|
|
|
macArray[4] = second
|
|
|
macArray[5] = first
|
|
|
- # print(macArray)
|
|
|
|
|
|
tmp = ':'.join(map(lambda x: "%02x" % x, macArray))
|
|
|
- # print(tmp)
|
|
|
return tmp.upper()
|
|
|
|
|
|
- @staticmethod
|
|
|
- def decode_data(content, start=1, end=4):
|
|
|
- if not content:
|
|
|
- return ''
|
|
|
- try:
|
|
|
- for i in range(start, end):
|
|
|
- if i == 1:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[1:-1]
|
|
|
- if i == 2:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[2:-2]
|
|
|
- if i == 3:
|
|
|
- content = base64.b64decode(content)
|
|
|
- content = content.decode('utf-8')
|
|
|
- content = content[3:-3]
|
|
|
- print(content)
|
|
|
-
|
|
|
- return content
|
|
|
- except Exception as e:
|
|
|
- print(e)
|
|
|
- return None
|
|
|
-
|
|
|
- @staticmethod
|
|
|
- def encode_data(content, start=1, end=4):
|
|
|
- if not content:
|
|
|
- return ''
|
|
|
- for i in range(start, end):
|
|
|
- if i == 1:
|
|
|
- content = CommonService.RandomStr(3, False) + content + CommonService.RandomStr(3, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
- if i == 2:
|
|
|
- content = CommonService.RandomStr(2, False) + str(content) + CommonService.RandomStr(2, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
- if i == 3:
|
|
|
- content = CommonService.RandomStr(1, False) + str(content) + CommonService.RandomStr(1, False)
|
|
|
- content = base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
|
- return content
|
|
|
-
|
|
|
@staticmethod
|
|
|
def encode_data_without_salt(content):
|
|
|
return base64.b64encode(str(content).encode("utf-8")).decode('utf8')
|
|
@@ -631,13 +577,13 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
|
|
|
@return: region_id
|
|
|
"""
|
|
|
region_id = 3
|
|
|
- if CONFIG_INFO == CONFIG_US: # 美洲
|
|
|
+ if CONFIG_INFO == CONFIG_US: # 美洲
|
|
|
region_id = 3
|
|
|
- elif CONFIG_INFO == CONFIG_EUR: # 欧洲
|
|
|
+ elif CONFIG_INFO == CONFIG_EUR: # 欧洲
|
|
|
region_id = 4
|
|
|
- elif CONFIG_INFO == CONFIG_CN: # 中国
|
|
|
+ elif CONFIG_INFO == CONFIG_CN: # 中国
|
|
|
region_id = 1
|
|
|
- elif CONFIG_INFO == CONFIG_TEST: # 测试
|
|
|
+ elif CONFIG_INFO == CONFIG_TEST: # 测试
|
|
|
region_id = 5
|
|
|
return region_id
|
|
|
|
|
@@ -745,11 +691,9 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
|
|
|
"""
|
|
|
if order_type == 0:
|
|
|
content = content + '(' + '云存' + ')'
|
|
|
- return content
|
|
|
+ return content
|
|
|
elif order_type == 1:
|
|
|
content = content + '(' + 'AI' + ')'
|
|
|
return content
|
|
|
elif order_type == 2:
|
|
|
pass
|
|
|
-
|
|
|
-
|