|
@@ -0,0 +1,87 @@
|
|
|
+import json
|
|
|
+
|
|
|
+from django.http import QueryDict
|
|
|
+from django.views import View
|
|
|
+from Ansjer.config import LOGGER
|
|
|
+
|
|
|
+from Model.models import DeviceVersionInfo, CountryAPN, LanguageModel, CountryLanguageModel, CountryModel
|
|
|
+from Object.Enums.RedisKeyConstant import RedisKeyConstant
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Service.CommonService import CommonService
|
|
|
+
|
|
|
+
|
|
|
+class APNConfigView(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
+
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
+ response = ResponseObject('en')
|
|
|
+ tko = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
+ if tko.code != 0:
|
|
|
+ return response.json(tko.code)
|
|
|
+ response.lang = tko.lang
|
|
|
+ userID = tko.userID
|
|
|
+ if operation == 'APNConfigList':
|
|
|
+ return self.get_apn_config(request_dict, response)
|
|
|
+ elif operation == 'CountryCodeList':
|
|
|
+ return self.get_country_code_list(request_dict, response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_apn_config(request_dict, response):
|
|
|
+ # 从请求字典中获取uid和version
|
|
|
+ country_code = request_dict.get('countryCode', None)
|
|
|
+ if not country_code:
|
|
|
+ return response.json(444)
|
|
|
+ country_code = country_code.upper()
|
|
|
+ country_apn_qs = CountryAPN.objects.filter(iso=country_code).values('apn_name', 'apn_address', 'username', 'password',
|
|
|
+ 'auth_type')
|
|
|
+ country_apn_list = []
|
|
|
+ for country_apn in country_apn_qs:
|
|
|
+ country_apn_list.append({
|
|
|
+ 'apnName': country_apn['apn_name'] if country_apn['apn_name'] else '',
|
|
|
+ 'apnAddress': country_apn['apn_address'] if country_apn['apn_address'] else '',
|
|
|
+ 'username': country_apn['username'] if country_apn['username'] else '',
|
|
|
+ 'password': country_apn['password'] if country_apn['password'] else '',
|
|
|
+ 'authType': country_apn['auth_type'] if country_apn['auth_type'] else '',
|
|
|
+ })
|
|
|
+
|
|
|
+ return response.json(0, country_apn_list)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_country_code_list(request_dict, response):
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
+
|
|
|
+ # 获取语言 ID
|
|
|
+ language = LanguageModel.objects.filter(lang=lang).first()
|
|
|
+
|
|
|
+ if not language:
|
|
|
+ language = LanguageModel.objects.filter(lang='en').first()
|
|
|
+
|
|
|
+ # 查询tb_country_language和tb_country,获取国家名称和国家iso2代码
|
|
|
+ countries = CountryLanguageModel.objects.filter(language=language).select_related('country')
|
|
|
+
|
|
|
+ # 返回国家名和对应的 country_code
|
|
|
+ country_iso_list = [{
|
|
|
+ 'countryName': country.country_name,
|
|
|
+ 'countryCode': country.country.country_code
|
|
|
+ } for country in countries]
|
|
|
+
|
|
|
+ return response.json(0, country_iso_list)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|