Browse Source

fix:
detect push code bug

chenjunkai 6 years ago
parent
commit
b4973523a4
1 changed files with 15 additions and 18 deletions
  1. 15 18
      Controller/DetectController.py

+ 15 - 18
Controller/DetectController.py

@@ -319,9 +319,8 @@ class NotificationView(View):
         if uid_set_qs.exists():
             uid_set_id = uid_set_qs[0].id
             uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id).values('token_val', 'app_type',
-                                                                                     'appBundleId', 'push_type', 'uid',
-                                                                                     'userID_id', 'userID__NickName',
-                                                                                     'interval')
+                                                                                     'appBundleId', 'push_type',
+                                                                                     'userID_id', 'userID__NickName')
             if uid_set_qs.exists():
                 redisObj = RedisObject(db=6)
                 pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
@@ -329,26 +328,25 @@ class NotificationView(View):
                     res_data = {'code': 0, 'msg': 'success,!'}
                     return JsonResponse(status=200, data=res_data)
                 else:
-                    detect_interval = UidSetModel[0].detect_interval
+                    detect_interval = uid_set_qs[0].detect_interval
                     if detect_interval:
                         redisObj.set_data(key=pkey, val=1, expire=detect_interval)
-
                 auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
                 bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
                 for up in uid_push_qs:
                     push_type = up['push_type']
                     # ios apns
                     if push_type == 0:
-                        self.do_apns(request_dict, up, response)
+                        self.do_apns(request_dict, up, response, uid)
                     # android gcm
                     elif push_type == 1:
-                        self.do_gmc(request_dict, up, response)
+                        self.do_gmc(request_dict, up, response, uid)
                     # android jpush
                     elif push_type == 2:
-                        self.do_jpush(request_dict, up, response)
+                        self.do_jpush(request_dict, up, response, uid)
                     # 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)
+                self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
                 if is_st == '0' or is_st == '2':
                     return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
                 else:
@@ -363,7 +361,7 @@ class NotificationView(View):
         else:
             return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
 
-    def do_jpush(self, request_dict, uaql, response):
+    def do_jpush(self, request_dict, uaql, response, uid):
         event_type = request_dict.get('event_type', None)
         jpush_config = {
             'com.ansjer.accloud_ab': {
@@ -403,7 +401,6 @@ class NotificationView(View):
         n_time = request_dict.get('n_time', None)
         appBundleId = uaql['appBundleId']
         token_val = uaql['token_val']
-        uid = uaql['uid']
 
         response = ResponseObject()
         app_key = jpush_config[appBundleId]['Key']
@@ -429,12 +426,11 @@ class NotificationView(View):
         else:
             return response.json(0)
 
-    def do_gmc(self, request_dict, uaql, response):
+    def do_gmc(self, request_dict, uaql, response, uid):
 
         n_time = request_dict.get('n_time')
         appBundleId = uaql['appBundleId']
         token_val = uaql['token_val']
-        uid = uaql['uid']
         gcm_config = {
             'com.ansjer.zccloud_a': 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I',
             'com.ansjer.loocamccloud_a': 'AAAAb9YP3rk:APA91bFCgd-kbVmpK4EVpfdHH_PJZQCYTkOGnTZdIuBWEz2r7aMRsJYHOH3sB-rwcbaRWgnufTyjX9nGQxb6KxQbWVk4ah_H-M3IqGh6Mb60WQQAuR33V6g_Jes5pGL6ViuIxGHqVMaR',
@@ -462,11 +458,10 @@ class NotificationView(View):
         req = requests.post(url, data, headers=headers)
         return response.json(0)
 
-    def do_apns(self, request_dict, uaql, response):
+    def do_apns(self, request_dict, uaql, response, uid):
         token_val = uaql['token_val']
         n_time = request_dict.get('n_time')
         appBundleId = uaql['appBundleId']
-        uid = uaql['uid']
         apns_config = {
             'appbundleId': {'pem_path': 'xxxx', 'topic': 'topic', 'password': 'password'}
         }
@@ -490,17 +485,19 @@ class NotificationView(View):
         except Exception as e:
             return response.json(10, repr(e))
 
-    def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
+    def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
         #
         qs_list = []
         nowTime = int(time.time())
+        # 设备昵称
+
         for dv in uaqs:
             add_data = {
                 'userID_id': dv["userID_id"],
                 'eventTime': n_time,
                 'eventType': event_type,
-                'devUid': dv['uid'],
-                'devNickName': '',
+                'devUid': uid,
+                'devNickName': uid,
                 'Channel': channel,
                 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
                 'is_st': int(is_st),