Browse Source

添加alexa区域信息判断

locky 4 years ago
parent
commit
0e80d97cde
2 changed files with 10 additions and 4 deletions
  1. 1 1
      azoauth/config.py
  2. 9 3
      controller/deviceStatus.py

+ 1 - 1
azoauth/config.py

@@ -32,5 +32,5 @@ ALEXA_EVENT_API = {
     #美洲
     'NA': 'https://api.amazonalexa.com/v3/events',
     #欧洲
-    'EU' : 'https://api.eu.amazonalexa.com/v3/events'
+    'EU': 'https://api.eu.amazonalexa.com/v3/events'
 }

+ 9 - 3
controller/deviceStatus.py

@@ -239,10 +239,14 @@ class deviceStatus(TemplateView):
             if not alexAuth.exists():
                 logger.info('UID为 {} 的用户不存在'.format(UID))
                 return JsonResponse({'code': 102, 'msg': 'not found user'})
+            
             expiresTime = alexAuth[0]['expiresTime']
             access_token = alexAuth[0]['access_token']
             refresh_token = alexAuth[0]['refresh_token']
             alexa_region = alexAuth[0]['alexa_region']
+            if alexa_region not in ALEXA_EVENT_API.keys():
+                logger.info('alexa区域信息错误,alexa_region: {}'.format(alexa_region))
+                return JsonResponse({'code': 102, 'msg': 'alexa_region error'})
 
             # 更新alexa token
             now_time = int(time.time())
@@ -360,7 +364,7 @@ class deviceStatus(TemplateView):
         UID = request_dict.get("UID", '')
         userID = request_dict.get("userID", '')
         logger = logging.getLogger('django')
-        logger.info('class:deviceStatus-------function:delete------------------')
+        logger.info('--------删除设备--------')
         logger.info('userID: {}, UID: {}'.format(userID, UID))
         if not all([UID, userID]):
             return JsonResponse({'code': 111, 'msg': 'fail'})
@@ -369,14 +373,16 @@ class deviceStatus(TemplateView):
             alexAuth = AlexaAuthModel.objects.filter(userID=userID).\
                 values('expiresTime', 'refresh_token', 'access_token', 'alexa_region')
             if not alexAuth.exists():
+                logger.info('UID为 {} 的用户不存在'.format(UID))
                 return JsonResponse({'code': 102, 'msg': 'not found user'})
 
             expiresTime = alexAuth[0]['expiresTime']
             refresh_token = alexAuth[0]['refresh_token']
             access_token = alexAuth[0]['access_token']
             alexa_region = alexAuth[0]['alexa_region']
-            logger.info('expiresTime: {}, refresh_token: {}, access_token: {}, alexa_region: {}'.
-                        format(expiresTime, refresh_token, access_token, alexa_region))
+            if alexa_region not in ALEXA_EVENT_API.keys():
+                logger.info('alexa区域信息错误,alexa_region: {}'.format(alexa_region))
+                return JsonResponse({'code': 102, 'msg': 'alexa_region error'})
 
             now_time = int(time.time())
             if now_time > expiresTime: