|
@@ -21,17 +21,18 @@ import oss2
|
|
|
from django.http import JsonResponse
|
|
|
from django.views.generic.base import View
|
|
|
from pyfcm import FCMNotification
|
|
|
-from AnsjerPush.config import SERVER_TYPE
|
|
|
-from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, FCM_CONFIG, \
|
|
|
+
|
|
|
+from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, JPUSH_CONFIG, FCM_CONFIG, \
|
|
|
APNS_CONFIG, BASE_DIR, APNS_MODE
|
|
|
+from AnsjerPush.config import SERVER_TYPE
|
|
|
from Model.models import Equipment_Info, UidPushModel, SysMsgModel
|
|
|
from Object.ETkObject import ETkObject
|
|
|
-from Object.LogUtil import LogUtil
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
-from Object.utils import LocalDateTimeUtil
|
|
|
+
|
|
|
'''
|
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
|
http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
|
|
@@ -60,8 +61,6 @@ class NotificationView(View):
|
|
|
n_time = request_dict.get('n_time', None)
|
|
|
event_type = request_dict.get('event_type', None)
|
|
|
is_st = request_dict.get('is_st', None)
|
|
|
- # print("aaa")
|
|
|
- # return JsonResponse(0,safe=False)
|
|
|
if not all([channel, n_time]):
|
|
|
return JsonResponse(status=200, data={
|
|
|
'code': 444,
|
|
@@ -109,8 +108,8 @@ class NotificationView(View):
|
|
|
logger.info("redis_list----------\n")
|
|
|
else:
|
|
|
# 从数据库查询出来
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
|
|
|
- values('token_val', 'app_type', 'appBundleId','m_code',
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'm_code',
|
|
|
'push_type', 'userID_id', 'userID__NickName',
|
|
|
'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
'uid_set__channel')
|
|
@@ -118,7 +117,6 @@ class NotificationView(View):
|
|
|
logger.info("uid_push_qs----------\n")
|
|
|
logger.info(list(uid_push_qs))
|
|
|
|
|
|
-
|
|
|
# 新建一个list接收数据
|
|
|
redis_list = []
|
|
|
# 把数据库数据追加进redis_list
|
|
@@ -130,11 +128,6 @@ class NotificationView(View):
|
|
|
res_data = {'code': 404, 'msg': 'error !'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
- # 此时应该更新一下redis里面的dkey的有效时间
|
|
|
- # detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
- # tmp_channel = redis_list[0]['uid_set__channel']
|
|
|
- # self.do_update_detect_interval(uid, tmp_channel, redisObj, detect_interval)
|
|
|
-
|
|
|
if not redis_list:
|
|
|
print("没有redi_list")
|
|
|
res_data = {'code': 0, 'msg': 'no redi_list success!'}
|
|
@@ -154,7 +147,7 @@ class NotificationView(View):
|
|
|
else:
|
|
|
detect_med_type = 2 # 为2的话,既推送,又存库
|
|
|
# detect_group=0允许全部推送的时候
|
|
|
- if detect_group == '0'or detect_group == '':
|
|
|
+ if detect_group == '0' or detect_group == '':
|
|
|
redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
else:
|
|
|
detect_group_list = detect_group.split(',')
|
|
@@ -164,14 +157,11 @@ class NotificationView(View):
|
|
|
redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
# 改为1秒
|
|
|
# 如果不是正式
|
|
|
- if SERVER_TYPE!="Ansjer.formal_settings":
|
|
|
+ if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
redisObj.set_data(key=pkey, val=1, expire=10)
|
|
|
else:
|
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
|
|
|
- # 打印have_ykey
|
|
|
- # return JsonResponse(status=200, data={'pkey': 0, 'have_ykey': have_ykey, 'have_pkey': have_pkey, 'have_ykey': have_dkey})
|
|
|
-
|
|
|
# 旧模式并且没有pkey,重新创建一个
|
|
|
if not detect_group and not have_pkey:
|
|
|
# 设置推送时间为60秒一次
|
|
@@ -187,12 +177,7 @@ class NotificationView(View):
|
|
|
'channel': channel,
|
|
|
'event_type': event_type,
|
|
|
'n_time': n_time,
|
|
|
- # 'appBundleId': appBundleId,
|
|
|
- # 'token_val': token_val,
|
|
|
- # 'msg_title': msg_title,
|
|
|
- # 'msg_text': msg_text
|
|
|
}
|
|
|
- eq_list = []
|
|
|
sys_msg_list = []
|
|
|
userID_ids = []
|
|
|
do_apns_code = ''
|
|
@@ -224,11 +209,9 @@ class NotificationView(View):
|
|
|
logger.info('<<<<<旧的接口,根据时区计算后日期={},时区={}'.format(local_date_time, tz))
|
|
|
local_date_time = local_date_time[0:10]
|
|
|
logger.info('<<<<<旧的接口,日期={}'.format(local_date_time))
|
|
|
- push_server_status = 0
|
|
|
|
|
|
# 以下是存库
|
|
|
userID_id = up["userID_id"]
|
|
|
- int_is_st = int(is_st)
|
|
|
if userID_id not in userID_ids:
|
|
|
|
|
|
if is_sys_msg:
|
|
@@ -242,19 +225,6 @@ class NotificationView(View):
|
|
|
uid=uid,
|
|
|
eventType=event_type))
|
|
|
else:
|
|
|
- # eq_list.append(Equipment_Info(
|
|
|
- # userID_id=userID_id,
|
|
|
- # eventTime=n_time,
|
|
|
- # eventType=event_type,
|
|
|
- # devUid=uid,
|
|
|
- # devNickName=nickname,
|
|
|
- # Channel=channel,
|
|
|
- # alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
- # is_st=int_is_st,
|
|
|
- # receiveTime=n_time,
|
|
|
- # addTime=now_time,
|
|
|
- # storage_location=1
|
|
|
- # ))
|
|
|
logger.info('----《旧接口》start------')
|
|
|
new_device_info_list.append(EquipmentInfoService.get_equipment_info_obj(
|
|
|
local_date_time,
|
|
@@ -275,7 +245,6 @@ class NotificationView(View):
|
|
|
|
|
|
# 推送
|
|
|
if detect_med_type == 2 or detect_med_type == 0:
|
|
|
-
|
|
|
try:
|
|
|
if push_type == 0: # ios apns
|
|
|
print('do_apns')
|
|
@@ -293,7 +262,6 @@ class NotificationView(View):
|
|
|
print('do_jpush')
|
|
|
do_jpush_code = self.do_jpush(**kwag_args)
|
|
|
push_server_status = do_jpush_code
|
|
|
- # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
|
|
|
except Exception as e:
|
|
|
logger.info("errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno,
|
|
|
errMsg=repr(e)))
|
|
@@ -306,7 +274,6 @@ class NotificationView(View):
|
|
|
if is_sys_msg:
|
|
|
SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
else:
|
|
|
- # Equipment_Info.objects.bulk_create(eq_list)
|
|
|
if new_device_info_list and len(new_device_info_list) > 0:
|
|
|
# 根据日期获得星期几
|
|
|
week = LocalDateTimeUtil.date_to_week(local_date_time)
|
|
@@ -330,7 +297,7 @@ class NotificationView(View):
|
|
|
del up['uid_set__nickname']
|
|
|
del up['uid_set__detect_interval']
|
|
|
del up['uid_set__detect_group']
|
|
|
- return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2' ,'re_list':redis_list})
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2'})
|
|
|
|
|
|
elif is_st == '1':
|
|
|
print("is_st=1")
|
|
@@ -353,7 +320,7 @@ class NotificationView(View):
|
|
|
del up['uid_set__detect_group']
|
|
|
# 不是正式服务器
|
|
|
if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
|
|
|
+ res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
|
else:
|
|
|
# 是正式服务器的时候
|
|
|
res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
@@ -387,13 +354,12 @@ class NotificationView(View):
|
|
|
|
|
|
# 不是正式服务器
|
|
|
if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
|
|
|
+ res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
|
|
|
else:
|
|
|
# 是正式服务器的时候
|
|
|
res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
-
|
|
|
def get_msg_title(self, appBundleId, nickname):
|
|
|
package_title_config = {
|
|
|
'com.ansjer.customizedd_a': 'DVS',
|
|
@@ -420,7 +386,7 @@ class NotificationView(View):
|
|
|
return False
|
|
|
|
|
|
def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
|
|
|
- n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
|
|
|
etype = int(event_type)
|
|
|
if lang == 'cn':
|
|
|
if etype == 704:
|
|
@@ -616,7 +582,7 @@ class PushNotificationView(View):
|
|
|
# 从数据库查询出来
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
|
- 'push_type', 'userID_id', 'lang','m_code',
|
|
|
+ 'push_type', 'userID_id', 'lang', 'm_code',
|
|
|
'tz', 'uid_set__nickname')
|
|
|
# 新建一个list接收数据
|
|
|
redis_list = []
|