소스 검색

新增更新亚马逊令牌接口

locky 1 년 전
부모
커밋
5e7646c8b7
2개의 변경된 파일23개의 추가작업 그리고 4개의 파일을 삭제
  1. 20 1
      controller/AppToApp.py
  2. 3 3
      controller/deviceStatus.py

+ 20 - 1
controller/AppToApp.py

@@ -9,7 +9,7 @@ import uuid
 from django.http import JsonResponse
 from django.views import View
 
-from model.models import UserModel
+from model.models import UserModel, AlexaAuthModel
 from object.ResObject import ResObject
 from service.CommonService import CommonService
 
@@ -31,6 +31,8 @@ class Oa2View(View):
             return self.get_auth_code_and_token(request_dict, response)
         elif operation == 'getTokenWithAuthCode':  # 根据用户验证码获取访问令牌
             return self.get_token_with_auth_code(request_dict, response)
+        elif operation == 'updateAmazonToken':  # 更新亚马逊令牌
+            return self.update_amazon_token(request_dict)
         else:
             return self.print_url(operation, request_dict, response)
 
@@ -87,6 +89,23 @@ class Oa2View(View):
         }
         return JsonResponse(res_json)
 
+    @staticmethod
+    def update_amazon_token(request_dict):
+        user_id = request_dict.get('user_id')
+        access_token = request_dict.get('access_token')
+        refresh_token = request_dict.get('refresh_token')
+
+        if not all([user_id, access_token, refresh_token]):
+            return JsonResponse({}, status=500)
+
+        try:
+            now_time = int(time.time())
+            AlexaAuthModel.objects.filter(userID=user_id).update(
+                access_token=access_token, refresh_token=refresh_token, expiresTime=now_time + 3000, updTime=now_time)
+            return JsonResponse({})
+        except Exception as e:
+            return JsonResponse({}, status=500)
+
     @staticmethod
     def print_url(operation, request_dict, response):
         logger = logging.getLogger('django')

+ 3 - 3
controller/deviceStatus.py

@@ -476,7 +476,7 @@ class deviceStatus(TemplateView):
                     alexAuth.update(
                         access_token=res['access_token'],
                         refresh_token=res['refresh_token'],
-                        expiresTime=now_time + 300,
+                        expiresTime=now_time + 3000,
                         updTime=now_time,
                     )
                     access_token = res['access_token']
@@ -564,7 +564,7 @@ class deviceStatus(TemplateView):
                     alexAuth.update(
                         access_token=res['access_token'],
                         refresh_token=res['refresh_token'],
-                        expiresTime=now_time + 300,
+                        expiresTime=now_time + 3000,
                         updTime=now_time,
                     )
                     access_token = res['access_token']
@@ -673,7 +673,7 @@ class deviceStatus(TemplateView):
                     alexAuth.update(
                         access_token=res['access_token'],
                         refresh_token=res['refresh_token'],
-                        expiresTime=now_time + 300,
+                        expiresTime=now_time + 3000,
                         updTime=now_time,
                     )
                     access_token = res['access_token']