|
@@ -37,6 +37,9 @@ http://push.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
|
|
|
|
|
|
http://www.dvema.com/detect/changeStatus?push_type=2&token_val=1a0018970a332cca935&appBundleId=com.ansjer.zccloud_ab&tz=+08.00&uid=HLK7EJ2VYLNHHUMG111A&status=1&m_code=AN02000025070000001207.zccloud_ab&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyIjoiMTMxMTk2NTc3MTMiLCJsYW5nIjoiZW4iLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJ1c2VySUQiOiIxNTQ0ODM4MjMyOTczMTM4MDAxMzgwMDAiLCJleHAiOjE1ODQxNDc0NjN9.NjK91B26jZDtdmq8tW-8hXNQPqqDfo9Zwf_Jg6Uf7co&lang=cn&app_type=2
|
|
|
|
|
|
+http://127.0.0.1:8077/detect/changeStatus?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTg0MzUxODk2MjgyMTM4MDAxMzgwMDAiLCJsYW5nIjoiZW4iLCJ1c2VyIjoiMTM2ODAzMTc1OTYiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1ODcyNjEzODN9.H87931EDg6PGZK63EAsvY1FRJov9qo_S70mBKvpZeQM&push_type=2&token_val=token_val&appBundleId=appBundleId&tz=0&uid=158440619973313800138000&status=1&m_code&lang=cn&app_type=0&start_status=1&interval=60&eventType=60
|
|
|
+http://192.168.136.140:8077/detect/changeStatus?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySUQiOiIxNTg0MzUxODk2MjgyMTM4MDAxMzgwMDAiLCJsYW5nIjoiZW4iLCJ1c2VyIjoiMTM2ODAzMTc1OTYiLCJtX2NvZGUiOiIxMjM0MTMyNDMyMTQiLCJleHAiOjE1ODcyNjEzODN9.H87931EDg6PGZK63EAsvY1FRJov9qo_S70mBKvpZeQM&push_type=2&token_val=token_val&appBundleId=appBundleId&tz=0&uid=158440619973313800138000&status=1&m_code&lang=cn&app_type=0&start_status=1&interval=60&eventType=60
|
|
|
+detect/changeStatus
|
|
|
|
|
|
'''
|
|
|
|
|
@@ -65,6 +68,7 @@ class DetectControllerView(View):
|
|
|
userID = tko.userID
|
|
|
# 修改推送设置
|
|
|
if operation == 'changeStatus':
|
|
|
+ print("进入changeStatus")
|
|
|
return self.do_change_status(userID, request_dict, response)
|
|
|
# 查询推送信息
|
|
|
elif operation == 'queryInfo':
|
|
@@ -266,24 +270,28 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(14)
|
|
|
|
|
|
- def do_change_status(self, userID, request_dict, response):
|
|
|
- uid = request_dict.get('uid', None)
|
|
|
+ def do_change_status11(self, userID, request_dict, response):
|
|
|
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)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ detect_group = request_dict.get('eventType', None)
|
|
|
# 设备语言
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
tz = request_dict.get('tz', '0')
|
|
|
+ start_status = request_dict.get('start_status', None)
|
|
|
# interval = request_dict.get('interval', None)
|
|
|
if not status:
|
|
|
return response.json(444, 'status')
|
|
|
+ print("111")
|
|
|
# 关闭推送
|
|
|
if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
# 判断推送类型对应key是否存在
|
|
|
+ print('push_type:', push_type)
|
|
|
if push_type == '0':
|
|
|
if appBundleId not in APNS_CONFIG.keys():
|
|
|
return response.json(904)
|
|
@@ -295,7 +303,23 @@ class DetectControllerView(View):
|
|
|
return response.json(904)
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
+
|
|
|
dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ # 新增a
|
|
|
+ if start_status == "1":
|
|
|
+ interval = request_dict.get('interval', None)
|
|
|
+ # 设备表,用于判断这台设备是否存在
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ if dvqs.exists():
|
|
|
+ uid_set_qs = UidSetModel.objects. \
|
|
|
+ filter(uid=uid, uidpushmodel__userID_id=userID)
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_qs.update(detect_interval=int(interval))
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ # 移动侦测 evenType为字符串0,将detect_group设置进数据库
|
|
|
+ UidSetModel.objects.filter(uid=uid, uidpushmodel__userID_id=userID).update(detect_group=detect_group)
|
|
|
+ # /新增a
|
|
|
status = int(status)
|
|
|
# 获取用户区域
|
|
|
# ip = self.ip
|
|
@@ -326,7 +350,135 @@ class DetectControllerView(View):
|
|
|
UidPushModel.objects.filter(uid_set__uid=uid).delete()
|
|
|
# 状态为0的时候删除redis缓存数据
|
|
|
ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
- redisObj = RedisObject(db=6,SERVER_HOST = 'push.dvema.com')
|
|
|
+ redisObj = RedisObject(db=6, SERVER_HOST='push.dvema.com')
|
|
|
+ redisObj.del_data(key=ykey)
|
|
|
+ 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})
|
|
|
+ etkObj = ETkObject(etk='')
|
|
|
+ etk = etkObj.encrypt(uid)
|
|
|
+ detectUrl = "{DETECT_PUSH_DOMAIN}notify/push?etk={etk}". \
|
|
|
+ format(etk=etk, DETECT_PUSH_DOMAIN=DETECT_PUSH_DOMAIN)
|
|
|
+ return response.json(0, {'detectUrl': detectUrl})
|
|
|
+ else:
|
|
|
+ return response.json(14)
|
|
|
+
|
|
|
+ def do_change_status(self, userID, request_dict, response):
|
|
|
+ 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)
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ # 设备语言
|
|
|
+ lang = request_dict.get('lang', 'en')
|
|
|
+ tz = request_dict.get('tz', '0')
|
|
|
+ # 消息提醒功能新增
|
|
|
+ detect_group = request_dict.get('detect_group', None)
|
|
|
+ interval = request_dict.get('interval', None)
|
|
|
+ if not status:
|
|
|
+ return response.json(444, 'status')
|
|
|
+ print("111")
|
|
|
+ # 关闭推送
|
|
|
+ if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
+ return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
+ # 判断推送类型对应key是否存在
|
|
|
+ print('push_type:', push_type)
|
|
|
+
|
|
|
+ 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
|
|
|
+ qs_data = {
|
|
|
+ 'detect_status': status,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ }
|
|
|
+ if interval:
|
|
|
+ qs_data['detect_interval'] = int(interval)
|
|
|
+ if detect_group:
|
|
|
+ qs_data['detect_group'] = detect_group
|
|
|
+ print(qs_data)
|
|
|
+ uid_set_qs.update(**qs_data)
|
|
|
+
|
|
|
+ else:
|
|
|
+ qs_data = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'detect_status': status,
|
|
|
+ }
|
|
|
+ if interval:
|
|
|
+ qs_data['detect_interval'] = int(interval)
|
|
|
+ if detect_group:
|
|
|
+ qs_data['detect_group'] = detect_group
|
|
|
+ # 添加设备配置
|
|
|
+ uid_set_qs = UidSetModel.objects.create(**qs_data)
|
|
|
+
|
|
|
+ uid_set_id = uid_set_qs.id
|
|
|
+
|
|
|
+ if status == 0:
|
|
|
+ UidPushModel.objects.filter(uid_set__uid=uid).delete()
|
|
|
+ # 状态为0的时候删除redis缓存数据
|
|
|
+ ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
+ redisObj = RedisObject(db=6, SERVER_HOST='push.dvema.com')
|
|
|
redisObj.del_data(key=ykey)
|
|
|
return response.json(0)
|
|
|
elif status == 1:
|
|
@@ -423,16 +575,30 @@ class NotificationView(View):
|
|
|
uid = utko.UID
|
|
|
# utko = UidTokenObject(uidToken)
|
|
|
# uid = utko.UID
|
|
|
+ detect_group = UidSetModel.objects.filter(uid=uid). \
|
|
|
+ values('detect_group')
|
|
|
+ event_type = detect_group
|
|
|
+ # 新增 移动侦测
|
|
|
+ if event_type == '0':
|
|
|
+ self.detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st)
|
|
|
+ # 新增 pir侦测
|
|
|
+ if event_type == '1':
|
|
|
+ self.detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st)
|
|
|
+ # 新增 移动侦测和pir侦测
|
|
|
+ if event_type == '01':
|
|
|
+ self.detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st)
|
|
|
+
|
|
|
+ # 新增 把代码封装以便后面分侦测类型
|
|
|
+ def detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st):
|
|
|
redisObj = RedisObject(db=6)
|
|
|
- # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
- pkey = '{uid}_ptl'.format(uid=uid)
|
|
|
+ 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_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
|
|
|
+ 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', 'userID__NickName',
|
|
|
'lang', 'tz', 'uid_set__nickname')
|
|
@@ -451,11 +617,11 @@ class NotificationView(View):
|
|
|
# android gcm
|
|
|
elif push_type == 1:
|
|
|
self.do_fcm(request_dict, up, response, uid, channel, nickname)
|
|
|
- # self.do_gmc(request_dict, up, response, uid, channel,nickname)
|
|
|
+ # self.do_gmc(request_dict, up, response, uid, channel,nickname)
|
|
|
# android jpush
|
|
|
elif push_type == 2:
|
|
|
self.do_jpush(request_dict, up, response, uid, channel, nickname)
|
|
|
- # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
+ # 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':
|
|
@@ -502,7 +668,7 @@ class NotificationView(View):
|
|
|
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}
|
|
|
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,event_type=event_type)
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
|
|
|
android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
|
|
|
big_text=send_text, title=message_title,
|
|
|
extras=push_data)
|
|
@@ -565,7 +731,7 @@ class NotificationView(View):
|
|
|
push_service = FCMNotification(api_key=serverKey)
|
|
|
registration_id = token_val
|
|
|
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,event_type=event_type)
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
|
|
|
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}
|
|
|
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
|
|
@@ -586,7 +752,7 @@ class NotificationView(View):
|
|
|
appBundleId = uaql['appBundleId']
|
|
|
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,event_type=event_type)
|
|
|
+ send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
|
|
|
try:
|
|
|
print('---')
|
|
|
|
|
@@ -679,8 +845,9 @@ class PushNotificationView(View):
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
else:
|
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
- 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', 'userID__NickName', 'lang', 'tz', 'uid_set__nickname')
|
|
|
+ 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', 'userID__NickName', 'lang',
|
|
|
+ 'tz', 'uid_set__nickname')
|
|
|
if uid_push_qs.exists():
|
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|