Selaa lähdekoodia

获取apn配置接口

linhaohong 8 kuukautta sitten
vanhempi
commit
396f56862a
2 muutettua tiedostoa jossa 91 lisäystä ja 1 poistoa
  1. 4 1
      Ansjer/urls.py
  2. 87 0
      Controller/UserDevice/APNConfigController.py

+ 4 - 1
Ansjer/urls.py

@@ -32,7 +32,8 @@ from Controller.CustomCustomer import CustomCustomerController
 from Controller.MessagePush import EquipmentMessagePush
 from Controller.SensorGateway import SensorGatewayController, EquipmentFamilyController
 from Controller.Surveys import CloudStorageController
-from Controller.UserDevice import UserDeviceShareController, UserSubscriptionController, DeviceVersionInfoController
+from Controller.UserDevice import UserDeviceShareController, UserSubscriptionController, DeviceVersionInfoController, \
+    APNConfigController
 from Controller.CampaignController import AppCampaignController, AdDepartmentController
 from Controller.UserDevice import SerialNumberCheckController
 from Model import views  # 定时任务,不要删除该行代码
@@ -289,6 +290,8 @@ urlpatterns = [
     re_path('shopify/(?P<operation>.*)$', ShopifyController.ShopifyView.as_view()),
     # 根据版本号获取设备配置信息
     re_path('open/device/configuration/(?P<operation>.*)', DeviceVersionInfoController.DeviceVersionInfoView.as_view()),
+    # 获取APN配置信息
+    re_path('APNConfig/(?P<operation>.*)', APNConfigController.APNConfigView.as_view()),
 
 
 

+ 87 - 0
Controller/UserDevice/APNConfigController.py

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