|
@@ -11,46 +11,43 @@
|
|
@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 os
|
|
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, BASE_DIR, APNS_MODE
|
|
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
|
|
|
|
+from Object.ETkObject import ETkObject
|
|
|
|
+'''
|
|
|
|
+http://test.dvema.com/detect/changeStatus?push_type=2&token_val=1507bfd3f7ba3bbb551&appBundleId=com.ansjer.zccloud_ab&tz=+08.00&uid=T4AZ3CUKCERH9FZA111A&status=1&m_code=AN020000own000000unkn.zccloud_ab&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NzUxOTAxNjksInVzZXJJRCI6IjE1Njc3NTgyMTg2MTkxMzgwMDEzODAwMCIsImxhbmciOiJ0YyIsInVzZXIiOiIxMzExOTY1NzcxMyJ9.rQ11jA3IQPxQofFbZyG0nvLhGVcxOR82N2qQ8i04VuU&lang=tc&app_type=2
|
|
|
|
+http://test.push.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJUNEFaM0NVS0NFUkg5RlpBMTExQSJ9.GtrXeq5gb2Z9M3mKECxi9eNQbPxqC-6PtgJkOOg6PwI&n_time=1598456451&channel=1&event_type=1&is_st=1
|
|
|
|
+'''
|
|
|
|
|
|
-
|
|
|
|
-# http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1&app_type=1&m_code=12
|
|
|
|
class DetectControllerView(View):
|
|
class DetectControllerView(View):
|
|
- @method_decorator(csrf_exempt)
|
|
|
|
- def dispatch(self, *args, **kwargs):
|
|
|
|
- return super(DetectControllerView, self).dispatch(*args, **kwargs)
|
|
|
|
-
|
|
|
|
- def __init__(self):
|
|
|
|
- self.ip = ''
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
def get(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
operation = kwargs.get('operation')
|
|
operation = kwargs.get('operation')
|
|
- self.ip = CommonService.get_ip_address(request)
|
|
|
|
|
|
+ # self.ip = CommonService.get_ip_address(request)
|
|
return self.validation(request.GET, operation)
|
|
return self.validation(request.GET, operation)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
def post(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
operation = kwargs.get('operation')
|
|
operation = kwargs.get('operation')
|
|
- self.ip = CommonService.get_ip_address(request)
|
|
|
|
|
|
+ # self.ip = CommonService.get_ip_address(request)
|
|
return self.validation(request.POST, operation)
|
|
return self.validation(request.POST, operation)
|
|
|
|
|
|
def validation(self, request_dict, operation):
|
|
def validation(self, request_dict, operation):
|
|
@@ -78,26 +75,31 @@ class DetectControllerView(View):
|
|
def do_query(self, request_dict, response, userID):
|
|
def do_query(self, request_dict, response, userID):
|
|
page = int(request_dict.get('page', None))
|
|
page = int(request_dict.get('page', None))
|
|
line = int(request_dict.get('line', None))
|
|
line = int(request_dict.get('line', None))
|
|
- nowTime = int(time.time())
|
|
|
|
if not page or not line:
|
|
if not page or not line:
|
|
return response.json(444, 'page,line')
|
|
return response.json(444, 'page,line')
|
|
-
|
|
|
|
- qs = Equipment_Info.objects.filter(userID_id=userID, addTime__gte=nowTime - 3600 * 24 * 27)
|
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
|
- if uid:
|
|
|
|
- qs = qs.filter(devUid=uid)
|
|
|
|
- dvqs = Device_Info.objects.filter(UID=uid).values('Type', 'NickName')
|
|
|
|
- uid_type_dict = {uid: {'type': dvqs[0]['Type'], 'NickName': dvqs[0]['NickName']}}
|
|
|
|
|
|
+ startTime = request_dict.get('startTime', None)
|
|
|
|
+ endTime = request_dict.get('endTime', None)
|
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID)
|
|
|
|
+ if startTime and endTime:
|
|
|
|
+ qs = qs.filter(addTime__range=(startTime, endTime))
|
|
|
|
+ uids = request_dict.get('uids', None)
|
|
|
|
+ if uids:
|
|
|
|
+ uid_list = uids.split(',')
|
|
|
|
+ qs = qs.filter(devUid__in=uid_list)
|
|
|
|
+ dvqs = Device_Info.objects.filter(UID__in=uid_list, userID_id=userID).values('UID', 'Type', 'NickName')
|
|
|
|
+ uid_type_dict = {}
|
|
|
|
+ for dv in dvqs:
|
|
|
|
+ uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
else:
|
|
else:
|
|
dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
|
|
dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
|
|
uid_type_dict = {}
|
|
uid_type_dict = {}
|
|
for dv in dvqs:
|
|
for dv in dvqs:
|
|
uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
- print(uid_type_dict)
|
|
|
|
|
|
+ # print(uid_type_dict)
|
|
if not qs.exists():
|
|
if not qs.exists():
|
|
return response.json(0, {'datas': [], 'count': 0})
|
|
return response.json(0, {'datas': [], 'count': 0})
|
|
qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
- 'receiveTime', 'is_st')
|
|
|
|
|
|
+ 'receiveTime', 'is_st', 'addTime')
|
|
count = qs.count()
|
|
count = qs.count()
|
|
qr = qs[(page - 1) * line:page * line]
|
|
qr = qs[(page - 1) * line:page * line]
|
|
res = []
|
|
res = []
|
|
@@ -117,7 +119,7 @@ class DetectControllerView(View):
|
|
# 列表装载回放时间戳标记
|
|
# 列表装载回放时间戳标记
|
|
vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
|
|
vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
|
|
.values("bucket__bucket", "bucket__endpoint")
|
|
.values("bucket__bucket", "bucket__endpoint")
|
|
- print(vodqs)
|
|
|
|
|
|
+ # print(vodqs)
|
|
if vodqs.exists():
|
|
if vodqs.exists():
|
|
bucket_name = vodqs[0]['bucket__bucket']
|
|
bucket_name = vodqs[0]['bucket__bucket']
|
|
endpoint = vodqs[0]['bucket__endpoint']
|
|
endpoint = vodqs[0]['bucket__endpoint']
|
|
@@ -136,7 +138,7 @@ class DetectControllerView(View):
|
|
res.append(p)
|
|
res.append(p)
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
|
- def do_change_status(self, userID, request_dict, response):
|
|
|
|
|
|
+ def do_change_status1(self, userID, request_dict, response):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
@@ -146,20 +148,32 @@ class DetectControllerView(View):
|
|
m_code = request_dict.get('m_code', None)
|
|
m_code = request_dict.get('m_code', None)
|
|
# 设备语言
|
|
# 设备语言
|
|
lang = request_dict.get('lang', 'en')
|
|
lang = request_dict.get('lang', 'en')
|
|
|
|
+ tz = request_dict.get('tz', '0')
|
|
# 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():
|
|
# 获取用户区域
|
|
# 获取用户区域
|
|
- ip = self.ip
|
|
|
|
- ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
|
- area = ipInfo['country_name']
|
|
|
|
|
|
+ # ip = self.ip
|
|
|
|
+ # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
|
+ # area = ipInfo['country_name']
|
|
# if area == 'China':
|
|
# if area == 'China':
|
|
# DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
|
|
# DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
|
|
# else:
|
|
# else:
|
|
@@ -175,7 +189,8 @@ class DetectControllerView(View):
|
|
'push_type': push_type,
|
|
'push_type': push_type,
|
|
'token_val': token_val,
|
|
'token_val': token_val,
|
|
'updTime': nowTime,
|
|
'updTime': nowTime,
|
|
- 'lang': lang
|
|
|
|
|
|
+ 'lang': lang,
|
|
|
|
+ 'tz': tz
|
|
}
|
|
}
|
|
uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
|
|
UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
|
|
@@ -219,7 +234,8 @@ class DetectControllerView(View):
|
|
'm_code': m_code,
|
|
'm_code': m_code,
|
|
'addTime': nowTime,
|
|
'addTime': nowTime,
|
|
'updTime': nowTime,
|
|
'updTime': nowTime,
|
|
- 'lang': lang
|
|
|
|
|
|
+ 'lang': lang,
|
|
|
|
+ 'tz': tz
|
|
}
|
|
}
|
|
# 绑定设备推送
|
|
# 绑定设备推送
|
|
UidPushModel.objects.create(**uid_push_create_dict)
|
|
UidPushModel.objects.create(**uid_push_create_dict)
|
|
@@ -233,6 +249,104 @@ class DetectControllerView(View):
|
|
else:
|
|
else:
|
|
return response.json(14)
|
|
return response.json(14)
|
|
|
|
|
|
|
|
+ def do_change_status(self, userID, request_dict, response):
|
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
+ token_val = request_dict.get('token_val', None)
|
|
|
|
+ appBundleId = request_dict.get('appBundleId', None)
|
|
|
|
+ app_type = request_dict.get('app_type', None)
|
|
|
|
+ push_type = request_dict.get('push_type', None)
|
|
|
|
+ status = request_dict.get('status', None)
|
|
|
|
+ m_code = request_dict.get('m_code', None)
|
|
|
|
+ # 设备语言
|
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
|
+ tz = request_dict.get('tz', '0')
|
|
|
|
+ # interval = request_dict.get('interval', None)
|
|
|
|
+ if not status:
|
|
|
|
+ return response.json(444, 'status')
|
|
|
|
+ # 关闭推送
|
|
|
|
+ if not all([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)
|
|
|
|
+ status = int(status)
|
|
|
|
+ # 获取用户区域
|
|
|
|
+ # ip = self.ip
|
|
|
|
+ # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
|
|
|
|
+ # area = ipInfo['country_name']
|
|
|
|
+ # if area == 'China':
|
|
|
|
+ # DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
|
|
|
|
+ # else:
|
|
|
|
+ # DETECT_PUSH_DOMAIN = 'en.push.dvema.com'
|
|
|
|
+ nowTime = int(time.time())
|
|
|
|
+ if dvqs.exists():
|
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
|
+ # uid配置信息是否存在
|
|
|
|
+ if uid_set_qs.exists():
|
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
|
+ else:
|
|
|
|
+ uid_set_create_dict = {
|
|
|
|
+ 'uid': uid,
|
|
|
|
+ 'addTime': nowTime,
|
|
|
|
+ 'updTime': nowTime,
|
|
|
|
+ 'detect_status': status,
|
|
|
|
+ }
|
|
|
|
+ # 添加设备配置
|
|
|
|
+ uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
|
+ uid_set_id = uid_set_qs.id
|
|
|
|
+ uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
|
|
+ if status == 0:
|
|
|
|
+ UidPushModel.objects.filter(uid_set__uid=uid).delete()
|
|
|
|
+ return response.json(0)
|
|
|
|
+ elif status == 1:
|
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid)
|
|
|
|
+ if uid_push_qs.exists():
|
|
|
|
+ uid_push_update_dict = {
|
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
|
+ 'app_type': app_type,
|
|
|
|
+ 'push_type': push_type,
|
|
|
|
+ 'token_val': token_val,
|
|
|
|
+ 'updTime': nowTime,
|
|
|
|
+ 'lang': lang,
|
|
|
|
+ 'tz': tz
|
|
|
|
+ }
|
|
|
|
+ uid_push_qs.update(**uid_push_update_dict)
|
|
|
|
+ else:
|
|
|
|
+ # uid_set_id = uid_set_qs[0].id
|
|
|
|
+ uid_push_create_dict = {
|
|
|
|
+ 'uid_set_id': uid_set_id,
|
|
|
|
+ 'userID_id': userID,
|
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
|
+ 'app_type': app_type,
|
|
|
|
+ 'push_type': push_type,
|
|
|
|
+ 'token_val': token_val,
|
|
|
|
+ 'm_code': m_code,
|
|
|
|
+ 'addTime': nowTime,
|
|
|
|
+ 'updTime': nowTime,
|
|
|
|
+ 'lang': lang,
|
|
|
|
+ 'tz': tz
|
|
|
|
+ }
|
|
|
|
+ # 绑定设备推送
|
|
|
|
+ UidPushModel.objects.create(**uid_push_create_dict)
|
|
|
|
+ utko = UidTokenObject()
|
|
|
|
+ # right
|
|
|
|
+ utko.generate(data={'uid': uid})
|
|
|
|
+ detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
|
+ format(uidToken=utko.token, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
|
|
+ return response.json(0, {'detectUrl': detectUrl})
|
|
|
|
+ else:
|
|
|
|
+ return response.json(14)
|
|
|
|
+
|
|
def do_update_interval(self, userID, request_dict, response):
|
|
def do_update_interval(self, userID, request_dict, response):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
interval = request_dict.get('interval', None)
|
|
interval = request_dict.get('interval', None)
|
|
@@ -277,27 +391,30 @@ class NotificationView(View):
|
|
# return response.json(444)
|
|
# return response.json(444)
|
|
utko = UidTokenObject(uidToken)
|
|
utko = UidTokenObject(uidToken)
|
|
uid = utko.UID
|
|
uid = utko.UID
|
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
|
+ pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
|
+ if redisObj.get_data(key=pkey):
|
|
|
|
+ res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
+ else:
|
|
|
|
+ # 设置推送间隔60秒一次
|
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
if uid_set_qs.exists():
|
|
if uid_set_qs.exists():
|
|
uid_set_id = uid_set_qs[0].id
|
|
uid_set_id = uid_set_qs[0].id
|
|
nickname = uid_set_qs[0].nickname
|
|
nickname = uid_set_qs[0].nickname
|
|
|
|
+ if not nickname:
|
|
|
|
+ nickname = uid
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
- values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang')
|
|
|
|
- if uid_set_qs.exists():
|
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
|
- pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
|
- if redisObj.get_data(key=pkey):
|
|
|
|
- res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
|
- else:
|
|
|
|
- detect_interval = uid_set_qs[0].detect_interval
|
|
|
|
- if detect_interval:
|
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=detect_interval)
|
|
|
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
|
|
|
|
+ 'tz')
|
|
|
|
+ if uid_push_qs.exists():
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
for up in uid_push_qs:
|
|
for up in uid_push_qs:
|
|
push_type = up['push_type']
|
|
push_type = up['push_type']
|
|
# ios apns
|
|
# ios apns
|
|
|
|
+ print(push_type)
|
|
if push_type == 0:
|
|
if push_type == 0:
|
|
self.do_apns(request_dict, up, response, uid, channel, nickname)
|
|
self.do_apns(request_dict, up, response, uid, channel, nickname)
|
|
# android gcm
|
|
# android gcm
|
|
@@ -326,53 +443,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': '8fc4f495685bde53341ee25dMaster',
|
|
|
|
- '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']
|
|
-
|
|
|
|
|
|
+ tz = uaql['tz']
|
|
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()
|
|
@@ -382,19 +460,8 @@ class NotificationView(View):
|
|
push.audience = jpush.registration_id(token_val)
|
|
push.audience = jpush.registration_id(token_val)
|
|
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}
|
|
- n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
|
|
|
|
- if lang == 'cn':
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "周视({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "周视({uid})".format(uid=uid)
|
|
|
|
- send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
- else:
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "zosi({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "zosi({uid})".format(uid=uid)
|
|
|
|
- send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
|
|
android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
|
|
android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
|
|
big_text=send_text, title=message_title,
|
|
big_text=send_text, title=message_title,
|
|
extras=push_data)
|
|
extras=push_data)
|
|
@@ -412,75 +479,47 @@ class NotificationView(View):
|
|
else:
|
|
else:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
|
|
|
|
- '''
|
|
|
|
- def do_gmc(self, request_dict, uaql, response, uid, channel):
|
|
|
|
-
|
|
|
|
- n_time = request_dict.get('n_time')
|
|
|
|
- appBundleId = uaql['appBundleId']
|
|
|
|
- token_val = uaql['token_val']
|
|
|
|
- gcm_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',
|
|
|
|
|
|
+ def get_message_title(self, appBundleId, nickname):
|
|
|
|
+ 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',
|
|
}
|
|
}
|
|
- serverKey = gcm_config[appBundleId]
|
|
|
|
- event_type = request_dict.get('event_type', None)
|
|
|
|
- push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
|
- "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1"}
|
|
|
|
- json_data = {
|
|
|
|
- "collapse_key": "WhatYouWant",
|
|
|
|
- "data": push_data,
|
|
|
|
- "delay_while_idle": False,
|
|
|
|
- "time_to_live": 3600,
|
|
|
|
- "registration_ids": [token_val]
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- url = 'https://android.googleapis.com/gcm/send'
|
|
|
|
- # serverKey = "AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I"
|
|
|
|
|
|
+ if appBundleId in package_title_config.keys():
|
|
|
|
+ return package_title_config[appBundleId] + '(' + nickname + ')'
|
|
|
|
+ else:
|
|
|
|
+ return nickname
|
|
|
|
|
|
- data = json.dumps(json_data).encode('utf-8')
|
|
|
|
- headers = {'Content-Type': 'application/json', 'Authorization': 'key=%s' % serverKey}
|
|
|
|
- req = requests.post(url, data, headers=headers)
|
|
|
|
- return response.json(0)
|
|
|
|
- '''
|
|
|
|
|
|
+ def get_send_text(self, channel, n_time, lang, tz):
|
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
|
|
|
|
+ send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
|
|
+ if lang == 'cn':
|
|
|
|
+ send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
+ return send_text
|
|
|
|
|
|
def do_fcm(self, request_dict, uaql, response, uid, channel, nickname):
|
|
def do_fcm(self, request_dict, uaql, response, uid, channel, nickname):
|
|
n_time = request_dict.get('n_time')
|
|
n_time = request_dict.get('n_time')
|
|
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'
|
|
|
|
- }
|
|
|
|
|
|
+ tz = uaql['tz']
|
|
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)
|
|
push_service = FCMNotification(api_key=serverKey)
|
|
push_service = FCMNotification(api_key=serverKey)
|
|
registration_id = token_val
|
|
registration_id = token_val
|
|
- n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
|
|
|
|
- if lang == 'cn':
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "周视({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "周视({uid})".format(uid=uid)
|
|
|
|
- send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
- else:
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "zosi({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "zosi({uid})".format(uid=uid)
|
|
|
|
- send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
|
|
data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
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}
|
|
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
|
|
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
|
|
@@ -499,28 +538,15 @@ 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)))
|
|
|
|
- if lang == 'cn':
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "周视({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "周视({uid})".format(uid=uid)
|
|
|
|
- send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
- else:
|
|
|
|
- if nickname:
|
|
|
|
- message_title = "zosi({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = "zosi({uid})".format(uid=uid)
|
|
|
|
- send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
|
|
|
|
|
|
+ tz = uaql['tz']
|
|
|
|
+ message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
|
|
try:
|
|
try:
|
|
- cli = apns2.APNSClient(mode="dev", client_cert=apns_config[appBundleId]['pem_path'],
|
|
|
|
- password=apns_config[appBundleId]['password'])
|
|
|
|
|
|
+ print('---')
|
|
|
|
+
|
|
|
|
+ cli = apns2.APNSClient(mode=APNS_MODE,
|
|
|
|
+ client_cert=os.path.join(BASE_DIR, 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)
|
|
@@ -529,12 +555,15 @@ class NotificationView(View):
|
|
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=appBundleId)
|
|
res = cli.push(n=n, device_token=token_val, topic=appBundleId)
|
|
# assert res.status_code == 200, res.reason
|
|
# assert res.status_code == 200, res.reason
|
|
- # assert res.apns_id
|
|
|
|
|
|
+ # assert res.apns_id
|
|
|
|
+ print('========')
|
|
|
|
+ print(res.status_code)
|
|
if res.status_code == 200:
|
|
if res.status_code == 200:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
else:
|
|
else:
|
|
return response.json(404, res.reason)
|
|
return response.json(404, res.reason)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
|
+ print(repr(e))
|
|
return response.json(10, repr(e))
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
@@ -542,21 +571,112 @@ class NotificationView(View):
|
|
qs_list = []
|
|
qs_list = []
|
|
nowTime = int(time.time())
|
|
nowTime = int(time.time())
|
|
# 设备昵称
|
|
# 设备昵称
|
|
|
|
+ userID_ids = []
|
|
|
|
+ for dv in uaqs:
|
|
|
|
+ userID_id = dv["userID_id"]
|
|
|
|
+ if userID_id not in userID_ids:
|
|
|
|
+ add_data = {
|
|
|
|
+ 'userID_id': dv["userID_id"],
|
|
|
|
+ 'eventTime': n_time,
|
|
|
|
+ 'eventType': event_type,
|
|
|
|
+ 'devUid': uid,
|
|
|
|
+ 'devNickName': uid,
|
|
|
|
+ 'Channel': channel,
|
|
|
|
+ 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
+ 'is_st': int(is_st),
|
|
|
|
+ 'receiveTime': n_time,
|
|
|
|
+ 'addTime': nowTime
|
|
|
|
+ }
|
|
|
|
+ qs_list.append(Equipment_Info(**add_data))
|
|
|
|
+ userID_ids.append(userID_id)
|
|
|
|
+ if qs_list:
|
|
|
|
+ print(1)
|
|
|
|
+ Equipment_Info.objects.bulk_create(qs_list)
|
|
|
|
+ return True
|
|
|
|
+ else:
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
|
|
+# 移动侦测接口
|
|
|
|
+class PushNotificationView(View):
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ # operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.GET)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ # operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.POST)
|
|
|
|
+
|
|
|
|
+ def validation(self, request_dict):
|
|
|
|
+ etk = request_dict.get('etk', None)
|
|
|
|
+ channel = request_dict.get('channel', '1')
|
|
|
|
+ n_time = request_dict.get('n_time', None)
|
|
|
|
+ event_type = request_dict.get('event_type', None)
|
|
|
|
+ is_st = request_dict.get('is_st', None)
|
|
|
|
+ eto = ETkObject(etk)
|
|
|
|
+ uid = eto.uid
|
|
|
|
+ if len(uid) == 20:
|
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
|
+ pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
|
+ # 推送时间限制
|
|
|
|
+ if redisObj.get_data(key=pkey):
|
|
|
|
+ res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
+ else:
|
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
|
|
+ if uid_set_qs.exists():
|
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type',
|
|
|
|
+ 'userID_id', 'userID__NickName', 'lang', 'tz')
|
|
|
|
+ if uid_set_qs.exists():
|
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
|
+ self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
|
|
|
|
+ if is_st == '0' or is_st == '2':
|
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
|
+ else:
|
|
|
|
+ # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
|
+ obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
|
|
|
|
+ # 设置此签名URL在60秒内有效。
|
|
|
|
+ url = bucket.sign_url('PUT', obj, 7200)
|
|
|
|
+ res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
+ else:
|
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
|
+ else:
|
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
|
+ else:
|
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
|
|
|
|
|
|
|
|
+ def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
|
|
+ #
|
|
|
|
+ qs_list = []
|
|
|
|
+ nowTime = int(time.time())
|
|
|
|
+ # 设备昵称
|
|
|
|
+ userID_ids = []
|
|
for dv in uaqs:
|
|
for dv in uaqs:
|
|
- add_data = {
|
|
|
|
- 'userID_id': dv["userID_id"],
|
|
|
|
- 'eventTime': n_time,
|
|
|
|
- 'eventType': event_type,
|
|
|
|
- 'devUid': uid,
|
|
|
|
- 'devNickName': uid,
|
|
|
|
- 'Channel': channel,
|
|
|
|
- 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
- 'is_st': int(is_st),
|
|
|
|
- 'receiveTime': n_time,
|
|
|
|
- 'addTime': nowTime
|
|
|
|
- }
|
|
|
|
- qs_list.append(Equipment_Info(**add_data))
|
|
|
|
|
|
+ userID_id = dv["userID_id"]
|
|
|
|
+ if userID_id not in userID_ids:
|
|
|
|
+ add_data = {
|
|
|
|
+ 'userID_id': dv["userID_id"],
|
|
|
|
+ 'eventTime': n_time,
|
|
|
|
+ 'eventType': event_type,
|
|
|
|
+ 'devUid': uid,
|
|
|
|
+ 'devNickName': uid,
|
|
|
|
+ 'Channel': channel,
|
|
|
|
+ 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
|
+ 'is_st': int(is_st),
|
|
|
|
+ 'receiveTime': n_time,
|
|
|
|
+ 'addTime': nowTime
|
|
|
|
+ }
|
|
|
|
+ qs_list.append(Equipment_Info(**add_data))
|
|
|
|
+ userID_ids.append(userID_id)
|
|
if qs_list:
|
|
if qs_list:
|
|
print(1)
|
|
print(1)
|
|
Equipment_Info.objects.bulk_create(qs_list)
|
|
Equipment_Info.objects.bulk_create(qs_list)
|