|
@@ -29,6 +29,7 @@ import requests
|
|
from Model.models import Equipment_Info
|
|
from Model.models import Equipment_Info
|
|
|
|
|
|
|
|
|
|
|
|
+# http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1
|
|
class DetectControllerView(View):
|
|
class DetectControllerView(View):
|
|
@method_decorator(csrf_exempt)
|
|
@method_decorator(csrf_exempt)
|
|
def dispatch(self, *args, **kwargs):
|
|
def dispatch(self, *args, **kwargs):
|
|
@@ -59,35 +60,42 @@ class DetectControllerView(View):
|
|
else:
|
|
else:
|
|
return response.json(tko.code)
|
|
return response.json(tko.code)
|
|
|
|
|
|
- def do_change_status(self, userID, uid, request_dict, response):
|
|
|
|
|
|
+ def do_change_status(self, userID, request_dict, response):
|
|
uid = request_dict.get('uid', None)
|
|
uid = request_dict.get('uid', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
token_val = request_dict.get('token_val', None)
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
push_type = request_dict.get('push_type', None)
|
|
push_type = request_dict.get('push_type', None)
|
|
- dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
|
- aiqs = App_Info.objects.filter(appBundleId=appBundleId).values('app_type')
|
|
|
|
- if dvqs.exists() and aiqs.exists():
|
|
|
|
- now_time = int(time.time())
|
|
|
|
- try:
|
|
|
|
- UID_App.objects.create(
|
|
|
|
- uid=uid,
|
|
|
|
- userID_id=userID,
|
|
|
|
- appBundleId=appBundleId,
|
|
|
|
- app_type=aiqs[0]['app_type'],
|
|
|
|
- push_type=push_type,
|
|
|
|
- token_val=token_val,
|
|
|
|
- addTime=now_time,
|
|
|
|
- updTime=now_time)
|
|
|
|
- except Exception as e:
|
|
|
|
- print(repr(e))
|
|
|
|
|
|
+ status = request_dict.get('status', None)
|
|
|
|
+ if status == 0:
|
|
|
|
+ UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, token_val=token_val, uid=uid).delete()
|
|
|
|
+ return response.json(0)
|
|
|
|
+ elif status == 1:
|
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
|
+ aiqs = App_Info.objects.filter(appBundleId=appBundleId).values('app_type')
|
|
|
|
+ print(dvqs)
|
|
|
|
+ print(aiqs)
|
|
|
|
+ if dvqs.exists() and aiqs.exists():
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ try:
|
|
|
|
+ UID_App.objects.create(
|
|
|
|
+ uid=uid,
|
|
|
|
+ userID_id=userID,
|
|
|
|
+ appBundleId=appBundleId,
|
|
|
|
+ app_type=aiqs[0]['app_type'],
|
|
|
|
+ push_type=push_type,
|
|
|
|
+ token_val=token_val,
|
|
|
|
+ addTime=now_time,
|
|
|
|
+ updTime=now_time)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(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:
|
|
else:
|
|
- utko = UidTokenObject()
|
|
|
|
- utko.generate(data={'uid': uid})
|
|
|
|
- detectUrl = "{SERVER_DOMAIN}detect/push?uidToken={uidToken}". \
|
|
|
|
- format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
|
- return response.json(0, {'detectUrl': detectUrl})
|
|
|
|
- else:
|
|
|
|
- return response.json(173)
|
|
|
|
|
|
+ return response.json(173)
|
|
|
|
|
|
|
|
|
|
class NotificationView(View):
|
|
class NotificationView(View):
|
|
@@ -102,15 +110,13 @@ class NotificationView(View):
|
|
# operation = kwargs.get('operation')
|
|
# operation = kwargs.get('operation')
|
|
return self.validation(request.POST)
|
|
return self.validation(request.POST)
|
|
|
|
|
|
- def validation(self, request_dict, operation):
|
|
|
|
|
|
+ def validation(self, request_dict):
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
- if operation is None:
|
|
|
|
- return response.json(444, 'error path')
|
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
uidToken = request_dict.get('uidToken', None)
|
|
utko = UidTokenObject(uidToken)
|
|
utko = UidTokenObject(uidToken)
|
|
uid = utko.UID
|
|
uid = utko.UID
|
|
uaqs = UID_App.objects.filter(uid=uid). \
|
|
uaqs = UID_App.objects.filter(uid=uid). \
|
|
- values('token_val', 'app_type', 'appBundleId', 'push_type', 'uid', 'userID_id')
|
|
|
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type', 'uid', 'userID_id', 'userID__NickName')
|
|
if uaqs.exists():
|
|
if uaqs.exists():
|
|
for ua in uaqs:
|
|
for ua in uaqs:
|
|
push_type = ua['push_type']
|
|
push_type = ua['push_type']
|
|
@@ -180,14 +186,23 @@ class NotificationView(View):
|
|
_jpush.set_logging("DEBUG")
|
|
_jpush.set_logging("DEBUG")
|
|
# push.audience = jpush.all_
|
|
# push.audience = jpush.all_
|
|
push.audience = jpush.registration_id(token_val)
|
|
push.audience = jpush.registration_id(token_val)
|
|
- push_msg = json.dumps({'n_time': n_time, 'uid': uid})
|
|
|
|
|
|
+ push_data = {"alert": "Motion ", "event_time": n_time, "event_type": "51", "msg": "",
|
|
|
|
+ "received_at": n_time, "sound": "sound.aif", "uid": uid}
|
|
|
|
+ push_msg = json.dumps(push_data)
|
|
# push.notification = jpush.notification(alert="hello jpush api")
|
|
# push.notification = jpush.notification(alert="hello jpush api")
|
|
- push.notification = jpush.notification(alert=push_msg)
|
|
|
|
|
|
+ # push.notification = jpush.notification(alert=push_msg)
|
|
|
|
+ # android = jpush.android(alert="Hello, Android msg",extras=push_data)
|
|
|
|
+
|
|
|
|
+ # push.notification = jpush.notification(alert="Hello, JPush!", android=android)
|
|
|
|
+ # push.notification = jpush.message(msg_content=push_data, extras=push_data)
|
|
|
|
+ push.message = jpush.message('Motion', extras=push_data, title='KPNS', content_type='text')
|
|
push.platform = jpush.all_
|
|
push.platform = jpush.all_
|
|
try:
|
|
try:
|
|
res = push.send()
|
|
res = push.send()
|
|
|
|
+ print(res)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print("Exception")
|
|
print("Exception")
|
|
|
|
+ print(repr(e))
|
|
return response.json(10, repr(e))
|
|
return response.json(10, repr(e))
|
|
else:
|
|
else:
|
|
return response.json(0)
|
|
return response.json(0)
|
|
@@ -206,11 +221,11 @@ class NotificationView(View):
|
|
'com.ansjer.customizeda_a': 'AAAAb9YP3rk:APA91bF0HzizVWDc6dKzobY9fsaKDK4veqkOZehDXshVXs8pEEvNWjR_YWbhP60wsRYCHCal8fWN5cECVOWNMMzDsfU88Ty2AUl8S5FtZsmeDTkoGntQOswBr8Ln7Fm_LAp1VqTf9CpM',
|
|
'com.ansjer.customizeda_a': 'AAAAb9YP3rk:APA91bF0HzizVWDc6dKzobY9fsaKDK4veqkOZehDXshVXs8pEEvNWjR_YWbhP60wsRYCHCal8fWN5cECVOWNMMzDsfU88Ty2AUl8S5FtZsmeDTkoGntQOswBr8Ln7Fm_LAp1VqTf9CpM',
|
|
}
|
|
}
|
|
serverKey = gcm_config[appBundleId]
|
|
serverKey = gcm_config[appBundleId]
|
|
-
|
|
|
|
- msg = {'n_time': n_time, 'uid': uid}
|
|
|
|
|
|
+ push_data = {"alert": "Motion ", "event_time": n_time, "event_type": "51", "msg": "",
|
|
|
|
+ "received_at": n_time, "sound": "sound.aif", "uid": uid}
|
|
json_data = {
|
|
json_data = {
|
|
"collapse_key": "WhatYouWant",
|
|
"collapse_key": "WhatYouWant",
|
|
- "data": msg,
|
|
|
|
|
|
+ "data": push_data,
|
|
"delay_while_idle": False,
|
|
"delay_while_idle": False,
|
|
"time_to_live": 3600,
|
|
"time_to_live": 3600,
|
|
"registration_ids": [token_val]
|
|
"registration_ids": [token_val]
|
|
@@ -254,17 +269,12 @@ class NotificationView(View):
|
|
return response.json(10, repr(e))
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
def do_save_equipment_info(self, uaql, n_time):
|
|
def do_save_equipment_info(self, uaql, n_time):
|
|
- try:
|
|
|
|
- Equipment_Info.objects.create(
|
|
|
|
- userID_id=uaql['userID_id'],
|
|
|
|
- eventTime=n_time,
|
|
|
|
- eventType=1,
|
|
|
|
- devUid=uaql['uid'],
|
|
|
|
- devNickName=uaql['devNickName'],
|
|
|
|
- Channel='0',
|
|
|
|
- alarm='0',
|
|
|
|
- receiveTime=n_time)
|
|
|
|
- except Exception as e:
|
|
|
|
- return False
|
|
|
|
- else:
|
|
|
|
- return True
|
|
|
|
|
|
+ Equipment_Info.objects.create(
|
|
|
|
+ userID_id=uaql['userID_id'],
|
|
|
|
+ eventTime=n_time,
|
|
|
|
+ eventType=1,
|
|
|
|
+ devUid=uaql['uid'],
|
|
|
|
+ devNickName=uaql['userID__NickName'],
|
|
|
|
+ Channel='0',
|
|
|
|
+ alarm='0',
|
|
|
|
+ receiveTime=n_time)
|