Pārlūkot izejas kodu

绑定UID时 增加返回iot区域端点

chenshibin 4 gadi atpakaļ
vecāks
revīzija
7d20d8aeee
1 mainītis faili ar 15 papildinājumiem un 3 dzēšanām
  1. 15 3
      Controller/SerialNumberController.py

+ 15 - 3
Controller/SerialNumberController.py

@@ -8,7 +8,7 @@ from django.db import transaction
 from django.views import View
 from django.views import View
 
 
 from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, CompanyModel, RegionModel, \
 from Model.models import SerialNumberModel, CompanySerialModel, UIDCompanySerialModel, CompanyModel, RegionModel, \
-    CountryModel, UIDModel
+    CountryModel, UIDModel, RegionCountryModel
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
 from Object.uidManageResponseObject import uidManageResponseObject
 from Object.uidManageResponseObject import uidManageResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
@@ -209,6 +209,16 @@ class SerialNumberView(View):
                     if not company_serial_qs.exists():
                     if not company_serial_qs.exists():
                         return response.json(173)
                         return response.json(173)
 
 
+                    region_country_qs = RegionCountryModel.objects.filter(number=serial)
+                    endpoint = 'a2rqy12o004ad8-ats.iot.us-east-1.amazonaws.com'
+                    if region_country_qs.exists():
+                        user_region = region_country_qs[0]
+                        if user_region.region_id == 1:
+                            endpoint = 'a250bbr0p9u7as-ats.iot.cn-northwest-1.amazonaws.com.cn'
+                        elif user_region.region_id == 2:
+                            endpoint = 'a2rqy12o004ad8-ats.iot.ap-southeast-1.amazonaws.com'
+                        elif user_region.region_id == 3:
+                            endpoint = 'a2rqy12o004ad8-ats.iot.eu-west-1.amazonaws.com'
 
 
                     # 当序列号已关联UID
                     # 当序列号已关联UID
                     company_serial = company_serial_qs[0]
                     company_serial = company_serial_qs[0]
@@ -252,7 +262,8 @@ class SerialNumberView(View):
                                 res = {
                                 res = {
                                     'uid': CommonService.encode_data(uid.uid),
                                     'uid': CommonService.encode_data(uid.uid),
                                     'mac': CommonService.encode_data(uid.mac),
                                     'mac': CommonService.encode_data(uid.mac),
-                                    'extra': uid.uid_extra
+                                    'extra': uid.uid_extra,
+                                    'endpoint': endpoint
                                 }
                                 }
                                 return response.json(0, res)
                                 return response.json(0, res)
                             else:
                             else:
@@ -266,7 +277,8 @@ class SerialNumberView(View):
                             res = {
                             res = {
                                 'uid': CommonService.encode_data(uid['uid__uid']),
                                 'uid': CommonService.encode_data(uid['uid__uid']),
                                 'mac': CommonService.encode_data(uid['uid__mac']),
                                 'mac': CommonService.encode_data(uid['uid__mac']),
-                                'extra': uid['uid__uid_extra']
+                                'extra': uid['uid__uid_extra'],
+                                'endpoint': endpoint
                             }
                             }
                             return response.json(0, res)
                             return response.json(0, res)
                         else:
                         else: