|
@@ -29,6 +29,8 @@ class AppToAppView(View):
|
|
|
return self.get_alexa_app_url_and_lwa_fallback_url(response)
|
|
|
elif operation == 'accountLinkWithAmazonAuthorizationCode': # 通过亚马逊授权码连接账号
|
|
|
return self.account_link_with_amazon_authorization_code(user_id, request_dict, response)
|
|
|
+ elif operation == 'getSkillPageURL': # 获取skill页面URL(取消链接)
|
|
|
+ return self.get_skill_page_url(response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
|
|
@@ -66,42 +68,56 @@ class AppToAppView(View):
|
|
|
'client_secret': '43353cac67670aefd64a5f95309754ddd6bcfe8a087cc3cad1348b626f64b132',
|
|
|
'redirect_uri': base_uri
|
|
|
}
|
|
|
- r = requests.post(url=url, data=data)
|
|
|
- if r.status_code != 200:
|
|
|
- return response.json(10, '{}请求响应状态码错误:{}'.format(url, r.status_code))
|
|
|
- res_data = eval(r.content)
|
|
|
- print(res_data)
|
|
|
- if res_data.get('access_token'):
|
|
|
- amazon_access_token = res_data['access_token']
|
|
|
- else:
|
|
|
- return response.json(10, '{}请求响应缺失令牌:{}'.format(url, res_data))
|
|
|
+ try:
|
|
|
+ r = requests.post(url=url, data=data, timeout=10)
|
|
|
+ if r.status_code != 200:
|
|
|
+ return response.json(10, '{}请求响应状态码错误:{}'.format(url, r.status_code))
|
|
|
+ res_data = eval(r.content)
|
|
|
+ print(res_data)
|
|
|
+ if res_data.get('access_token'):
|
|
|
+ amazon_access_token = res_data['access_token']
|
|
|
+ else:
|
|
|
+ return response.json(10, '{}请求响应缺失令牌:{}'.format(url, res_data))
|
|
|
|
|
|
- # 获取用户授权码
|
|
|
- url = base_uri + '/appToApp/oa2/getAuthCode'
|
|
|
- params = {
|
|
|
- 'user_id': user_id
|
|
|
- }
|
|
|
- r = requests.get(url=url, params=params)
|
|
|
- if r.status_code != 200:
|
|
|
- return response.json(10, '{}请求响应状态码错误:{}'.format(url, r.status_code))
|
|
|
- res = eval(r.content)
|
|
|
- user_authorization_code = res['res']['user_authorization_code']
|
|
|
- data = {
|
|
|
- "stage": "development",
|
|
|
- "accountLinkRequest": {
|
|
|
- "redirectUri": base_uri,
|
|
|
- "authCode": user_authorization_code,
|
|
|
- "type": "AUTH_CODE"
|
|
|
+ # 获取用户授权码
|
|
|
+ url = base_uri + '/appToApp/oa2/getAuthCode'
|
|
|
+ params = {
|
|
|
+ 'user_id': user_id
|
|
|
}
|
|
|
+ r = requests.get(url=url, params=params, timeout=10)
|
|
|
+ if r.status_code != 200:
|
|
|
+ return response.json(10, '{}请求响应状态码错误:{}'.format(url, r.status_code))
|
|
|
+ res = eval(r.content)
|
|
|
+ user_authorization_code = res['res']['user_authorization_code']
|
|
|
+ data = {
|
|
|
+ "stage": "development",
|
|
|
+ "accountLinkRequest": {
|
|
|
+ "redirectUri": base_uri,
|
|
|
+ "authCode": user_authorization_code,
|
|
|
+ "type": "AUTH_CODE"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ # 请求连接skill
|
|
|
+ headers = {
|
|
|
+ 'Content-Type': 'application/json',
|
|
|
+ 'Authorization': "Bearer {}".format(amazon_access_token)
|
|
|
+ }
|
|
|
+ skill_id = 'amzn1.ask.skill.ff5a5074-7ec7-442b-979b-cb57095f7a94'
|
|
|
+ url = 'https://api.amazonalexa.com/v1/users/~current/skills/{}/enablement'.format(skill_id)
|
|
|
+ get_token_res = requests.post(headers=headers, url=url, json=data, timeout=30)
|
|
|
+ res_data = eval(get_token_res.content)
|
|
|
+ print(res_data)
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ print('error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def get_skill_page_url(response):
|
|
|
+ skill_asin = 'B0C94Q7H1L'
|
|
|
+ skill_page_url = 'https://alexa.amazon.com/spa/index.html#skills/dp/{}'.format(skill_asin)
|
|
|
+ lwa_page_url = 'https://www.amazon.com/dp/{}'.format(skill_asin)
|
|
|
+ res = {
|
|
|
+ 'skill_page_url': skill_page_url,
|
|
|
+ 'lwa_page_url': lwa_page_url
|
|
|
}
|
|
|
- # 请求连接skill
|
|
|
- headers = {
|
|
|
- 'Content-Type': 'application/json',
|
|
|
- 'Authorization': "Bearer {}".format(amazon_access_token)
|
|
|
- }
|
|
|
- skill_id = 'amzn1.ask.skill.ff5a5074-7ec7-442b-979b-cb57095f7a94'
|
|
|
- url = 'https://api.amazonalexa.com/v1/users/~current/skills/{}/enablement'.format(skill_id)
|
|
|
- get_token_res = requests.post(headers=headers, url=url, json=data)
|
|
|
- res_data = eval(get_token_res.content)
|
|
|
- print(res_data)
|
|
|
- return response.json(0)
|
|
|
+ return response.json(0, res)
|