|
@@ -38,6 +38,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
|
|
|
+
|
|
|
'''
|
|
|
|
|
|
|
|
@@ -267,7 +270,7 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(14)
|
|
|
|
|
|
- def do_change_status(self, userID, request_dict, response):
|
|
|
+ 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)
|
|
@@ -288,6 +291,7 @@ class DetectControllerView(View):
|
|
|
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,11 +299,11 @@ class DetectControllerView(View):
|
|
|
if appBundleId not in FCM_CONFIG.keys():
|
|
|
return response.json(904)
|
|
|
elif push_type == '2':
|
|
|
- print('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)
|
|
|
# 新增a
|
|
|
if start_status == "1":
|
|
@@ -346,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:
|
|
@@ -404,6 +536,7 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
|
|
|
+
|
|
|
# http://192.168.136.40:8077/notify/push?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJUTjdNUEUzMjExVUU3NkFQMTExQSJ9.k501567VdnhFpn_ygzGRDat3Kqlz5CsEA9jAC2dDk_g&obj=12341234&n_time=1234561234
|
|
|
# http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
|
# 移动侦测接口
|
|
@@ -445,16 +578,17 @@ class NotificationView(View):
|
|
|
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侦测
|
|
|
+ # 新增 pir侦测
|
|
|
if event_type == '1':
|
|
|
self.detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st)
|
|
|
- #新增 移动侦测和pir侦测
|
|
|
+ # 新增 移动侦测和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)
|
|
@@ -534,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)
|
|
@@ -597,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,
|
|
@@ -618,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('---')
|
|
|
|
|
@@ -711,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')
|
|
@@ -774,4 +909,4 @@ class PushNotificationView(View):
|
|
|
Equipment_Info.objects.bulk_create(qs_list)
|
|
|
return True
|
|
|
else:
|
|
|
- return False
|
|
|
+ return False
|