|
@@ -26,7 +26,7 @@ from django.views.generic.base import View
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
-from Model.models import Device_Info, VodHlsModel, UID_App, Equipment_Info, UidSetModel, UidPushModel
|
|
|
+from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
@@ -130,72 +130,6 @@ class DetectControllerView(View):
|
|
|
res.append(p)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
|
- def do_change_status11(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)
|
|
|
- # interval = request_dict.get('interval', None)
|
|
|
- print('status:' + status)
|
|
|
- if not status:
|
|
|
- return response.json(444, 'status')
|
|
|
- # 关闭推送
|
|
|
- if status == '0':
|
|
|
- if not all([app_type, appBundleId, uid, m_code]):
|
|
|
- return response.json(444, 'app_type,appBundleId,uid,m_code')
|
|
|
- uid_app_qs = UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, m_code=m_code, uid=uid,
|
|
|
- app_type=app_type)
|
|
|
- if uid_app_qs.exists():
|
|
|
- uid_app_qs.update(status=0)
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- return response.json(173)
|
|
|
- # 开启推
|
|
|
- elif status == '1':
|
|
|
- if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
- return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
- dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
-
|
|
|
- if dvqs.exists():
|
|
|
- now_time = int(time.time())
|
|
|
- try:
|
|
|
- uid_app_qs = UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, token_val=token_val,
|
|
|
- uid=uid, m_code=m_code)
|
|
|
- print(uid_app_qs)
|
|
|
- if uid_app_qs.exists():
|
|
|
- update_dict = {'status': 1}
|
|
|
- # if interval:
|
|
|
- # update_dict['interval'] = int(interval)
|
|
|
- uid_app_qs.update(**update_dict)
|
|
|
- else:
|
|
|
- create_dict = {
|
|
|
- 'uid': uid,
|
|
|
- 'userID_id': userID,
|
|
|
- 'appBundleId': appBundleId,
|
|
|
- 'app_type': app_type,
|
|
|
- 'push_type': push_type,
|
|
|
- 'token_val': token_val,
|
|
|
- 'status': 1,
|
|
|
- 'm_code': m_code,
|
|
|
- 'addTime': now_time,
|
|
|
- 'updTime': now_time}
|
|
|
- # if interval:
|
|
|
- # create_dict['interval'] = int(interval)
|
|
|
- UID_App.objects.create(**create_dict)
|
|
|
- except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- return response.json(10, repr(e))
|
|
|
- else:
|
|
|
- utko = UidTokenObject()
|
|
|
- utko.generate(data={'uid': uid})
|
|
|
- detectUrl = "{SERVER_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
- format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
- return response.json(0, {'detectUrl': detectUrl})
|
|
|
- else:
|
|
|
- return response.json(173)
|
|
|
|
|
|
def do_change_status(self, userID, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
@@ -319,55 +253,49 @@ class NotificationView(View):
|
|
|
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', 'uid',
|
|
|
- 'userID_id', 'userID__NickName',
|
|
|
- 'interval')
|
|
|
+ 'appBundleId', 'push_type',
|
|
|
+ 'userID_id', 'userID__NickName')
|
|
|
if uid_set_qs.exists():
|
|
|
- pass
|
|
|
+ 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)
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
+ for up in uid_push_qs:
|
|
|
+ push_type = up['push_type']
|
|
|
+ # ios apns
|
|
|
+ if push_type == 0:
|
|
|
+ self.do_apns(request_dict, up, response, uid)
|
|
|
+ # android gcm
|
|
|
+ elif push_type == 1:
|
|
|
+ self.do_gmc(request_dict, up, response, uid)
|
|
|
+ # android jpush
|
|
|
+ elif push_type == 2:
|
|
|
+ self.do_jpush(request_dict, up, response, uid)
|
|
|
+ # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
+ # 需求不一样,所以这么做的
|
|
|
+ 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'})
|
|
|
|
|
|
- # if uaqs.exists():
|
|
|
- # redisObj = RedisObject(db=6)
|
|
|
- #
|
|
|
- # auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- # bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
- #
|
|
|
- # for ua in uaqs:
|
|
|
- # push_type = ua['push_type']
|
|
|
- # 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:
|
|
|
- # if ua['interval']:
|
|
|
- # redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
|
|
|
- # # ios apns
|
|
|
- # if push_type == 0:
|
|
|
- # self.do_apns(request_dict, ua, response)
|
|
|
- # # android gcm
|
|
|
- # elif push_type == 1:
|
|
|
- # self.do_gmc(request_dict, ua, response)
|
|
|
- # # android jpush
|
|
|
- # elif push_type == 2:
|
|
|
- # self.do_jpush(request_dict, ua, response)
|
|
|
- #
|
|
|
- # # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
- # # 需求不一样,所以这么做的
|
|
|
- # self.do_bulk_create_info(uaqs, n_time, channel, event_type, is_st)
|
|
|
- # 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)
|
|
|
-
|
|
|
- def do_jpush(self, request_dict, uaql, response):
|
|
|
+ def do_jpush(self, request_dict, uaql, response, uid):
|
|
|
event_type = request_dict.get('event_type', None)
|
|
|
jpush_config = {
|
|
|
'com.ansjer.accloud_ab': {
|
|
@@ -407,7 +335,6 @@ class NotificationView(View):
|
|
|
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']
|
|
@@ -433,12 +360,11 @@ class NotificationView(View):
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
|
|
|
- def do_gmc(self, request_dict, uaql, response):
|
|
|
+ def do_gmc(self, request_dict, uaql, response, uid):
|
|
|
|
|
|
n_time = request_dict.get('n_time')
|
|
|
appBundleId = uaql['appBundleId']
|
|
|
token_val = uaql['token_val']
|
|
|
- uid = uaql['uid']
|
|
|
gcm_config = {
|
|
|
'com.ansjer.zccloud_a': 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I',
|
|
|
'com.ansjer.loocamccloud_a': 'AAAAb9YP3rk:APA91bFCgd-kbVmpK4EVpfdHH_PJZQCYTkOGnTZdIuBWEz2r7aMRsJYHOH3sB-rwcbaRWgnufTyjX9nGQxb6KxQbWVk4ah_H-M3IqGh6Mb60WQQAuR33V6g_Jes5pGL6ViuIxGHqVMaR',
|
|
@@ -466,11 +392,10 @@ class NotificationView(View):
|
|
|
req = requests.post(url, data, headers=headers)
|
|
|
return response.json(0)
|
|
|
|
|
|
- def do_apns(self, request_dict, uaql, response):
|
|
|
+ def do_apns(self, request_dict, uaql, response, uid):
|
|
|
token_val = uaql['token_val']
|
|
|
n_time = request_dict.get('n_time')
|
|
|
appBundleId = uaql['appBundleId']
|
|
|
- uid = uaql['uid']
|
|
|
apns_config = {
|
|
|
'appbundleId': {'pem_path': 'xxxx', 'topic': 'topic', 'password': 'password'}
|
|
|
}
|
|
@@ -494,29 +419,19 @@ class NotificationView(View):
|
|
|
except Exception as e:
|
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
- def do_save_equipment_info(self, uaql, n_time, channel, event_type, is_st):
|
|
|
- Equipment_Info.objects.create(
|
|
|
- userID_id=uaql['userID_id'],
|
|
|
- eventTime=n_time,
|
|
|
- eventType=event_type,
|
|
|
- devUid=uaql['uid'],
|
|
|
- devNickName=uaql['userID__NickName'],
|
|
|
- Channel=channel,
|
|
|
- alarm='0',
|
|
|
- is_st=int(is_st),
|
|
|
- receiveTime=n_time)
|
|
|
-
|
|
|
- def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
|
|
|
+ def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
|
|
|
#
|
|
|
qs_list = []
|
|
|
nowTime = int(time.time())
|
|
|
+ # 设备昵称
|
|
|
+
|
|
|
for dv in uaqs:
|
|
|
add_data = {
|
|
|
'userID_id': dv["userID_id"],
|
|
|
'eventTime': n_time,
|
|
|
'eventType': event_type,
|
|
|
- 'devUid': dv['uid'],
|
|
|
- 'devNickName': dv['userID__NickName'],
|
|
|
+ 'devUid': uid,
|
|
|
+ 'devNickName': uid,
|
|
|
'Channel': channel,
|
|
|
'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
'is_st': int(is_st),
|