chenjunkai 5 years ago
parent
commit
e9de5aaa1e
1 changed files with 4 additions and 61 deletions
  1. 4 61
      Controller/DetectController.py

+ 4 - 61
Controller/DetectController.py

@@ -445,7 +445,8 @@ class NotificationView(View):
         try:
             print('---')
 
-            cli = apns2.APNSClient(mode=APNS_MODE, client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
+            cli = apns2.APNSClient(mode=APNS_MODE,
+                                   client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
             # password=APNS_CONFIG[appBundleId]['password'])
             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}
@@ -500,7 +501,7 @@ class NotificationView(View):
 # 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
 # 移动侦测接口
-class NotificationView(View):
+class NotificationViewXX(View):
 
     def get(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
@@ -517,62 +518,4 @@ class NotificationView(View):
         uidToken = request_dict.get('uidToken', None)
         channel = request_dict.get('channel', '1')
         n_time = request_dict.get('n_time', None)
-        event_type = request_dict.get('event_type', None)
-        is_st = request_dict.get('is_st', None)
-        if not all([uidToken, channel, n_time]):
-            return JsonResponse(status=200, data={
-                'code': 444,
-                'msg': 'param is wrong'})
-            # return response.json(444)
-        utko = UidTokenObject(uidToken)
-        uid = utko.UID
-        uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
-        if uid_set_qs.exists():
-            uid_set_id = uid_set_qs[0].id
-            nickname = uid_set_qs[0].nickname
-            if not nickname:
-                nickname = uid
-            uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
-                values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
-                       'tz')
-            if uid_set_qs.exists():
-                redisObj = RedisObject(db=6)
-                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:
-                    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
-                    print(push_type)
-                    if push_type == 0:
-                        self.do_apns(request_dict, up, response, uid, channel, nickname)
-                    # 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)
-                    # 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_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:
-                    # Endpoint以杭州为例,其它Region请按实际情况填写。
-                    obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
-                    # 设置此签名URL在60秒内有效。
-                    url = bucket.sign_url('PUT', obj, 7200)
-                    res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
-                    return JsonResponse(status=200, data=res_data)
-            else:
-                return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
-        else:
-            return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
+        return