浏览代码

完善返回域名接口

locky 2 年之前
父节点
当前提交
e534431b63
共有 2 个文件被更改,包括 43 次插入25 次删除
  1. 41 25
      Controller/RegionController.py
  2. 2 0
      Model/models.py

+ 41 - 25
Controller/RegionController.py

@@ -3,9 +3,10 @@
 import json
 import time
 
+from django.db.models import F
 from django.views import View
 
-from Model.models import RegionModel, CountryModel, LanguageModel, CountryLanguageModel
+from Model.models import RegionModel, CountryModel, LanguageModel, CountryLanguageModel, App_Info
 from Object.uidManageResponseObject import uidManageResponseObject
 from Object.TokenObject import TokenObject
 from Service.CommonService import CommonService
@@ -27,13 +28,11 @@ class RegionView(View):
         return self.validate(request_dict, operation)
 
     def validate(self, request_dict, operation):
-        token = TokenObject(request_dict.get('token', None))
-
         response = uidManageResponseObject()
-
-        if operation == 'getCountry':
+        if operation == 'getCountryAndDomainName':
             return self.get_country(request_dict, response)
         else:
+            token = TokenObject(request_dict.get('token', None))
             if token.code != 0:
                 return response.json(token.code)
 
@@ -254,32 +253,49 @@ class RegionView(View):
         else:
             return response.json(444)
 
-    def get_country(self, request_dict, response):
-        type = request_dict.get('type', None)
-        token = request_dict.get('token', None)
+    @staticmethod
+    def get_country(request_dict, response):
+        lang = request_dict.get('lang', None)
+        app_bundle_id = request_dict.get('app_bundle_id', None)
         time_stamp = request_dict.get('time_stamp', None)
+        time_stamp_token = request_dict.get('time_stamp_token', None)
 
-        if not all([token, time_stamp, type]):
+        if not all([lang, app_bundle_id, time_stamp, time_stamp_token]):
             return response.json(444)
 
-        token = int(CommonService.decode_data(token))
-        time_stamp = int(time_stamp)
-
-        now_time = int(time.time())
-        distance = now_time - time_stamp
-
-        if token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
-            return response.json(404)
-
-        lang_qs = LanguageModel.objects.filter(lang=type)
+        try:
+            # 校验时间戳token
+            time_stamp_token = int(CommonService.decode_data(time_stamp_token))
+            time_stamp = int(time_stamp)
+            now_time = int(time.time())
+            distance = now_time - time_stamp
+            if time_stamp_token != time_stamp or distance > 60000 or distance < -60000:  # 为了全球化时间控制在一天内
+                return response.json(404)
 
-        if not lang_qs.exists():
-            lang_qs = LanguageModel.objects.filter(lang='en')
+            # 查询app名
+            app_inf_qs = App_Info.objects.filter(appBundleId=app_bundle_id).values('appName')
+            if not app_inf_qs.exists():
+                return response.json(173)
 
-        lang = lang_qs[0]
-        country_qs = CountryLanguageModel.objects.filter(language_id=lang.id).\
-            values('country_name', 'country__number', 'country__region__api', 'country__region__push_api')
-        return response.json(0, list(country_qs))
+            lang_qs = LanguageModel.objects.filter(lang=lang)
+            if not lang_qs.exists():
+                lang_qs = LanguageModel.objects.filter(lang='en')
+            lang = lang_qs[0]
+
+            # 根据app名返回相应域名
+            app_name = app_inf_qs[0]['appName']
+            country_qs = CountryLanguageModel.objects.filter(language_id=lang.id).annotate(
+                country_number=F('country__number'), push_api=F('country__region__push_api'))
+            if 'Zosi' in app_name:
+                country_qs = country_qs.annotate(api=F('country__region__zosi_api'))
+            elif 'Loocam' in app_name:
+                country_qs = country_qs.annotate(api=F('country__region__loocam_api'))
+            else:
+                country_qs = country_qs.annotate(api=F('country__region__api'))
+            country_qs = country_qs.values('country_name', 'country_number', 'api', 'push_api')
+            return response.json(0, list(country_qs))
+        except Exception as e:
+            return response.json(500, repr(e))
 
     def get_country_info(self, userID, request_dict, response):
         # perm = ModelService.check_perm_uid_manage(userID, 0)

+ 2 - 0
Model/models.py

@@ -1821,6 +1821,8 @@ class RegionModel(models.Model):
     name = models.CharField(max_length=32, default='', verbose_name='区域名称')
     continent_code = models.CharField(max_length=3, default='', verbose_name='洲代码')
     api = models.CharField(max_length=50, default='', verbose_name='域名')
+    zosi_api = models.CharField(max_length=50, default='', verbose_name='周视域名')
+    loocam_api = models.CharField(max_length=50, default='', verbose_name='录看域名')
     push_api = models.CharField(max_length=50, default='', verbose_name='推送域名')
 
     class Meta: