|
@@ -31,12 +31,13 @@ class Test(View):
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
|
|
request_dict = request.GET
|
|
|
- return self.do_apns(request_dict)
|
|
|
+ # return self.do_apns(request_dict)
|
|
|
# return self.do_get_putOss_url(request.GET)
|
|
|
# from django.http import JsonResponse
|
|
|
# return JsonResponse(status=200,data={
|
|
|
# 'code': 173,
|
|
|
# 'msg': 'data is not exist'})
|
|
|
+ return self.do_fcm_push(request)
|
|
|
return self.do_gcm_push(request)
|
|
|
return self.do_alipay_query_status()
|
|
|
|
|
@@ -67,6 +68,47 @@ class Test(View):
|
|
|
print("not paid...")
|
|
|
return response.json(404)
|
|
|
|
|
|
+ def do_fcm_push(self, request):
|
|
|
+ rg_id = request.GET.get('rg_id', '')
|
|
|
+ serverKey = request.GET.get('serverKey', '')
|
|
|
+ push_type = request.GET.get('push_type', None)
|
|
|
+ # Send to single device.
|
|
|
+ from pyfcm import FCMNotification
|
|
|
+
|
|
|
+ # OR initialize with proxies
|
|
|
+
|
|
|
+ # proxy_dict = {
|
|
|
+ # "http": "http://127.0.0.1",
|
|
|
+ # "https": "http://127.0.0.1",
|
|
|
+ # }
|
|
|
+ # push_service = FCMNotification(api_key="<api-key>", proxy_dict=proxy_dict)
|
|
|
+ push_service = FCMNotification(api_key=serverKey)
|
|
|
+
|
|
|
+ # Your api-key can be gotten from: https://console.firebase.google.com/project/<project-name>/settings/cloudmessaging
|
|
|
+
|
|
|
+ registration_id = rg_id
|
|
|
+ message_title = "Zosi Smart(Camera 007)"
|
|
|
+ now_time = int(time.time())
|
|
|
+ data = {"alert": "Motion ", "event_time": now_time, "event_type": "51", "msg": "",
|
|
|
+ "received_at": now_time, "sound": "sound.aif", "uid": "XFDJUHUIOKJHYTGSFFDR", "zpush": "1"}
|
|
|
+ # message_body = json.dumps(data)
|
|
|
+
|
|
|
+ message_body = '警告:Motion Channel:1 日期:{tt}'.format(
|
|
|
+ tt=str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))))
|
|
|
+ print(message_body)
|
|
|
+ if push_type:
|
|
|
+ result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
|
|
|
+ message_body=message_body, data_message=data)
|
|
|
+ else:
|
|
|
+ result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
|
|
|
+ message_body=message_body)
|
|
|
+
|
|
|
+ from var_dump import var_dump
|
|
|
+ var_dump(result)
|
|
|
+
|
|
|
+ response = ResponseObject()
|
|
|
+ return response.json(0, result)
|
|
|
+
|
|
|
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')
|
|
@@ -121,16 +163,9 @@ class Test(View):
|
|
|
serverKey = request.GET.get('serverKey', '')
|
|
|
if not rg_id or not serverKey:
|
|
|
return response.json(444)
|
|
|
- data = {
|
|
|
- "received_at": "1",
|
|
|
- "msg": "1",
|
|
|
- "uid": "1",
|
|
|
- "alert": "1",
|
|
|
- "sound": "1",
|
|
|
- "event_time": "1",
|
|
|
- "event_type": "1",
|
|
|
- }
|
|
|
-
|
|
|
+ now_time = int(time.time())
|
|
|
+ data = {"alert": "Motion ", "event_time": now_time, "event_type": "51", "msg": "",
|
|
|
+ "received_at": now_time, "sound": "sound.aif", "uid": "XFDJUHUIOKJHYTGSFFDR", "zpush": "1"}
|
|
|
json_data = {
|
|
|
"collapse_key": "WhatYouWant",
|
|
|
"data": data,
|