|
@@ -16,6 +16,7 @@ from object.ResObject import ResObject
|
|
import subprocess
|
|
import subprocess
|
|
# from gevent.pool import Pool
|
|
# from gevent.pool import Pool
|
|
from model.models import UserModel,UidRtspModel
|
|
from model.models import UserModel,UidRtspModel
|
|
|
|
+from object.ResponseObject import ResponseObject
|
|
from object.tkObject import tkObject
|
|
from object.tkObject import tkObject
|
|
from service.CommonService import CommonService
|
|
from service.CommonService import CommonService
|
|
from object.RedisObject import RedisObject
|
|
from object.RedisObject import RedisObject
|
|
@@ -23,6 +24,7 @@ from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
rtspServer = "rtsp.zositech.org,3.16.66.144"
|
|
rtspServer = "rtsp.zositech.org,3.16.66.144"
|
|
|
|
|
|
class deviceStatus(TemplateView):
|
|
class deviceStatus(TemplateView):
|
|
@@ -30,101 +32,114 @@ class deviceStatus(TemplateView):
|
|
def dispatch(self, *args, **kwargs):
|
|
def dispatch(self, *args, **kwargs):
|
|
return super(deviceStatus, self).dispatch(*args, **kwargs)
|
|
return super(deviceStatus, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
- def post(self, request, *args, **kwargs):
|
|
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
operation = kwargs.get('operation')
|
|
operation = kwargs.get('operation')
|
|
- if operation == 'test':
|
|
|
|
- return JsonResponse({'res': '11'})
|
|
|
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
|
|
|
-
|
|
|
|
- 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 = 'xvc48ylgwzZ7yThu3s113oKTr5LSTuFm'
|
|
|
|
- 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": [
|
|
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
|
+
|
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
|
+ response = ResponseObject()
|
|
|
|
+ if operation is None:
|
|
|
|
+ return JsonResponse({'code':404,'msg':'not found'})
|
|
|
|
+ if operation == 'getAccessToken':
|
|
|
|
+ return self.accessToken(request_dict, response)
|
|
|
|
+ # 付款完成
|
|
|
|
+ elif operation == 'test':
|
|
|
|
+ return JsonResponse({'code':404,'msg':'not found'})
|
|
|
|
+ return self.test(request_dict, response)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ def getAccessToken(self,request_dict, response):
|
|
|
|
+ # lwa_params = {
|
|
|
|
+ # "grant_type" : "authorization_code",
|
|
|
|
+ # "code": 'NHxKR2mgPmNgCp9yxNCJvJ7fgPbCayNa',
|
|
|
|
+ # "client_id": 'amzn1.application-oa2-client.efb07b51dd444f848b6f0598635da3cc',
|
|
|
|
+ # "client_secret": 'showmeyousecret.zosi'
|
|
|
|
+ # }
|
|
|
|
+ # header = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
|
|
|
|
+ # response = requests.post('https://api.amazon.com/auth/o2/token', data=lwa_params, headers= header, allow_redirects=True)
|
|
|
|
+ #
|
|
|
|
+ #
|
|
|
|
+ # request_json = response.json()
|
|
|
|
+ # return JsonResponse({'res': request_json})
|
|
|
|
+ user_qs = UserModel.objects.filter(userID='158943604783713800138000').values('userID','refresh_token')
|
|
|
|
+ refresh_token = user_qs[0]['refresh_token']
|
|
|
|
+
|
|
|
|
+ payload = {
|
|
|
|
+ 'grant_type': 'refresh_token',
|
|
|
|
+ 'refresh_token': refresh_token,
|
|
|
|
+ 'client_id': 'amzn1.application-oa2-client.efb07b51dd444f848b6f0598635da3cc',
|
|
|
|
+ 'client_secret': '8a49390ebe362bfee153be87587f5673d0c1d8aeb6bc1ef736fda6c9d5d81c8f',
|
|
|
|
+ 'redirect_uri': 'http://www.baidu.com'
|
|
|
|
+ }
|
|
|
|
+ return self.post_to_api(payload)
|
|
|
|
+
|
|
|
|
+ def test(self,request_dict, response):
|
|
|
|
+ api_uri = 'https://api.amazonalexa.com/v3/events'
|
|
|
|
+ messageId = str(uuid.uuid4())
|
|
|
|
+ access_token = 'Atza|IwEBIGZVV6GPFAXf1_ySVAZkOfGc2j0rNhAnGW8dQ71KVnBY9XmKoi5xd1742t-64FLiM27ErgW_D9sqfAd2A69F1o63_HyPeTfP1_CpgYj6ohGGoMTAN9id58PBOyXtqoJr698luykXb8cT30LBxTqU8zYcmxwJfMzyr2Mxz6KkNtusSB4mHBEkfmQ-xkZ_87G0sUscbVokLnkd676kQAuPzmuYzY_nLLbkR28x8ohh0F9lGZYyEJjyg8-VXdoqWBMfEYxgCnQo76FOXXDFyVEPg6ZC'
|
|
|
|
+ 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": [
|
|
{
|
|
{
|
|
- "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.CameraStreamController",
|
|
|
|
+ "version": "3",
|
|
|
|
+ "cameraStreamConfigurations": [
|
|
{
|
|
{
|
|
- "type": "AlexaInterface",
|
|
|
|
- "interface": "Alexa.MediaMetadata",
|
|
|
|
- "version": "3",
|
|
|
|
- "proactivelyReported": True,
|
|
|
|
- # "retrievable": True
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
|
|
+ "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
|
|
|
|
- }
|
|
|
|
|
|
+ ]
|
|
}
|
|
}
|
|
|
|
+ ],
|
|
|
|
+ "scope": {
|
|
|
|
+ "type": "BearerToken",
|
|
|
|
+ "token": access_token
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- response = requests.post(api_uri, data = payload, headers = headers)
|
|
|
|
- request_json = response.json()
|
|
|
|
- return JsonResponse({'res': request_json})
|
|
|
|
-
|
|
|
|
- elif operation == 'getAccessToken':
|
|
|
|
- # lwa_params = {
|
|
|
|
- # "grant_type" : "authorization_code",
|
|
|
|
- # "code": 'NHxKR2mgPmNgCp9yxNCJvJ7fgPbCayNa',
|
|
|
|
- # "client_id": 'amzn1.application-oa2-client.efb07b51dd444f848b6f0598635da3cc',
|
|
|
|
- # "client_secret": 'showmeyousecret.zosi'
|
|
|
|
- # }
|
|
|
|
- # header = {"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"}
|
|
|
|
- # response = requests.post('https://api.amazon.com/auth/o2/token', data=lwa_params, headers= header, allow_redirects=True)
|
|
|
|
- #
|
|
|
|
- #
|
|
|
|
- # request_json = response.json()
|
|
|
|
- # return JsonResponse({'res': request_json})
|
|
|
|
- user_qs = UserModel.objects.filter(userID='158943604783713800138000').values('userID','refresh_token')
|
|
|
|
- refresh_token = user_qs[0]['refresh_token']
|
|
|
|
-
|
|
|
|
- payload = {
|
|
|
|
- 'grant_type': 'refresh_token',
|
|
|
|
- 'refresh_token': refresh_token,
|
|
|
|
- 'client_id': 'amzn1.application-oa2-client.efb07b51dd444f848b6f0598635da3cc',
|
|
|
|
- 'client_secret': '8a49390ebe362bfee153be87587f5673d0c1d8aeb6bc1ef736fda6c9d5d81c8f',
|
|
|
|
- 'redirect_uri': 'http://www.baidu.com'
|
|
|
|
- }
|
|
|
|
- return self.post_to_api(payload)
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ response = requests.post(api_uri, data = payload, headers = headers)
|
|
|
|
+ request_json = response.json()
|
|
|
|
+ return JsonResponse({'res': request_json})
|
|
|
|
|
|
|
|
|
|
def post_to_api(self, payload):
|
|
def post_to_api(self, payload):
|