|
@@ -1,5 +1,5 @@
|
|
|
-#!/usr/bin/env python3
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
"""
|
|
|
@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
@AUTHOR: ASJRD018
|
|
@@ -24,6 +24,8 @@ import jpush as jpush
|
|
|
from Model.models import Device_User, Device_Info, Equipment_Info, App_Info, UID_App
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
+import json
|
|
|
+import requests
|
|
|
|
|
|
|
|
|
class DetectControllerView(View):
|
|
@@ -91,12 +93,12 @@ class NotificationView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- operation = kwargs.get('operation')
|
|
|
+ # operation = kwargs.get('operation')
|
|
|
return self.validation(request.GET)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
- operation = kwargs.get('operation')
|
|
|
+ # operation = kwargs.get('operation')
|
|
|
return self.validation(request.POST)
|
|
|
|
|
|
def validation(self, request_dict, operation):
|
|
@@ -104,14 +106,26 @@ class NotificationView(View):
|
|
|
if operation is None:
|
|
|
return response.json(444, 'error path')
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
- time = request_dict.get('time', None)
|
|
|
utko = UidTokenObject(uidToken)
|
|
|
uid = utko.UID
|
|
|
- uaqs = UID_App.objects.filter(uid=uid).values('token_val','app_type','appBundleId')
|
|
|
+ uaqs = UID_App.objects.filter(uid=uid).values('token_val', 'app_type', 'appBundleId', 'push_type','uid')
|
|
|
if uaqs.exists():
|
|
|
-
|
|
|
- return
|
|
|
-
|
|
|
+ push_type = uaqs[0]['push_type']
|
|
|
+ # token_val = uaqs[0]['token_val']
|
|
|
+ # appBundleId = uaqs[0]['appBundleId']
|
|
|
+ # app_type = uaqs[0]['app_type']
|
|
|
+
|
|
|
+ # ios apns
|
|
|
+ if push_type == 0:
|
|
|
+ return self.do_apns(request_dict, uaqs[0], response)
|
|
|
+ # android gcm
|
|
|
+ elif push_type == 1:
|
|
|
+ return self.do_gmc(request_dict, uaqs[0], response)
|
|
|
+ # android jpush
|
|
|
+ elif push_type == 2:
|
|
|
+ return self.do_apns(request_dict, uaqs[0], response)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
# # 设备主键uid
|
|
|
# if pushType == 'jpush':
|
|
|
# return self.do_jpush(request_dict)
|
|
@@ -122,9 +136,7 @@ class NotificationView(View):
|
|
|
# else:
|
|
|
# return response.json(414)
|
|
|
|
|
|
-
|
|
|
- def do_jpush(self, request_dict):
|
|
|
-
|
|
|
+ def do_jpush(self, request_dict, uaql, response):
|
|
|
jpush_config = {
|
|
|
'com.ansjer.accloud_ab': {
|
|
|
'Key': 'f0dc047e5e53fd14199de5b0',
|
|
@@ -160,9 +172,10 @@ class NotificationView(View):
|
|
|
'Key': '9d79630aa49adfa291fe2568',
|
|
|
'Secret': '4d8ff52f88136561875a0212'},
|
|
|
}
|
|
|
- appBundleId = request_dict.get('appBundleId', None)
|
|
|
- devToken = request_dict.get('devToken', None)
|
|
|
-
|
|
|
+ n_time = request_dict.get('n_time', None)
|
|
|
+ appBundleId = uaql['appBundleId']
|
|
|
+ token_val = uaql['token_val']
|
|
|
+ uid = uaql['uid']
|
|
|
response = ResponseObject()
|
|
|
app_key = jpush_config[appBundleId]['Key']
|
|
|
master_secret = jpush_config[appBundleId]['Secret']
|
|
@@ -173,9 +186,10 @@ class NotificationView(View):
|
|
|
# if you set the logging level to "DEBUG",it will show the debug logging.
|
|
|
_jpush.set_logging("DEBUG")
|
|
|
# push.audience = jpush.all_
|
|
|
- push.audience = jpush.registration_id(devToken)
|
|
|
-
|
|
|
- push.notification = jpush.notification(alert="hello jpush api")
|
|
|
+ push.audience = jpush.registration_id(token_val)
|
|
|
+ push_msg = json.dumps({'n_time': n_time, 'uid': uid})
|
|
|
+ # push.notification = jpush.notification(alert="hello jpush api")
|
|
|
+ push.notification = jpush.notification(alert=push_msg)
|
|
|
push.platform = jpush.all_
|
|
|
try:
|
|
|
res = push.send()
|
|
@@ -185,21 +199,18 @@ class NotificationView(View):
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
|
|
|
- def do_gmc(self):
|
|
|
- import json
|
|
|
- import requests
|
|
|
-
|
|
|
- data = {
|
|
|
- "key1": "abc",
|
|
|
- "key2": "def"
|
|
|
- }
|
|
|
+ def do_gmc(self, request_dict, response):
|
|
|
|
|
|
+ n_time = request_dict.get('n_time')
|
|
|
+ n_type = request_dict.get('n_type')
|
|
|
+ msg = {'n_time': n_time, 'n_type': n_type}
|
|
|
json_data = {
|
|
|
"collapse_key": "WhatYouWant",
|
|
|
- "data": data,
|
|
|
+ "data": msg,
|
|
|
"delay_while_idle": False,
|
|
|
"time_to_live": 3600,
|
|
|
- "registration_ids": [ 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
|
|
|
+ "registration_ids": [
|
|
|
+ 'eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
|
|
|
}
|
|
|
|
|
|
url = 'https://android.googleapis.com/gcm/send'
|
|
@@ -208,8 +219,6 @@ class NotificationView(View):
|
|
|
data = json.dumps(json_data).encode('utf-8')
|
|
|
headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
|
|
|
req = requests.post(url, data, headers=headers)
|
|
|
- response = ResponseObject()
|
|
|
-
|
|
|
return response.json(0)
|
|
|
|
|
|
def do_apns(self, request_dict, response):
|