|
@@ -11,24 +11,24 @@
|
|
@file: DetectController.py
|
|
@file: DetectController.py
|
|
@Contact: chanjunkai@163.com
|
|
@Contact: chanjunkai@163.com
|
|
"""
|
|
"""
|
|
-import json
|
|
|
|
-import os
|
|
|
|
import time
|
|
import time
|
|
-from pyfcm import FCMNotification
|
|
|
|
|
|
|
|
import apns2
|
|
import apns2
|
|
import jpush as jpush
|
|
import jpush as jpush
|
|
import oss2
|
|
import oss2
|
|
|
|
+from django.http import JsonResponse
|
|
from django.utils.decorators import method_decorator
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, BASE_DIR, DETECT_PUSH_DOMAIN
|
|
|
|
|
|
+from pyfcm import FCMNotification
|
|
|
|
+
|
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, \
|
|
|
|
+ FCM_CONFIG, APNS_CONFIG
|
|
from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel
|
|
from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel
|
|
|
|
+from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
-from django.http import JsonResponse
|
|
|
|
-from Object.RedisObject import RedisObject
|
|
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
|
@@ -147,12 +147,23 @@ class DetectControllerView(View):
|
|
# 设备语言
|
|
# 设备语言
|
|
lang = request_dict.get('lang', 'en')
|
|
lang = request_dict.get('lang', 'en')
|
|
# interval = request_dict.get('interval', None)
|
|
# interval = request_dict.get('interval', None)
|
|
- print('status:' + status)
|
|
|
|
if not status:
|
|
if not status:
|
|
return response.json(444, 'status')
|
|
return response.json(444, 'status')
|
|
# 关闭推送
|
|
# 关闭推送
|
|
if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
|
+ # 判断推送类型对应key是否存在
|
|
|
|
+ if push_type == 0:
|
|
|
|
+ if appBundleId not in APNS_CONFIG.keys():
|
|
|
|
+ return response.json(904)
|
|
|
|
+ elif push_type == 1:
|
|
|
|
+ if appBundleId not in FCM_CONFIG.keys():
|
|
|
|
+ return response.json(904)
|
|
|
|
+ elif push_type == 2:
|
|
|
|
+ if appBundleId not in JPUSH_CONFIG.keys():
|
|
|
|
+ return response.json(904)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(173)
|
|
dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
status = int(status)
|
|
status = int(status)
|
|
if dvqs.exists():
|
|
if dvqs.exists():
|
|
@@ -326,53 +337,14 @@ class NotificationView(View):
|
|
|
|
|
|
def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
|
|
def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
|
|
event_type = request_dict.get('event_type', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
- jpush_config = {
|
|
|
|
- 'com.ansjer.accloud_ab': {
|
|
|
|
- 'Key': 'f0dc047e5e53fd14199de5b0',
|
|
|
|
- 'Secret': 'aa7f7db33e9f0a7f3871aa1c'},
|
|
|
|
- 'com.ansjer.adcloud_ab': {
|
|
|
|
- 'Key': '76d97b535185114985608234',
|
|
|
|
- 'Secret': 'c9a92b301043cc9c52778692'},
|
|
|
|
- 'com.ansjer.zccloud_ab': {
|
|
|
|
- 'Key': 'd9924f56d3cc7c6017965130',
|
|
|
|
- 'Secret': '869d832d126a232f158b5987'},
|
|
|
|
- 'com.ansjer.loocamccloud_ab': {
|
|
|
|
- 'Key': 'd1cc44797b4642b0e05304fe',
|
|
|
|
- 'Secret': 'c3e8b4ca8c576de61401e56a'},
|
|
|
|
- 'com.ansjer.loocamdcloud_ab': {
|
|
|
|
- 'Key': '76d97b535185114985608234',
|
|
|
|
- 'Secret': 'c9a92b301043cc9c52778692'},
|
|
|
|
- 'com.ansjer.zccloud_a': {
|
|
|
|
- 'Key': '57de2a80d68bf270fd6bdf5a',
|
|
|
|
- 'Secret': '3d354eb6a0b49c2610decf42'},
|
|
|
|
- 'com.ansjer.accloud_a': {
|
|
|
|
- 'Key': 'ff95ee685f49c0dc4013347b',
|
|
|
|
- 'Secret': 'de2c20959f5516fdeeafe78e'},
|
|
|
|
- 'com.ansjer.adcloud_a': {
|
|
|
|
- 'Key': '2e47eb1aee9b164460df3668',
|
|
|
|
- 'Secret': 'b9137d8d684bc248f1809b6d'},
|
|
|
|
- 'com.ansjer.loocamccloud_a': {
|
|
|
|
- 'Key': '23c9213215c7ca0ec945629b',
|
|
|
|
- 'Secret': '81e4b1e859cc8387e2e6c431'},
|
|
|
|
- 'com.ansjer.loocamdcloud_a': {
|
|
|
|
- 'Key': '1dbdd60a16e9892d6f68a073',
|
|
|
|
- 'Secret': '80a97690e7e043109059b403'},
|
|
|
|
- 'com.ansjer.customizedb_a': {
|
|
|
|
- 'Key': '9d79630aa49adfa291fe2568',
|
|
|
|
- 'Secret': '4d8ff52f88136561875a0212'},
|
|
|
|
- 'com.ansjer.customizedd_a': {
|
|
|
|
- 'Key': '8fc4f495685bde53341ee25d',
|
|
|
|
- 'Secret': 'f1da11fa466509fa2670fb66',
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
n_time = request_dict.get('n_time', None)
|
|
n_time = request_dict.get('n_time', None)
|
|
appBundleId = uaql['appBundleId']
|
|
appBundleId = uaql['appBundleId']
|
|
token_val = uaql['token_val']
|
|
token_val = uaql['token_val']
|
|
lang = uaql['lang']
|
|
lang = uaql['lang']
|
|
|
|
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
- app_key = jpush_config[appBundleId]['Key']
|
|
|
|
- master_secret = jpush_config[appBundleId]['Secret']
|
|
|
|
|
|
+ app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
|
|
+ master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
# 此处换成各自的app_key和master_secre
|
|
# 此处换成各自的app_key和master_secre
|
|
_jpush = jpush.JPush(app_key, master_secret)
|
|
_jpush = jpush.JPush(app_key, master_secret)
|
|
push = _jpush.create_push()
|
|
push = _jpush.create_push()
|
|
@@ -417,23 +389,22 @@ class NotificationView(View):
|
|
else:
|
|
else:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
-
|
|
|
|
def get_message_title(self, appBundleId, nickname):
|
|
def get_message_title(self, appBundleId, nickname):
|
|
package_title_config = {
|
|
package_title_config = {
|
|
- 'com.ansjer.customizedd_a':'DVS',
|
|
|
|
- 'com.ansjer.zccloud_a':'ZosiSmart',
|
|
|
|
- 'com.ansjer.zccloud_ab':'周视',
|
|
|
|
- 'com.ansjer.adcloud_a':'ADCloud',
|
|
|
|
- 'com.ansjer.adcloud_ab':'ADCloud',
|
|
|
|
- 'com.ansjer.accloud_a':'ACCloud',
|
|
|
|
- 'com.ansjer.loocamccloud_a':'Loocam',
|
|
|
|
- 'com.ansjer.loocamdcloud_a':'Anlapus',
|
|
|
|
- 'com.ansjer.customizedb_a':'COCOONHD',
|
|
|
|
- 'com.ansjer.customizeda_a':'Guardian365',
|
|
|
|
- 'com.ansjer.customizedc_a':'PatrolSecure',
|
|
|
|
|
|
+ 'com.ansjer.customizedd_a': 'DVS',
|
|
|
|
+ 'com.ansjer.zccloud_a': 'ZosiSmart',
|
|
|
|
+ 'com.ansjer.zccloud_ab': '周视',
|
|
|
|
+ 'com.ansjer.adcloud_a': 'ADCloud',
|
|
|
|
+ 'com.ansjer.adcloud_ab': 'ADCloud',
|
|
|
|
+ 'com.ansjer.accloud_a': 'ACCloud',
|
|
|
|
+ 'com.ansjer.loocamccloud_a': 'Loocam',
|
|
|
|
+ 'com.ansjer.loocamdcloud_a': 'Anlapus',
|
|
|
|
+ 'com.ansjer.customizedb_a': 'COCOONHD',
|
|
|
|
+ 'com.ansjer.customizeda_a': 'Guardian365',
|
|
|
|
+ 'com.ansjer.customizedc_a': 'PatrolSecure',
|
|
}
|
|
}
|
|
if appBundleId in package_title_config.keys():
|
|
if appBundleId in package_title_config.keys():
|
|
- return package_title_config[appBundleId]+'('+nickname+')'
|
|
|
|
|
|
+ return package_title_config[appBundleId] + '(' + nickname + ')'
|
|
else:
|
|
else:
|
|
return nickname
|
|
return nickname
|
|
|
|
|
|
@@ -442,18 +413,8 @@ class NotificationView(View):
|
|
appBundleId = uaql['appBundleId']
|
|
appBundleId = uaql['appBundleId']
|
|
token_val = uaql['token_val']
|
|
token_val = uaql['token_val']
|
|
lang = uaql['lang']
|
|
lang = uaql['lang']
|
|
- fcm_config = {
|
|
|
|
- 'com.ansjer.zccloud_a': 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I',
|
|
|
|
- 'com.ansjer.loocamccloud_a': 'AAAAb9YP3rk:APA91bFCgd-kbVmpK4EVpfdHH_PJZQCYTkOGnTZdIuBWEz2r7aMRsJYHOH3sB-rwcbaRWgnufTyjX9nGQxb6KxQbWVk4ah_H-M3IqGh6Mb60WQQAuR33V6g_Jes5pGL6ViuIxGHqVMaR',
|
|
|
|
- 'com.ansjer.loocamdcloud_a': 'AAAAb9YP3rk:APA91bGw2I2KMD4i-5T7nZO_wB8kuAOuqgyqe5rxmY-W5qkpYEx9IL2IfmC_qf6B_xOyjIDDSjckvMo-RauN__SEoxvAkis7042GRkoKpw7cjZ_H8lC-d50PC0GclPzccrOGFusyKbFY',
|
|
|
|
- 'com.ansjer.customizedb_a': 'AAAAb9YP3rk:APA91bE7kI4vcm-9h_CJNFlOZfc-xwP4Btn6AnjOrwoKV6fgYN7fdarkO76sYxVZiAbDnxsFfOJyP7vQfwyan6mdjuyD5iHdt_XgO22VqniC0vA1V4GJiCS8Tp7LxIX8JVKZl9I_Powt',
|
|
|
|
- 'com.ansjer.customizeda_a': 'AAAAb9YP3rk:APA91bF0HzizVWDc6dKzobY9fsaKDK4veqkOZehDXshVXs8pEEvNWjR_YWbhP60wsRYCHCal8fWN5cECVOWNMMzDsfU88Ty2AUl8S5FtZsmeDTkoGntQOswBr8Ln7Fm_LAp1VqTf9CpM',
|
|
|
|
- 'com.ansjer.customizedd_a': 'AAAAb9YP3rk:APA91bHkxOozJWBrlv3eNT0PgwosYENI9aM4Zuzd418cX-iKkpa1zFNC5MkNDKApx1KH4fhmAfaJ6IMRZ0nj5GIxCpstDYCaZWwgC7-etqfSxG5JAq8LOwJx0o_1tUZqwjIic8ztsg0o',
|
|
|
|
- 'com.ansjer.adcloud_a': 'AAAAb9YP3rk:APA91bFm06w8b9OKQ0gz0iaWFuRqRIkvgAz6z7Gp3dBU_X-LNGJQd1hc1QR2W7QzBglF8SHtERA45a2lbdLRa5qv7hxfd6W_sJLBK7dA8jklsOQBvy505oUzTwMKWy4TwH-exps9KrhO',
|
|
|
|
- 'com.ansjer.accloud_a': 'AAAAb9YP3rk:APA91bFm06w8b9OKQ0gz0iaWFuRqRIkvgAz6z7Gp3dBU_X-LNGJQd1hc1QR2W7QzBglF8SHtERA45a2lbdLRa5qv7hxfd6W_sJLBK7dA8jklsOQBvy505oUzTwMKWy4TwH-exps9KrhO'
|
|
|
|
- }
|
|
|
|
try:
|
|
try:
|
|
- serverKey = fcm_config[appBundleId]
|
|
|
|
|
|
+ serverKey = FCM_CONFIG[appBundleId]
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(404)
|
|
return response.json(404)
|
|
event_type = request_dict.get('event_type', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
@@ -463,17 +424,17 @@ class NotificationView(View):
|
|
if lang == 'cn':
|
|
if lang == 'cn':
|
|
if nickname:
|
|
if nickname:
|
|
# message_title = "周视({nickname})".format(nickname=nickname)
|
|
# message_title = "周视({nickname})".format(nickname=nickname)
|
|
- message_title = self.get_message_title(appBundleId=appBundleId,nickname=nickname)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
else:
|
|
else:
|
|
# message_title = "周视({uid})".format(uid=uid)
|
|
# message_title = "周视({uid})".format(uid=uid)
|
|
- message_title = self.get_message_title(appBundleId=appBundleId,nickname=uid)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
else:
|
|
else:
|
|
if nickname:
|
|
if nickname:
|
|
- message_title = self.get_message_title(appBundleId=appBundleId,nickname=nickname)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
# message_title = "zosi({nickname})".format(nickname=nickname)
|
|
# message_title = "zosi({nickname})".format(nickname=nickname)
|
|
else:
|
|
else:
|
|
- message_title = self.get_message_title(appBundleId=appBundleId,nickname=uid)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
|
|
|
|
# message_title = "zosi({uid})".format(uid=uid)
|
|
# message_title = "zosi({uid})".format(uid=uid)
|
|
send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
@@ -495,12 +456,6 @@ class NotificationView(View):
|
|
lang = uaql['lang']
|
|
lang = uaql['lang']
|
|
n_time = request_dict.get('n_time')
|
|
n_time = request_dict.get('n_time')
|
|
appBundleId = uaql['appBundleId']
|
|
appBundleId = uaql['appBundleId']
|
|
- apns_config = {
|
|
|
|
- 'com.ansjer.loocamccloud': {
|
|
|
|
- 'pem_path': os.path.join(BASE_DIR, 'Ansjer/file/apns_pem/apns-dev-test.pem'),
|
|
|
|
- 'password': '111111'
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
|
|
n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
|
|
if lang == 'cn':
|
|
if lang == 'cn':
|
|
if nickname:
|
|
if nickname:
|
|
@@ -515,8 +470,8 @@ class NotificationView(View):
|
|
message_title = "zosi({uid})".format(uid=uid)
|
|
message_title = "zosi({uid})".format(uid=uid)
|
|
send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
try:
|
|
try:
|
|
- cli = apns2.APNSClient(mode="dev", client_cert=apns_config[appBundleId]['pem_path'],
|
|
|
|
- password=apns_config[appBundleId]['password'])
|
|
|
|
|
|
+ cli = apns2.APNSClient(mode="dev", client_cert=APNS_CONFIG[appBundleId]['pem_path'],
|
|
|
|
+ password=APNS_CONFIG[appBundleId]['password'])
|
|
push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
"received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
"received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
# body = json.dumps(push_data)
|
|
# body = json.dumps(push_data)
|