Ver Fonte

根据配置确认地区

locky há 2 anos atrás
pai
commit
a5e66edef7

+ 4 - 6
Controller/IotCoreController.py

@@ -40,7 +40,7 @@ class IotCoreView(View):
         lang = request_dict.get('lang', 'en')
         response.lang = lang
         if operation == 'createKeysAndCertificate':     # 设备注册到IoT core
-            return self.create_keys_and_certificate(request_dict, response, request)
+            return self.create_key_and_certificate(request_dict, response)
         elif operation == 'requestPublishMessage':
             return self.request_publish_message(request_dict, response)
         elif operation == 'getS3PullKey':
@@ -64,7 +64,7 @@ class IotCoreView(View):
 
     # 设备注册到aws iot core
     @staticmethod
-    def create_keys_and_certificate(request_dict, response, request):
+    def create_key_and_certificate(request_dict, response):
         logger = logging.getLogger('info')
         logger.info('设备注册到aws iot core请求参数:{}'.format(request_dict))
         token = request_dict.get('token', None)
@@ -130,8 +130,7 @@ class IotCoreView(View):
                 return response.json(0, {'res': res})
             else:
                 # 获取并判断region_id是否有效
-                region_id = request_dict.get('region_id', None)
-                region_id = int(region_id) if region_id else CommonService.confirm_region_id()
+                region_id = CommonService.confirm_region_id()
                 if region_id not in [1, 2, 3, 4]:
                     return response.json(444, {'invalid region_id': region_id})
 
@@ -198,8 +197,7 @@ class IotCoreView(View):
                 return response.json(13)
 
         # 获取并判断region_id是否有效
-        region_id = request_dict.get('region_id', None)
-        region_id = int(region_id) if region_id else CommonService.confirm_region_id()
+        region_id = CommonService.confirm_region_id()
         if region_id not in [1, 2, 3, 4]:
             return response.json(444, {'invalid region_id': region_id})
 

+ 1 - 5
Controller/SerialNumberController.py

@@ -166,8 +166,7 @@ class SerialNumberView(View):
                     return response.json(5)
 
                 # 获取并判断region_id
-                region_id = request_dict.get('region_id', None)
-                region_id = int(region_id) if region_id else CommonService.confirm_region_id(request)
+                region_id = CommonService.confirm_region_id()
                 if region_id not in [1, 2, 3, 4]:
                     return response.json(444, {'invalid region_id': region_id})
 
@@ -175,9 +174,6 @@ class SerialNumberView(View):
                 if serial_number[9:10]:
                     p2p_type = serial_number[9:10]
                 p2p_type = int(p2p_type)
-                # 尚云: 地区为亚洲分配美洲的uid
-                if p2p_type == 1 and region_id == 2:
-                    region_id = 3
 
                 with transaction.atomic():
                     count = 0

+ 7 - 22
Service/CommonService.py

@@ -625,33 +625,18 @@ GCqvlyw5dfxNA+EtxNE2wCW/LW7ENJlACgcfgPlBZtpLheWoZB/maw4=
             return thing_name_suffix
 
     @staticmethod
-    def confirm_region_id(request=None):
+    def confirm_region_id():
         """
         根据配置信息确定region_id
-        @param request: 请求体
         @return: region_id
         """
         region_id = 3
-        if request is None:
-            if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
-                region_id = 1
-            elif CONFIG_INFO == CONFIG_US:
-                region_id = 3
-            elif CONFIG_INFO == CONFIG_EUR:
-                region_id = 4
-        else:
-            if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:
-                region_id = 1
-            else:  # 国外配置暂时通过ip确认
-                ip = CommonService.get_ip_address(request)
-                ipInfo = CommonService.getIpIpInfo(ip, 'CN')
-                if ipInfo['country_code']:
-                    country_qs = CountryModel.objects.filter(country_code=ipInfo['country_code']).values('region__id')
-                    if country_qs.exists():
-                        region_id = country_qs[0]['region__id']
-                else:  # 不存在默认返回美洲地区api
-                    region_qs = RegionModel.objects.filter(continent_code='NA').values("id")
-                    region_id = region_qs[0]['id']
+        if CONFIG_INFO == CONFIG_TEST or CONFIG_INFO == CONFIG_CN:  # 测试&中国
+            region_id = 1
+        elif CONFIG_INFO == CONFIG_US:      # 美洲
+            region_id = 3
+        elif CONFIG_INFO == CONFIG_EUR:     # 欧洲
+            region_id = 4
         return region_id
 
     @staticmethod