|
@@ -1,10 +1,12 @@
|
|
|
# @Author : Rocky
|
|
|
# @File : AlexaController.py
|
|
|
# @Time : 2023/12/25 10:46
|
|
|
+import requests
|
|
|
from django.views import View
|
|
|
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
+from Ansjer.config import SERVER_DOMAIN_SSL
|
|
|
|
|
|
|
|
|
class AppToAppView(View):
|
|
@@ -25,6 +27,8 @@ class AppToAppView(View):
|
|
|
return response.json(token.code)
|
|
|
if operation == 'getAlexaAppURLAndLWAFallbackURL': # 获取Alexa App和LWA fallback URL
|
|
|
return self.get_alexa_app_url_and_lwa_fallback_url(response)
|
|
|
+ elif operation == 'exchangesTheAmazonAuthorizationCode': # 根据亚马逊验证码获取亚马逊访问令牌
|
|
|
+ return self.exchanges_the_amazon_authorization_code(request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -32,7 +36,7 @@ class AppToAppView(View):
|
|
|
def get_alexa_app_url_and_lwa_fallback_url(response):
|
|
|
client_id = 'amzn1.application-oa2-client.98a01914518743e481d51115144dafb0'
|
|
|
skill_stage = 'development' # 开发中: development, 已上线: live
|
|
|
- redirect_uri = 'https://pitangui.amazon.com/api/skill/link/M1GQ2T9YG53MFV'
|
|
|
+ redirect_uri = 'https://smart.loocam2.com/deviceStatus/getAccessToken'
|
|
|
alexa_app_url = 'https://alexa.amazon.com/spa/skill-account-linking-consent?' \
|
|
|
'fragment=skill-account-linking-consent&client_id={}&' \
|
|
|
'scope=alexa::skills:account_linking&skill_stage={}&response_type=code&' \
|
|
@@ -46,3 +50,19 @@ class AppToAppView(View):
|
|
|
}
|
|
|
return response.json(0, res)
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def exchanges_the_amazon_authorization_code(request_dict, response):
|
|
|
+ amazon_authorization_code = request_dict.get('amazon_authorization_code', None)
|
|
|
+ if not amazon_authorization_code:
|
|
|
+ return response.json(444)
|
|
|
+
|
|
|
+ url = 'https://api.amazon.com/auth/o2/token'
|
|
|
+ data = {
|
|
|
+ 'grant_type': 'authorization_code',
|
|
|
+ 'code': amazon_authorization_code,
|
|
|
+ 'client_id': 'amzn1.application-oa2-client.98a01914518743e481d51115144dafb0',
|
|
|
+ 'client_secret': '43353cac67670aefd64a5f95309754ddd6bcfe8a087cc3cad1348b626f64b132',
|
|
|
+ 'redirect_uri': amazon_authorization_code,
|
|
|
+ }
|
|
|
+ requests.post(url=url, data=data)
|
|
|
+ return response.json(0)
|