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