|
@@ -146,6 +146,7 @@ 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)
|
|
if not status:
|
|
if not status:
|
|
return response.json(444, 'status')
|
|
return response.json(444, 'status')
|
|
@@ -168,9 +169,9 @@ class DetectControllerView(View):
|
|
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:
|
|
@@ -186,7 +187,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). \
|
|
@@ -230,7 +232,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)
|
|
@@ -292,8 +295,11 @@ class NotificationView(View):
|
|
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')
|
|
|
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
|
|
|
|
+ 'tz')
|
|
if uid_set_qs.exists():
|
|
if uid_set_qs.exists():
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
@@ -341,7 +347,7 @@ 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']
|
|
-
|
|
|
|
|
|
+ tz = uaql['tz']
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
@@ -354,24 +360,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)
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- # message_title = "周视({uid})".format(uid=uid)
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
|
|
- send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
- else:
|
|
|
|
- if nickname:
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
- # message_title = "zosi({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
|
|
-
|
|
|
|
- # 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)
|
|
@@ -408,11 +398,19 @@ class NotificationView(View):
|
|
else:
|
|
else:
|
|
return nickname
|
|
return nickname
|
|
|
|
|
|
|
|
+ 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']
|
|
|
|
+ tz = uaql['tz']
|
|
try:
|
|
try:
|
|
serverKey = FCM_CONFIG[appBundleId]
|
|
serverKey = FCM_CONFIG[appBundleId]
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -420,24 +418,8 @@ class NotificationView(View):
|
|
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)
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- # message_title = "周视({uid})".format(uid=uid)
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
|
|
- send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
|
|
|
|
- else:
|
|
|
|
- if nickname:
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
|
- # message_title = "zosi({nickname})".format(nickname=nickname)
|
|
|
|
- else:
|
|
|
|
- message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
|
|
|
|
-
|
|
|
|
- # 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,
|
|
@@ -456,19 +438,9 @@ 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']
|
|
- 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'],
|
|
cli = apns2.APNSClient(mode="dev", client_cert=APNS_CONFIG[appBundleId]['pem_path'],
|
|
password=APNS_CONFIG[appBundleId]['password'])
|
|
password=APNS_CONFIG[appBundleId]['password'])
|