chenjunkai 6 éve
szülő
commit
6148635eac
1 módosított fájl, 9 hozzáadás és 6 törlés
  1. 9 6
      Controller/DetectController.py

+ 9 - 6
Controller/DetectController.py

@@ -167,7 +167,8 @@ class NotificationView(View):
         response = ResponseObject()
         uidToken = request_dict.get('uidToken', None)
         channel = request_dict.get('channel', None)
-        n_time = request_dict.get('n_time')
+        n_time = request_dict.get('n_time',None)
+        event_type = request_dict.get('event_type',None)
         if not all([uidToken, channel, n_time]):
             return JsonResponse(status=404)
             # return response.json(444)
@@ -187,7 +188,7 @@ class NotificationView(View):
                 # android jpush
                 elif push_type == 2:
                     self.do_jpush(request_dict, ua, response)
-                self.do_save_equipment_info(ua, n_time, channel)
+                self.do_save_equipment_info(ua, n_time, channel,event_type)
             #############
             # 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
             auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
@@ -209,6 +210,7 @@ class NotificationView(View):
                 'msg': 'data is not exist'})
 
     def do_jpush(self, request_dict, uaql, response):
+        event_type = request_dict.get('event_type',None)
         jpush_config = {
             'com.ansjer.accloud_ab': {
                 'Key': 'f0dc047e5e53fd14199de5b0',
@@ -259,7 +261,7 @@ class NotificationView(View):
         _jpush.set_logging("DEBUG")
         # push.audience = jpush.all_
         push.audience = jpush.registration_id(token_val)
-        push_data = {"alert": "Motion ", "event_time": n_time, "event_type": "51", "msg": "",
+        push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
                      "received_at": n_time, "sound": "sound.aif", "uid": uid}
         push_msg = json.dumps(push_data)
         # push.notification = jpush.notification(alert="hello jpush api")
@@ -294,7 +296,8 @@ class NotificationView(View):
             'com.ansjer.customizeda_a': 'AAAAb9YP3rk:APA91bF0HzizVWDc6dKzobY9fsaKDK4veqkOZehDXshVXs8pEEvNWjR_YWbhP60wsRYCHCal8fWN5cECVOWNMMzDsfU88Ty2AUl8S5FtZsmeDTkoGntQOswBr8Ln7Fm_LAp1VqTf9CpM',
         }
         serverKey = gcm_config[appBundleId]
-        push_data = {"alert": "Motion ", "event_time": n_time, "event_type": "51", "msg": "",
+        event_type = request_dict.get('event_type',None)
+        push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
                      "received_at": n_time, "sound": "sound.aif", "uid": uid}
         json_data = {
             "collapse_key": "WhatYouWant",
@@ -340,11 +343,11 @@ class NotificationView(View):
         except Exception as e:
             return response.json(10, repr(e))
 
-    def do_save_equipment_info(self, uaql, n_time, channel):
+    def do_save_equipment_info(self, uaql, n_time, channel,event_type):
         Equipment_Info.objects.create(
             userID_id=uaql['userID_id'],
             eventTime=n_time,
-            eventType=1,
+            eventType=event_type,
             devUid=uaql['uid'],
             devNickName=uaql['userID__NickName'],
             Channel=channel,