lang 4 years ago
parent
commit
0c6112ebf9
3 changed files with 121 additions and 68 deletions
  1. 6 1
      azoauth/urls.py
  2. 110 0
      controller/deviceStatus.py
  3. 5 67
      controller/index.py

+ 6 - 1
azoauth/urls.py

@@ -13,11 +13,12 @@ Including another URLconf
     1. Import the include() function: from django.urls import include, path
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
-
+from django.conf.urls import url
 from django.contrib import admin
 from django.urls import path
 from controller import index
 from controller import distribution
+from controller import deviceStatus
 
 urlpatterns = [
     path('admin/', admin.site.urls),
@@ -38,4 +39,8 @@ urlpatterns = [
     path('distribution/select', distribution.selectConnectNum.as_view()),       #查询连接数并返回url
     path('distribution/storage', distribution.storageConnectNum.as_view()),       #存储连接数
 
+
+    #跟设备状态到alexa网关.
+    url(r'^deviceStatus/(?P<operation>.*)$', deviceStatus.deviceStatus.as_view()),
+
 ]

+ 110 - 0
controller/deviceStatus.py

@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+"""
+"""
+import json
+import time
+import requests
+import uuid
+import logging
+from django.views.generic import TemplateView
+from django.shortcuts import render_to_response
+from django.http import JsonResponse
+from object.ResObject import ResObject
+import subprocess
+# from gevent.pool import Pool
+from model.models import UserModel,UidRtspModel
+from object.tkObject import tkObject
+from service.CommonService import CommonService
+from object.RedisObject import RedisObject
+from django.utils.decorators import method_decorator
+from django.views.decorators.csrf import csrf_exempt
+
+
+rtspServer = "rtsp.zositech.org,3.16.66.144"
+
+class deviceStatus(TemplateView):
+    @method_decorator(csrf_exempt)
+    def dispatch(self, *args, **kwargs):
+        return super(deviceStatus, self).dispatch(*args, **kwargs)
+
+    def post(self, request, *args, **kwargs):
+        request.encoding = 'utf-8'
+        operation = kwargs.get('operation')
+        if operation == 'test':
+            return JsonResponse({'res': '11'})
+
+
+    def get(self, request, *args, **kwargs):
+            request.encoding = 'utf-8'
+            request_dict = request.GET
+            operation = kwargs.get('operation')
+            if operation == 'test':
+                api_uri = 'https://api.amazonalexa.com/v3/events'
+                messageId = str(uuid.uuid4())
+                access_token = 'dEqVJw7g3wR4oXOTD6szvNebyKQEkCba'
+                bearer_access_token = 'Bearer {access_token}'.format(access_token=access_token)
+                headers =  {'content-type': "application/json", 'Authorization': bearer_access_token}
+                payload = {
+                    "event": {
+                        "header": {
+                            "namespace": "Alexa.Discovery",
+                            "name": "AddOrUpdateReport",
+                            "payloadVersion": "3",
+                            "messageId": messageId
+                        },
+                        "payload": {
+                            "endpoints": [
+                                {
+                                    "endpointId": "HVTLKFJM6KDTAF9J111A",
+                                    "manufacturerName": "Sample Manufacturer",
+                                    "description": "Smart Light by Sample Manufacturer",
+                                    "friendlyName": "Kitchen Light",
+                                    "displayCategories": [
+                                        "CAMERA"
+                                    ],
+                                    "capabilities": [
+                                        {
+                                            "type": "AlexaInterface",
+                                            "interface": "Alexa.CameraStreamController",
+                                            "version": "3",
+                                            "cameraStreamConfigurations": [
+                                                {
+                                                    "protocols": ["RTSP"],
+                                                    "resolutions":  [{"width": 1280, "height": 720}],
+                                                    "authorizationTypes": ["NONE"],
+                                                    "videoCodecs": ["H264"],
+                                                    "audioCodecs": ["ACC"]
+                                                }]
+                                        },
+                                        {
+                                            "type": "AlexaInterface",
+                                            "interface": "Alexa.MediaMetadata",
+                                            "version": "3",
+                                            "proactivelyReported": True,
+                                            # "retrievable": True
+
+                                        }
+                                    ]
+                                }
+                            ],
+                            "scope": {
+                                "type": "BearerToken",
+                                "token": access_token
+                            }
+                        }
+                    }
+                }
+                response = requests.post(api_uri, data = payload, headers = headers)
+                request_json = response.json()
+                return JsonResponse({'res': request_json})
+
+
+
+
+
+
+
+
+
+

+ 5 - 67
controller/index.py

@@ -128,11 +128,11 @@ class oa2TokenView(TemplateView):
         client_id = request_dict.get("client_id", None)
         refresh_token = request_dict.get("refresh_token", None)
         from var_dump import var_dump
-        logger = logging.getLogger('django')
-        logger.info('token-------------begin')
-        logger.info(code)
-        logger.info(client_id)
-        logger.info(refresh_token)
+        # logger = logging.getLogger('django')
+        # logger.info('token-------------begin')
+        # logger.info(code)
+        # logger.info(client_id)
+        # logger.info(refresh_token)
 
 
         print('tokenView---------------')
@@ -405,68 +405,6 @@ class oa2DiscoveryDevice(TemplateView):
         region = request_dict.get("region", 'cn')
         logger = logging.getLogger('django')
 
-        # api_uri = 'https://api.amazonalexa.com/v3/events'
-        # messageId = str(uuid.uuid4())
-        # bearer_access_token = 'Bearer {access_token}'.format(access_token=access_token)
-        # headers =  {'content-type': "application/json", 'Authorization': bearer_access_token}
-        # payload = {
-        #     "event": {
-        #         "header": {
-        #             "namespace": "Alexa.Discovery",
-        #             "name": "AddOrUpdateReport",
-        #             "payloadVersion": "3",
-        #             "messageId": messageId
-        #         },
-        #         "payload": {
-        #             "endpoints": [
-        #                 {
-        #                     "endpointId": "HVTLKFJM6KDTAF9J111A",
-        #                     "manufacturerName": "Sample Manufacturer",
-        #                     "description": "Smart Light by Sample Manufacturer",
-        #                     "friendlyName": "Kitchen Light",
-        #                     "displayCategories": [
-        #                         "CAMERA"
-        #                     ],
-        #                     "capabilities": [
-        #                         {
-        #                             "type": "AlexaInterface",
-        #                             "interface": "Alexa.CameraStreamController",
-        #                             "version": "3",
-        #                             "cameraStreamConfigurations": [
-        #                                 {
-        #                                     "protocols": ["RTSP"],
-        #                                     "resolutions":  [{"width": 1280, "height": 720}],
-        #                                     "authorizationTypes": ["NONE"],
-        #                                     "videoCodecs": ["H264"],
-        #                                     "audioCodecs": ["ACC"]
-        #                                 }]
-        #                         },
-        #                         {
-        #                             "type": "AlexaInterface",
-        #                             "interface": "Alexa.MediaMetadata",
-        #                             "version": "3",
-        #                             "proactivelyReported": True,
-        #                             # "retrievable": True
-        #
-        #                         }
-        #                     ]
-        #                 }
-        #             ],
-        #             "scope": {
-        #                 "type": "BearerToken",
-        #                 "token": access_token
-        #             }
-        #         }
-        #     }
-        # }
-        # response = requests.post(api_uri, data = payload, headers = headers)
-        # request_json = response.json()
-        # logger.info('1111-----request_json--------------------')
-        # logger.info(request_json)
-        # return JsonResponse({'res': request_json})
-        # logger.info(request_json)
-
-
         try:
             user_qs = UserModel.objects.get(access_token=access_token)
         except Exception as e: