chenjunkai 5 gadi atpakaļ
vecāks
revīzija
deece79f9a

+ 44 - 1
AnsjerPush/formal_settings.py

@@ -133,4 +133,47 @@ CORS_ALLOW_HEADERS = (
     'user-agent',
     'user-agent',
     'x-csrftoken',
     'x-csrftoken',
     'x-requested-with',
     'x-requested-with',
-)
+)
+
+
+# 日志模块
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': True,
+    'formatters': {
+        'error_format': {
+            # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
+            'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
+        },
+    },
+    'filters': {
+    },
+    'handlers': {
+        'mail_admins': {
+            'level': 'ERROR',
+            'class': 'django.utils.log.AdminEmailHandler',
+            'include_html': True,
+        },
+        'default': {
+            'level': 'ERROR',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/error.log',
+            'maxBytes': 1024 * 1024 * 5,  # 5 MB
+            'backupCount': 5,
+            'formatter': 'error_format',
+        },
+        'console': {
+            'level': 'ERROR',
+            'class': 'logging.StreamHandler',
+            'formatter': 'error_format'
+        },
+    },
+    'loggers': {
+        'django': {
+            'handlers': ['default', 'console'],
+            # 'handlers': ['mail_admins','default','console'],
+            'level': 'ERROR',
+            'propagate': False
+        },
+    }
+}

+ 44 - 1
AnsjerPush/local_settings.py

@@ -142,4 +142,47 @@ CORS_ALLOW_HEADERS = (
     'user-agent',
     'user-agent',
     'x-csrftoken',
     'x-csrftoken',
     'x-requested-with',
     'x-requested-with',
-)
+)
+
+
+# 日志模块
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': True,
+    'formatters': {
+        'error_format': {
+            # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
+            'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
+        },
+    },
+    'filters': {
+    },
+    'handlers': {
+        'mail_admins': {
+            'level': 'ERROR',
+            'class': 'django.utils.log.AdminEmailHandler',
+            'include_html': True,
+        },
+        'default': {
+            'level': 'ERROR',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/error.log',
+            'maxBytes': 1024 * 1024 * 5,  # 5 MB
+            'backupCount': 5,
+            'formatter': 'error_format',
+        },
+        'console': {
+            'level': 'ERROR',
+            'class': 'logging.StreamHandler',
+            'formatter': 'error_format'
+        },
+    },
+    'loggers': {
+        'django': {
+            'handlers': ['default', 'console'],
+            # 'handlers': ['mail_admins','default','console'],
+            'level': 'ERROR',
+            'propagate': False
+        },
+    }
+}

+ 43 - 1
AnsjerPush/test_settings.py

@@ -134,4 +134,46 @@ CORS_ALLOW_HEADERS = (
     'user-agent',
     'user-agent',
     'x-csrftoken',
     'x-csrftoken',
     'x-requested-with',
     'x-requested-with',
-)
+)
+
+# 日志模块
+LOGGING = {
+    'version': 1,
+    'disable_existing_loggers': True,
+    'formatters': {
+        'error_format': {
+            # 'format': '{"asctime":"%(asctime)s","thread":"%(threadName)s:%(thread)d","errorline":"%(lineno)d","errorlevel":"%(levelname)s","errorcontent":"%(message)s"}'
+            'format': '%(asctime)s %(threadName)s %(thread)d %(lineno)d %(levelname)s %(message)s'
+        },
+    },
+    'filters': {
+    },
+    'handlers': {
+        'mail_admins': {
+            'level': 'ERROR',
+            'class': 'django.utils.log.AdminEmailHandler',
+            'include_html': True,
+        },
+        'default': {
+            'level': 'ERROR',
+            'class': 'logging.handlers.RotatingFileHandler',
+            'filename': BASE_DIR + '/static/log/error.log',
+            'maxBytes': 1024 * 1024 * 5,  # 5 MB
+            'backupCount': 5,
+            'formatter': 'error_format',
+        },
+        'console': {
+            'level': 'ERROR',
+            'class': 'logging.StreamHandler',
+            'formatter': 'error_format'
+        },
+    },
+    'loggers': {
+        'django': {
+            'handlers': ['default', 'console'],
+            # 'handlers': ['mail_admins','default','console'],
+            'level': 'ERROR',
+            'propagate': False
+        },
+    }
+}

+ 82 - 5
Controller/DetectController.py

@@ -30,6 +30,7 @@ from Object.ResponseObject import ResponseObject
 from Object.UidTokenObject import UidTokenObject
 from Object.UidTokenObject import UidTokenObject
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 
 
+
 # http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
 # http://test.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
 
 
 
 
@@ -46,7 +47,7 @@ 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):
+    def validation11(self, request_dict):
         response = ResponseObject()
         response = ResponseObject()
         uidToken = request_dict.get('uidToken', None)
         uidToken = request_dict.get('uidToken', None)
         channel = request_dict.get('channel', '1')
         channel = request_dict.get('channel', '1')
@@ -123,6 +124,82 @@ class NotificationView(View):
         else:
         else:
             return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
             return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
 
 
+    def validation(self, request_dict):
+        response = ResponseObject()
+        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
+        redisObj = RedisObject(db=6)
+        # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
+        pkey = '{uid}_ptl'.format(uid=uid)
+        if redisObj.get_data(key=pkey):
+            res_data = {'code': 0, 'msg': 'success,!'}
+            return JsonResponse(status=200, data=res_data)
+        else:
+            # 设置推送间隔60秒一次
+            redisObj.set_data(key=pkey, val=1, expire=60)
+        # uid_set_id = uid_set_qs[0].id
+
+        uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
+            values('token_val', 'app_type', 'appBundleId',
+                   'push_type', 'userID_id', 'userID__NickName',
+                   'lang', 'tz','uid_set__nickname')
+
+        if uid_push_qs.exists():
+            nickname = uid_push_qs[0]['uid_set__nickname']
+            if not nickname:
+                nickname = uid
+            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'})
+            elif is_st == '1':
+                # 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)
+            elif is_st == '3':
+                # 人形检测带动图
+                # Endpoint以杭州为例,其它Region请按实际情况填写。
+                img_url_list = []
+                for i in range(int(is_st)):
+                    obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
+                        format(uid=uid, channel=channel, filename=n_time, st=i)
+                    # 设置此签名URL在60秒内有效。
+                    url = bucket.sign_url('PUT', obj, 7200)
+                    img_url_list.append(url)
+                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
+                return JsonResponse(status=200, data=res_data)
+        else:
+            return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
+
     def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
     def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
         event_type = request_dict.get('event_type', None)
         event_type = request_dict.get('event_type', None)
         n_time = request_dict.get('n_time', None)
         n_time = request_dict.get('n_time', None)
@@ -143,7 +220,7 @@ class NotificationView(View):
         push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
         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}
                      "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
         message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
         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,
         android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
                                 big_text=send_text, title=message_title,
                                 big_text=send_text, title=message_title,
                                 extras=push_data)
                                 extras=push_data)
@@ -206,7 +283,7 @@ class NotificationView(View):
         push_service = FCMNotification(api_key=serverKey)
         push_service = FCMNotification(api_key=serverKey)
         registration_id = token_val
         registration_id = token_val
         message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
         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": "",
         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}
                 "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,
         result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
@@ -227,7 +304,7 @@ class NotificationView(View):
         appBundleId = uaql['appBundleId']
         appBundleId = uaql['appBundleId']
         tz = uaql['tz']
         tz = uaql['tz']
         message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
         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:
         try:
             print('---')
             print('---')
 
 
@@ -382,4 +459,4 @@ class PushNotificationView(View):
             Equipment_Info.objects.bulk_create(qs_list)
             Equipment_Info.objects.bulk_create(qs_list)
             return True
             return True
         else:
         else:
-            return False
+            return False