|
@@ -13,6 +13,7 @@
|
|
"""
|
|
"""
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
import os
|
|
import os
|
|
|
|
+
|
|
'''
|
|
'''
|
|
http://192.168.136.40:8077/Test
|
|
http://192.168.136.40:8077/Test
|
|
'''
|
|
'''
|
|
@@ -29,10 +30,6 @@ class Test(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
request_dict = request.GET
|
|
request_dict = request.GET
|
|
return self.do_apns(request_dict)
|
|
return self.do_apns(request_dict)
|
|
# return self.do_get_putOss_url(request.GET)
|
|
# return self.do_get_putOss_url(request.GET)
|
|
@@ -70,9 +67,8 @@ class Test(View):
|
|
print("not paid...")
|
|
print("not paid...")
|
|
return response.json(404)
|
|
return response.json(404)
|
|
|
|
|
|
-
|
|
|
|
- def do_apns(self,request_dict):
|
|
|
|
- token_val = request_dict.get('token_val',None)
|
|
|
|
|
|
+ def do_apns(self, request_dict):
|
|
|
|
+ token_val = request_dict.get('token_val', None)
|
|
pem_path = os.path.join(BASE_DIR, 'Ansjer/file/apns_pem/apns-dev-test.pem')
|
|
pem_path = os.path.join(BASE_DIR, 'Ansjer/file/apns_pem/apns-dev-test.pem')
|
|
print(pem_path)
|
|
print(pem_path)
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
@@ -89,14 +85,14 @@ class Test(View):
|
|
# assert response.apns_id
|
|
# assert response.apns_id
|
|
|
|
|
|
# cli = apns2.APNSClient(mode="prod", client_cert=pem_path)
|
|
# cli = apns2.APNSClient(mode="prod", client_cert=pem_path)
|
|
- cli = apns2.APNSClient(mode="dev", client_cert=pem_path,password='111111')
|
|
|
|
- push_data = {"alert": "Motion ", "event_time": now_time, "event_type": '51', "msg": "",
|
|
|
|
- "received_at": now_time, "sound": "sound.aif", "uid": "XFDJUHUIOKJHYTGSFFDR"}
|
|
|
|
|
|
+ cli = apns2.APNSClient(mode="dev", client_cert=pem_path, password='111111')
|
|
|
|
+ push_data = {"alert": "Motion ", "event_time": now_time, "event_type": "51", "msg": "",
|
|
|
|
+ "received_at": now_time, "sound": "sound.aif", "uid": "XFDJUHUIOKJHYTGSFFDR", "zpush": "1"}
|
|
alert = apns2.PayloadAlert(body=json.dumps(push_data), title="title!")
|
|
alert = apns2.PayloadAlert(body=json.dumps(push_data), title="title!")
|
|
payload = apns2.Payload(alert=alert)
|
|
payload = apns2.Payload(alert=alert)
|
|
|
|
|
|
n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
- res = cli.push(n=n, device_token=token_val,topic='com.ansjer.loocamccloud')
|
|
|
|
|
|
+ res = cli.push(n=n, device_token=token_val, topic='com.ansjer.loocamccloud')
|
|
if res.status_code == 200:
|
|
if res.status_code == 200:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
else:
|
|
else:
|
|
@@ -104,10 +100,9 @@ class Test(View):
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(10, repr(e))
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
-
|
|
|
|
def do_get_putOss_url(self, request_dict):
|
|
def do_get_putOss_url(self, request_dict):
|
|
import oss2
|
|
import oss2
|
|
- obj_name = request_dict.get('obj_name','')
|
|
|
|
|
|
+ obj_name = request_dict.get('obj_name', '')
|
|
# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
|
# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
|
auth = oss2.Auth('LTAIyMkGfEdogyL9', '71uIjpsqVOmF7DAITRyRuc259jHOjO')
|
|
auth = oss2.Auth('LTAIyMkGfEdogyL9', '71uIjpsqVOmF7DAITRyRuc259jHOjO')
|
|
# Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
# Endpoint以杭州为例,其它Region请按实际情况填写。
|