|
@@ -0,0 +1,48 @@
|
|
|
+# @Author : Rocky
|
|
|
+# @File : AlexaController.py
|
|
|
+# @Time : 2023/12/25 10:46
|
|
|
+from django.views import View
|
|
|
+
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+
|
|
|
+
|
|
|
+class AppToAppView(View):
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.GET, operation, request)
|
|
|
+
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ return self.validation(request.POST, operation, request)
|
|
|
+
|
|
|
+ def validation(self, request_dict, operation, request):
|
|
|
+ response = ResponseObject()
|
|
|
+ token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
+ if token.code != 0:
|
|
|
+ return response.json(token.code)
|
|
|
+ if operation == 'getAlexaAppURLAndLWAFallbackURL': # 获取Alexa App和LWA fallback URL
|
|
|
+ return self.get_alexa_app_url_and_lwa_fallback_url(response)
|
|
|
+ else:
|
|
|
+ return response.json(414)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ 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'
|
|
|
+ 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&' \
|
|
|
+ 'redirect_uri={}'.format(client_id, skill_stage, redirect_uri)
|
|
|
+ lwa_fallback_url = 'https://www.amazon.com/ap/oa?' \
|
|
|
+ 'client_id={}&scope=alexa::skills:account_linking&response_type=code&redirect_uri={}&'.\
|
|
|
+ format(client_id, redirect_uri)
|
|
|
+ res = {
|
|
|
+ 'alexa_app_url': alexa_app_url,
|
|
|
+ 'lwa_fallback_url': lwa_fallback_url
|
|
|
+ }
|
|
|
+ return response.json(0, res)
|
|
|
+
|