Преглед на файлове

根据app_bundle_id返回对应域名

locky преди 2 години
родител
ревизия
7986b2910b
променени са 2 файла, в които са добавени 52 реда и са изтрити 96 реда
  1. 15 3
      Controller/UserManger.py
  2. 37 93
      Service/CommonService.py

+ 15 - 3
Controller/UserManger.py

@@ -12,7 +12,7 @@ from django.views.generic import TemplateView, View
 
 from Ansjer.config import BASE_DIR, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, AVATAR_BUCKET
 from Ansjer.config import SERVER_DOMAIN
-from Model.models import Role, Device_User, UserOauth2Model, UserExModel, CountryLanguageModel, LanguageModel
+from Model.models import Role, Device_User, UserOauth2Model, UserExModel, CountryLanguageModel, LanguageModel, App_Info
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
@@ -37,6 +37,7 @@ class showUserMoreView(TemplateView):
         response = ResponseObject()
         token = request_dict.get('token', None)
         lang = request_dict.get('lang', 'en')
+        app_bundle_id = request_dict.get('app_bundle_id', None)
 
         tko = TokenObject(token)
         response.lang = tko.lang
@@ -46,14 +47,15 @@ class showUserMoreView(TemplateView):
         if not user_id:
             return response.json(104)
 
-        return self.show_user_more(user_id, lang, response)
+        return self.show_user_more(user_id, lang, app_bundle_id, response)
 
     @staticmethod
-    def show_user_more(user_id, lang, response):
+    def show_user_more(user_id, lang, app_bundle_id, response):
         """
         获取用户完整信息
         @param user_id: 用户id
         @param lang: 语言
+        @param app_bundle_id: app包id
         @param response: 响应
         @return: response
         """
@@ -90,6 +92,16 @@ class showUserMoreView(TemplateView):
                     sqlDict["datas"][k]['fields']['api'] = country_qs[0]['country__region__api']
                     if region_country == 1:     # 中国返回美洲域名
                         sqlDict["datas"][k]['fields']['api'] = 'https://www.dvema.com/'
+                    # 根据app_bundle_id返回对应域名
+                    if app_bundle_id:
+                        # 查询app名
+                        app_inf_qs = App_Info.objects.filter(appBundleId=app_bundle_id).values('appName')
+                        if app_inf_qs.exists():
+                            app_name = app_inf_qs[0]['appName']
+                            if 'Zosi' in app_name:
+                                sqlDict['datas'][k]['fields']['api'] = country_qs[0]['country__region__zosi_api']
+                            elif 'Loocam' in app_name:
+                                sqlDict['datas'][k]['fields']['api'] = country_qs[0]['country__region__loocam_api']
 
                     # region数据
                     region_country = sqlDict['datas'][k]['fields']['region_country']

+ 37 - 93
Service/CommonService.py

@@ -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
-
-