Prechádzať zdrojové kódy

删除推送不用接口

locky 3 rokov pred
rodič
commit
9c213b7bfd

+ 1 - 10
Ansjer/urls.py

@@ -21,7 +21,7 @@ from Controller import FeedBack, EquipmentOTA, EquipmentInfo, AdminManage, AppIn
     VerifyCodeController, FileController, UIDController, LogController, SalesController, \
     OrderTaskController, HistoryUIDController, UIDManageUserController, SerialNumberController, CompanyController, \
     RegionController, VPGController, LanguageController, TestController, DeviceConfirmRegion, S3GetStsController, \
-    DetectControllerV2, ShadowController, TestDetectController, PcInfo, PctestController, DeviceDebug, PaymentCycle, \
+    DetectControllerV2, PcInfo, PctestController, DeviceDebug, PaymentCycle, \
     DeviceLogController, CouponController, AiController
 from Controller.Cron import CronTaskController
 from Controller.MessagePush import EquipmentMessagePush
@@ -160,16 +160,9 @@ urlpatterns = [
     url(r'^v3/account/loginByFingerprint$', UserController.v3LoginByFingerprintView.as_view()),
     url(r'^v3/account/setFingerprint$', UserController.v3SetFingerprintView.as_view()),
 
-    url(r'^detect/detect_group_push$', DetectController.NotificationView.detect_group_push),
-    url(r'^detect/add$', DetectController.PushNotificationView.as_view()),
     # 推送项目接口
     url(r'^detect/(?P<operation>.*)$', DetectController.DetectControllerView.as_view()),
-    url(r'^notify/push$', DetectController.NotificationView.as_view()),
     url(r'^detectV2/(?P<operation>.*)$', DetectControllerV2.DetectControllerViewV2.as_view()),
-    url(r'^notifyV2/push$', DetectControllerV2.NotificationView.as_view()),
-    url(r'^deviceShadow/update$', ShadowController.update_device_shadow),
-    url(r'^deviceShadow/generateUTK$', ShadowController.generate_utk),
-    url(r'^test/notify/push$', TestDetectController.NotificationView.as_view()),
 
     # 新增
     url(r'^cloudVod/(?P<operation>.*)$', CloudVod.CloudVodView.as_view()),
@@ -200,8 +193,6 @@ urlpatterns = [
 
     url(r'^equipment/flowUpdate', EquipmentManager.update_uid_set),
 
-    url(r'^deviceShadow/update', EquipmentManager.update_device_shadow),
-
     url(r'^log/getUploadUrl', EquipmentStatus.getUploadLogUrl),
     url(r'^app/getIdData', AppInfo.AppIdDataView.as_view()),
     url(r'^wechat/authsign', UserController.wxAuthSignView.as_view()),

+ 0 - 736
Controller/DetectController.py

@@ -338,739 +338,3 @@ class DetectControllerView(View):
                 return response.json(173)
         else:
             return response.json(0)
-
-
-'''
-http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
-http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
-'''
-
-
-# 移动侦测接口
-class NotificationView(View):
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.GET)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.POST)
-
-    def validation(self, request_dict):
-
-        uidToken = request_dict.get('uidToken', None)
-        etk = request_dict.get('etk', 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)
-        # print("aaa")
-        # return JsonResponse(0,safe=False)
-        if not all([channel, n_time]):
-            return JsonResponse(status=200, data={
-                'code': 444,
-                'msg': 'param is wrong'})
-        if etk:
-            eto = ETkObject(etk)
-            uid = eto.uid
-            if len(uid) != 20:
-                return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
-        else:
-            utko = UidTokenObject(uidToken)
-            uid = utko.UID
-
-        pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
-        # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
-        ykey = '{uid}_redis_qs'.format(uid=uid)
-        # dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
-        is_sys_msg = self.is_sys_msg(int(event_type))
-        if is_sys_msg is True:
-            dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
-        else:
-            dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
-
-        # 判断redisObj.get_data(key=pkey):不为空
-        redisObj = RedisObject(db=6)
-        have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
-        have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
-        have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
-
-        # 一分钟外,推送开启状态
-        detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
-        # 暂时注销
-        if have_pkey:
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'msg': 'Push once every 10 seconds'}
-            else:
-                res_data = {'code': 0, 'msg': 'Push it once a minute'}
-
-            return JsonResponse(status=200, data=res_data)
-
-        # 数据库读取数据
-        if have_ykey:
-            redis_list = eval(redisObj.get_data(key=ykey))
-            print(have_ykey)
-        else:
-            # 从数据库查询出来
-            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                values('token_val', 'app_type', 'appBundleId', 'm_code',
-                       'push_type', 'userID_id', 'userID__NickName',
-                       'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
-                       'uid_set__channel')
-            print(uid_push_qs)
-            # 新建一个list接收数据
-            redis_list = []
-            # 把数据库数据追加进redis_list
-            for qs in uid_push_qs:
-                redis_list.append(qs)
-            # 修改redis数据,并设置过期时间为10分钟
-            redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-            if not redis_list:
-                res_data = {'code': 404, 'msg': 'error !'}
-                return JsonResponse(status=200, data=res_data)
-
-            # 此时应该更新一下redis里面的dkey的有效时间
-            # detect_interval = redis_list[0]['uid_set__detect_interval']
-            # tmp_channel = redis_list[0]['uid_set__channel']
-            # self.do_update_detect_interval(uid, tmp_channel, redisObj, detect_interval)
-
-        if not redis_list:
-            print("没有redi_list")
-            res_data = {'code': 0, 'msg': 'no redi_list success!'}
-            return JsonResponse(status=200, data=res_data)
-
-        # is_sys_msg = self.is_sys_msg(int(event_type))
-        nickname = redis_list[0]['uid_set__nickname']
-        detect_interval = redis_list[0]['uid_set__detect_interval']
-        detect_group = redis_list[0]['uid_set__detect_group']
-        now_time = int(time.time())
-        if not nickname:
-            nickname = uid
-
-        if detect_group is not None:
-            if have_dkey:
-                detect_med_type = 1  # 1为存库不推送
-            else:
-                detect_med_type = 2  # 为2的话,既推送,又存库
-                # detect_group=0允许全部推送的时候
-                if detect_group == '0' or detect_group == '':
-                    redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                else:
-                    detect_group_list = detect_group.split(',')
-                    if event_type in detect_group_list:
-                        if detect_interval < 60:
-                            detect_interval = 60
-                        redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                # 改为1秒
-                # 如果不是正式
-                if SERVER_TYPE != "Ansjer.formal_settings":
-                    redisObj.set_data(key=pkey, val=1, expire=10)
-                else:
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-
-            # 打印have_ykey
-        # return JsonResponse(status=200, data={'pkey': 0, 'have_ykey': have_ykey, 'have_pkey': have_pkey, 'have_ykey': have_dkey})
-
-        # 旧模式并且没有pkey,重新创建一个
-        if not detect_group and not have_pkey:
-            # 设置推送时间为60秒一次
-            # 如果不是正式
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                redisObj.set_data(key=pkey, val=1, expire=10)
-            else:
-                redisObj.set_data(key=pkey, val=1, expire=60)
-        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-        kwag_args = {
-            'uid': uid,
-            'channel': channel,
-            'event_type': event_type,
-            'n_time': n_time,
-            # 'appBundleId': appBundleId,
-            # 'token_val': token_val,
-            # 'msg_title': msg_title,
-            # 'msg_text': msg_text
-        }
-        eq_list = []
-        sys_msg_list = []
-        userID_ids = []
-        do_apns_code = ''
-        do_fcm_code = ''
-        do_jpush_code = ''
-        for up in redis_list:
-            push_type = up['push_type']
-            appBundleId = up['appBundleId']
-            token_val = up['token_val']
-            lang = up['lang']
-            tz = up['tz']
-            if tz is None or tz == '':
-                tz = 0
-            # 发送标题
-            msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-            # 发送内容
-            msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                         event_type=event_type)
-            kwag_args['appBundleId'] = appBundleId
-            kwag_args['token_val'] = token_val
-            kwag_args['msg_title'] = msg_title
-            kwag_args['msg_text'] = msg_text
-            push_server_status = 0
-            # 推送
-            if detect_med_type == 2 or detect_med_type == 0:
-                if push_type == 0:  # ios apns
-                    print('do_apns')
-                    # self.do_apns(**kwag_args)
-                    do_apns_code = self.do_apns(**kwag_args)
-                    if isinstance(do_apns_code, int):
-                        push_server_status = do_apns_code
-                    else:
-                        push_server_status = 400
-                elif push_type == 1:  # android gcm
-                    print('do_fcm')
-                    do_fcm_code = self.do_fcm(**kwag_args)
-                    push_server_status = 200
-                elif push_type == 2:  # android jpush
-                    print('do_jpush')
-                    do_jpush_code = self.do_jpush(**kwag_args)
-                    push_server_status = do_jpush_code
-                    # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
-            if detect_med_type == 1:
-                do_apns_code = '只存库不推送'
-                do_fcm_code = '只存库不推送'
-                do_jpush_code = '只存库不推送'
-            # 以下是存库
-            userID_id = up["userID_id"]
-            int_is_st = int(is_st)
-            if userID_id not in userID_ids:
-                eq_list.append(Equipment_Info(
-                    userID_id=userID_id,
-                    eventTime=n_time,
-                    eventType=event_type,
-                    devUid=uid,
-                    devNickName=nickname,
-                    Channel=channel,
-                    alarm='Motion \tChannel:{channel}'.format(channel=channel),
-                    is_st=int_is_st,
-                    receiveTime=n_time,
-                    addTime=now_time,
-                    storage_location=1
-                ))
-                if is_sys_msg:
-                    sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type, is_sys=1)
-                    sys_msg_list.append(SysMsgModel(
-                        userID_id=userID_id,
-                        msg=sys_msg_text,
-                        addTime=now_time,
-                        updTime=now_time,
-                        uid=uid,
-                        eventType=event_type))
-                userID_ids.append(userID_id)
-        if is_sys_msg:
-            SysMsgModel.objects.bulk_create(sys_msg_list)
-        Equipment_Info.objects.bulk_create(eq_list)
-        if is_st == '0' or is_st == '2':
-            print("is_st=0or2")
-            for up in redis_list:
-                if up['push_type'] == 0:  # ios apns
-                    up['do_apns_code'] = do_apns_code
-                elif up['push_type'] == 1:  # android gcm
-                    up['do_fcm_code'] = do_fcm_code
-                elif up['push_type'] == 2:  # android jpush
-                    up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
-
-        elif is_st == '1':
-            print("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)
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-                # 不是正式服务器
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
-            return JsonResponse(status=200, data=res_data)
-
-        elif is_st == '3':
-            print("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)
-
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-
-            # 不是正式服务器
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
-            return JsonResponse(status=200, data=res_data)
-
-    def get_msg_title(self, appBundleId, nickname):
-        package_title_config = {
-            'com.ansjer.customizedd_a': 'DVS',
-            'com.ansjer.zccloud_a': 'ZosiSmart',
-            'com.ansjer.zccloud_ab': '周视',
-            'com.ansjer.adcloud_a': 'ADCloud',
-            'com.ansjer.adcloud_ab': 'ADCloud',
-            'com.ansjer.accloud_a': 'ACCloud',
-            'com.ansjer.loocamccloud_a': 'Loocam',
-            'com.ansjer.loocamdcloud_a': 'Anlapus',
-            'com.ansjer.customizedb_a': 'COCOONHD',
-            'com.ansjer.customizeda_a': 'Guardian365',
-            'com.ansjer.customizedc_a': 'PatrolSecure',
-        }
-        if appBundleId in package_title_config.keys():
-            return package_title_config[appBundleId] + '(' + nickname + ')'
-        else:
-            return nickname
-
-    def is_sys_msg(self, event_type):
-        event_type_list = [702, 703, 704]
-        if event_type in event_type_list:
-            return True
-        return False
-
-    def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
-        etype = int(event_type)
-        if lang == 'cn':
-            if etype == 704:
-                msg_type = '电量过低'
-            elif etype == 702:
-                msg_type = '摄像头休眠'
-            elif etype == 703:
-                msg_type = '摄像头唤醒'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-                # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-        else:
-            if etype == 704:
-                msg_type = 'Low battery'
-            elif etype == 702:
-                msg_type = 'Camera sleep'
-            elif etype == 703:
-                msg_type = 'Camera wake'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
-        return send_text
-
-    def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
-                 msg_title, msg_text):
-        app_key = JPUSH_CONFIG[appBundleId]['Key']
-        master_secret = JPUSH_CONFIG[appBundleId]['Secret']
-        # 此处换成各自的app_key和master_secre
-        _jpush = jpush.JPush(app_key, master_secret)
-        push = _jpush.create_push()
-        # if you set the logging level to "DEBUG",it will show the debug logging.
-        # _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": event_type, "msg": "",
-                     "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
-        android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
-                                big_text=msg_text, title=msg_title,
-                                extras=push_data)
-        push.notification = jpush.notification(android=android)
-        push.platform = jpush.all_
-        res = push.send()
-        print(res)
-        return res.status_code
-        # try:
-        #     res = push.send()
-        #     print(res)
-        # except Exception as e:
-        #     print("jpush fail")
-        #     print("Exception")
-        #     print(repr(e))
-        #     return
-        # else:
-        #     print("jpush success")
-        #     return
-
-    def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
-        try:
-            serverKey = FCM_CONFIG[appBundleId]
-        except Exception as e:
-            return 'serverKey abnormal'
-        push_service = FCMNotification(api_key=serverKey)
-        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}
-        result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
-                                                   message_body=msg_text, data_message=data,
-                                                   extra_kwargs={
-                                                       'default_vibrate_timings': True,
-                                                       'default_sound': True,
-                                                       'default_light_settings': True
-                                                   })
-        print('fcm push ing')
-        print(result)
-        return result
-
-    def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
-                msg_text):
-        try:
-            cli = apns2.APNSClient(mode=APNS_MODE,
-                                   client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
-
-            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}
-            alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
-            payload = apns2.Payload(alert=alert, custom=push_data)
-
-            # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
-            n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
-            res = cli.push(n=n, device_token=token_val, topic=appBundleId)
-            print(res.status_code)
-
-            #     200, 推送成功。
-            #   400, 请求有问题。
-            #   403, 证书或Token有问题。
-            #   405, 请求方式不正确, 只支持POST请求
-            #   410, 设备的Token与证书不一致
-            if res.status_code == 200:
-                return res.status_code
-            else:
-                print('apns push fail')
-                print(res.reason)
-                return res.status_code
-        except (ValueError, ArithmeticError):
-            return 'The program has a numeric format exception, one of the arithmetic exceptions'
-        except Exception as e:
-            print(repr(e))
-            return repr(e)
-
-    def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
-        if channel == 0:
-            channel = 17
-        else:
-            channel += 1
-        for i in range(1, channel):
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-    # 新增 把代码封装以便后面分侦测类型
-    def detect_group_push(self, request_dict, uid, response, channel, n_time, event_type, is_st):
-        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:
-            # 设置推送间隔60秒一次
-            redisObj.set_data(key=pkey, val=1, expire=60)
-        uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-            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_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
-        #
-        qs_list = []
-        nowTime = int(time.time())
-        # 设备昵称
-        userID_ids = []
-        for dv in uaqs:
-            userID_id = dv["userID_id"]
-            if userID_id not in userID_ids:
-                if dv['uid_set__nickname']:
-                    uid_nickname = dv['uid_set__nickname']
-                else:
-                    uid_nickname = uid
-                add_data = {
-                    'userID_id': dv["userID_id"],
-                    'eventTime': n_time,
-                    'eventType': event_type,
-                    'devUid': uid,
-                    'devNickName': uid_nickname,
-                    'Channel': channel,
-                    'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
-                    'is_st': int(is_st),
-                    'receiveTime': n_time,
-                    'addTime': nowTime
-                }
-                qs_list.append(Equipment_Info(**add_data))
-                userID_ids.append(userID_id)
-        if qs_list:
-            print(1)
-            Equipment_Info.objects.bulk_create(qs_list)
-            return True
-        else:
-            return False
-
-
-# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
-# 移动侦测接口
-class PushNotificationView(View):
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        # operation = kwargs.get('operation')
-        return self.validation(request.GET)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        # operation = kwargs.get('operation')
-        return self.validation(request.POST)
-
-    def validation(self, request_dict):
-        etk = request_dict.get('etk', 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)
-        eto = ETkObject(etk)
-        uid = eto.uid
-        if len(uid) == 20:
-            redisObj = RedisObject(db=6)
-            # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
-            pkey = '{uid}_ptl'.format(uid=uid)
-            ykey = '{uid}_redis_qs'.format(uid=uid)
-            if redisObj.get_data(key=pkey):
-                res_data = {'code': 0, 'msg': 'success,!33333333333'}
-                return JsonResponse(status=200, data=res_data)
-            else:
-                redisObj.set_data(key=pkey, val=1, expire=60)
-            ##############
-            redis_data = redisObj.get_data(key=ykey)
-            if redis_data:
-                redis_list = eval(redis_data)
-            else:
-                # 设置推送时间为60秒一次
-                redisObj.set_data(key=pkey, val=1, expire=60)
-                print("从数据库查到数据")
-                # 从数据库查询出来
-                uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                    values('token_val', 'app_type', 'appBundleId',
-                           'push_type', 'userID_id', 'lang', 'm_code',
-                           'tz', 'uid_set__nickname')
-                # 新建一个list接收数据
-                redis_list = []
-                # 把数据库数据追加进redis_list
-                for qs in uid_push_qs:
-                    redis_list.append(qs)
-                # 修改redis数据,并设置过期时间为10分钟
-            if redis_list:
-                redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
-                if is_st == '0' or is_st == '2':
-                    return JsonResponse(status=200, data={'code': 0, 'msg': 'success44444444444444444'})
-                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':
-                    # 人形检测带动图
-                    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'})
-        else:
-            return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
-
-    def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
-        now_time = int(time.time())
-        # 设备昵称
-        userID_ids = []
-        sys_msg_list = []
-        is_sys_msg = self.is_sys_msg(int(event_type))
-        is_st = int(is_st)
-        eq_list = []
-        nickname = uaqs[0]['uid_set__nickname']
-        if not nickname:
-            nickname = uid
-        for ua in uaqs:
-            lang = ua['lang']
-            tz = ua['tz']
-            userID_id = ua["userID_id"]
-            if userID_id not in userID_ids:
-                eq_list.append(Equipment_Info(
-                    userID_id=userID_id,
-                    eventTime=n_time,
-                    eventType=event_type,
-                    devUid=uid,
-                    devNickName=nickname,
-                    Channel=channel,
-                    alarm='Motion \tChannel:{channel}'.format(channel=channel),
-                    is_st=is_st,
-                    receiveTime=n_time,
-                    addTime=now_time,
-                    storage_location=1
-                ))
-                if is_sys_msg:
-                    sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type, is_sys=1)
-                    sys_msg_list.append(SysMsgModel(
-                        userID_id=userID_id,
-                        msg=sys_msg_text,
-                        addTime=now_time,
-                        updTime=now_time,
-                        uid=uid,
-                        eventType=event_type))
-        if eq_list:
-            print('eq_list')
-            Equipment_Info.objects.bulk_create(eq_list)
-        if is_sys_msg:
-            print('sys_msg')
-            SysMsgModel.objects.bulk_create(sys_msg_list)
-        return True
-
-    def is_sys_msg(self, event_type):
-        event_type_list = [702, 703, 704]
-        if event_type in event_type_list:
-            return True
-        return False
-
-    def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
-        etype = int(event_type)
-        if lang == 'cn':
-            if etype == 704:
-                msg_type = '电量过低'
-            elif etype == 702:
-                msg_type = '摄像头休眠'
-            elif etype == 703:
-                msg_type = '摄像头唤醒'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-        else:
-            if etype == 704:
-                msg_type = 'Low battery'
-            elif etype == 702:
-                msg_type = 'Camera sleep'
-            elif etype == 703:
-                msg_type = 'Camera wake'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
-        return send_text

+ 0 - 553
Controller/DetectControllerV2.py

@@ -471,559 +471,6 @@ class DetectControllerViewV2(View):
             return response.json(0)
 
 
-# 设备调用接口
-# 移动侦测接口
-class NotificationView(View):
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.GET)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.POST)
-
-    def validation(self, request_dict):
-
-        uidToken = request_dict.get('uidToken', None)
-        etk = request_dict.get('etk', 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)
-        company_secrete = request_dict.get('company_secrete', None)
-        region = request_dict.get('region', None)
-        if not region:
-            return JsonResponse(status=200, data={'code': 404, 'msg': 'region is not exist'})
-        region = int(region)
-        # print("aaa")
-        # return JsonResponse(0,safe=False)
-        if not all([channel, n_time]):
-            return JsonResponse(status=200, data={
-                'code': 444,
-                'msg': 'param is wrong'})
-        if etk:
-            eto = ETkObject(etk)
-            uid = eto.uid
-            if len(uid) != 20 and len(uid) != 14:
-                return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
-        else:
-            utko = UidTokenObject(uidToken)
-            uid = utko.UID
-
-        pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
-        # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
-        ykey = '{uid}_redis_qs'.format(uid=uid)
-        # dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
-        is_sys_msg = self.is_sys_msg(int(event_type))
-        if is_sys_msg is True:
-            dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
-        else:
-            dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
-
-        # 判断redisObj.get_data(key=pkey):不为空
-        redisObj = RedisObject(db=6)
-        have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
-        have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
-        have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
-
-        # 一分钟外,推送开启状态
-        detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
-        # 暂时注销
-        if have_pkey:
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'msg': 'Push once every 10 seconds'}
-            else:
-                res_data = {'code': 0, 'msg': 'Push it once a minute'}
-
-            return JsonResponse(status=200, data=res_data)
-
-        # 数据库读取数据
-        if have_ykey:
-            redis_list = eval(redisObj.get_data(key=ykey))
-            print(have_ykey)
-            if not redis_list:
-                # 从数据库查询出来
-                uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                    values('token_val', 'app_type', 'appBundleId', 'm_code',
-                           'push_type', 'userID_id', 'userID__NickName',
-                           'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval',
-                           'uid_set__detect_group',
-                           'uid_set__channel')
-                print(uid_push_qs)
-                # 新建一个list接收数据
-                redis_list = []
-                # 把数据库数据追加进redis_list
-                for qs in uid_push_qs:
-                    redis_list.append(qs)
-                # 修改redis数据,并设置过期时间为10分钟
-                redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-                if not redis_list:
-                    res_data = {'code': 404, 'msg': 'error !'}
-                    return JsonResponse(status=200, data=res_data)
-        else:
-            # 从数据库查询出来
-            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                values('token_val', 'app_type', 'appBundleId', 'm_code',
-                       'push_type', 'userID_id', 'userID__NickName',
-                       'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
-                       'uid_set__channel')
-            print(uid_push_qs)
-            # 新建一个list接收数据
-            redis_list = []
-            # 把数据库数据追加进redis_list
-            for qs in uid_push_qs:
-                redis_list.append(qs)
-            # 修改redis数据,并设置过期时间为10分钟
-            redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-            if not redis_list:
-                res_data = {'code': 404, 'msg': 'error !'}
-                return JsonResponse(status=200, data=res_data)
-
-            # 此时应该更新一下redis里面的dkey的有效时间
-            # detect_interval = redis_list[0]['uid_set__detect_interval']
-            # tmp_channel = redis_list[0]['uid_set__channel']
-            # self.do_update_detect_interval(uid, tmp_channel, redisObj, detect_interval)
-
-        if not redis_list:
-            print("没有redi_list")
-            res_data = {'code': 0, 'msg': 'no redi_list success!'}
-            return JsonResponse(status=200, data=res_data)
-
-        # is_sys_msg = self.is_sys_msg(int(event_type))
-        nickname = redis_list[0]['uid_set__nickname']
-        detect_interval = redis_list[0]['uid_set__detect_interval']
-        detect_group = redis_list[0]['uid_set__detect_group']
-        now_time = int(time.time())
-        if not nickname:
-            nickname = uid
-
-        if detect_group is not None:
-            if have_dkey:
-                detect_med_type = 1  # 1为存库不推送
-            else:
-                detect_med_type = 2  # 为2的话,既推送,又存库
-                # detect_group=0允许全部推送的时候
-                if detect_group == '0' or detect_group == '':
-                    redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                else:
-                    detect_group_list = detect_group.split(',')
-                    if event_type in detect_group_list:
-                        if detect_interval < 60:
-                            detect_interval = 60
-                        redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                # 改为1秒
-                # 如果不是正式
-                if SERVER_TYPE != "Ansjer.formal_settings":
-                    redisObj.set_data(key=pkey, val=1, expire=10)
-                else:
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-
-            # 打印have_ykey
-        # return JsonResponse(status=200, data={'pkey': 0, 'have_ykey': have_ykey, 'have_pkey': have_pkey, 'have_ykey': have_dkey})
-
-        # 旧模式并且没有pkey,重新创建一个
-        if not detect_group and not have_pkey:
-            # 设置推送时间为60秒一次
-            # 如果不是正式
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                redisObj.set_data(key=pkey, val=1, expire=10)
-            else:
-                redisObj.set_data(key=pkey, val=1, expire=60)
-        # auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-        # bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-        aws_s3_guonei = boto3.client(
-            's3',
-            aws_access_key_id=AWS_ACCESS_KEY_ID[0],
-            aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
-            config=botocore.client.Config(signature_version='s3v4'),
-            region_name='cn-northwest-1'
-        )
-        aws_s3_guowai = boto3.client(
-            's3',
-            aws_access_key_id=AWS_ACCESS_KEY_ID[1],
-            aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
-            config=botocore.client.Config(signature_version='s3v4'),
-            region_name='us-east-1'
-        )
-        kwag_args = {
-            'uid': uid,
-            'channel': channel,
-            'event_type': event_type,
-            'n_time': n_time,
-            # 'appBundleId': appBundleId,
-            # 'token_val': token_val,
-            # 'msg_title': msg_title,
-            # 'msg_text': msg_text
-        }
-        eq_list = []
-        sys_msg_list = []
-        userID_ids = []
-        do_apns_code = ''
-        do_fcm_code = ''
-        do_jpush_code = ''
-        for up in redis_list:
-            push_type = up['push_type']
-            appBundleId = up['appBundleId']
-            token_val = up['token_val']
-            lang = up['lang']
-            tz = up['tz']
-            if tz is None or tz == '':
-                tz = 0
-            # 发送标题
-            msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-            # 发送内容
-            msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                         event_type=event_type)
-            kwag_args['appBundleId'] = appBundleId
-            kwag_args['token_val'] = token_val
-            kwag_args['msg_title'] = msg_title
-            kwag_args['msg_text'] = msg_text
-            push_server_status = 0
-            # 推送
-            if detect_med_type == 2 or detect_med_type == 0:
-                if push_type == 0:  # ios apns
-                    print('do_apns')
-                    # self.do_apns(**kwag_args)
-                    do_apns_code = self.do_apns(**kwag_args)
-                    if isinstance(do_apns_code, int):
-                        push_server_status = do_apns_code
-                    else:
-                        push_server_status = 400
-                elif push_type == 1:  # android gcm
-                    print('do_fcm')
-                    do_fcm_code = self.do_fcm(**kwag_args)
-                    push_server_status = 200
-                elif push_type == 2:  # android jpush
-                    print('do_jpush')
-                    do_jpush_code = self.do_jpush(**kwag_args)
-                    push_server_status = do_jpush_code
-                    # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
-            if detect_med_type == 1:
-                do_apns_code = '只存库不推送'
-                do_fcm_code = '只存库不推送'
-                do_jpush_code = '只存库不推送'
-            # 以下是存库
-            userID_id = up["userID_id"]
-            int_is_st = int(is_st)
-            if userID_id not in userID_ids:
-                eq_list.append(Equipment_Info(
-                    userID_id=userID_id,
-                    eventTime=n_time,
-                    eventType=event_type,
-                    devUid=uid,
-                    devNickName=nickname,
-                    Channel=channel,
-                    alarm='Motion \tChannel:{channel}'.format(channel=channel),
-                    is_st=int_is_st,
-                    receiveTime=n_time,
-                    addTime=now_time,
-                    storage_location=2
-                ))
-                if is_sys_msg:
-                    sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type, is_sys=1)
-                    sys_msg_list.append(SysMsgModel(
-                        userID_id=userID_id,
-                        msg=sys_msg_text,
-                        addTime=now_time,
-                        updTime=now_time,
-                        uid=uid,
-                        eventType=event_type))
-                userID_ids.append(userID_id)
-        if is_sys_msg:
-            SysMsgModel.objects.bulk_create(sys_msg_list)
-        Equipment_Info.objects.bulk_create(eq_list)
-        if is_st == '0' or is_st == '2':
-            print("is_st=0or2")
-            for up in redis_list:
-                if up['push_type'] == 0:  # ios apns
-                    up['do_apns_code'] = do_apns_code
-                elif up['push_type'] == 1:  # android gcm
-                    up['do_fcm_code'] = do_fcm_code
-                elif up['push_type'] == 2:  # android jpush
-                    up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
-
-        elif is_st == '1':
-            print("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)
-            thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
-            if region == 2:  # 2:国内
-                response_url = aws_s3_guonei.generate_presigned_url(
-                    ClientMethod='put_object',
-                    Params={
-                        'Bucket': 'push',
-                        'Key': thumbspng
-                    },
-                    ExpiresIn=3600
-                )
-            else:  # 1:国外
-                response_url = aws_s3_guowai.generate_presigned_url(
-                    ClientMethod='put_object',
-                    Params={
-                        'Bucket': 'foreignpush',
-                        'Key': thumbspng
-                    },
-                    ExpiresIn=3600
-                )
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-                # 不是正式服务器
-            # response_url = response_url[:4] + response_url[5:]
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                # res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
-                res_data = {'code': 0, 'img_push': response_url, 'msg': 'success', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                # res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
-                res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
-            return JsonResponse(status=200, data=res_data)
-
-        elif is_st == '3':
-            print("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)
-
-                thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
-                    format(uid=uid, channel=channel, filename=n_time, st=i)
-                if region == 2:  # 2:国内
-                    response_url = aws_s3_guonei.generate_presigned_url(
-                        ClientMethod='put_object',
-                        Params={
-                            'Bucket': 'push',
-                            'Key': thumbspng
-                        },
-                        ExpiresIn=3600
-                    )
-                else:  # 1:国外
-                    response_url = aws_s3_guowai.generate_presigned_url(
-                        ClientMethod='put_object',
-                        Params={
-                            'Bucket': 'foreignpush',
-                            'Key': thumbspng
-                        },
-                        ExpiresIn=3600
-                    )
-                # response_url = response_url[:4] + response_url[5:]
-                img_url_list.append(response_url)
-
-                # img_url_list.append(url)
-
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-
-            # 不是正式服务器
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
-            return JsonResponse(status=200, data=res_data)
-
-    def get_msg_title(self, appBundleId, nickname):
-        package_title_config = {
-            'com.ansjer.customizedd_a': 'DVS',
-            'com.ansjer.zccloud_a': 'ZosiSmart',
-            'com.ansjer.zccloud_ab': '周视',
-            'com.ansjer.adcloud_a': 'ADCloud',
-            'com.ansjer.adcloud_ab': 'ADCloud',
-            'com.ansjer.accloud_a': 'ACCloud',
-            'com.ansjer.loocamccloud_a': 'Loocam',
-            'com.ansjer.loocamdcloud_a': 'Anlapus',
-            'com.ansjer.customizedb_a': 'COCOONHD',
-            'com.ansjer.customizeda_a': 'Guardian365',
-            'com.ansjer.customizedc_a': 'PatrolSecure',
-        }
-        if appBundleId in package_title_config.keys():
-            return package_title_config[appBundleId] + '(' + nickname + ')'
-        else:
-            return nickname
-
-    def is_sys_msg(self, event_type):
-        event_type_list = [702, 703, 704]
-        if event_type in event_type_list:
-            return True
-        return False
-
-    def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
-        etype = int(event_type)
-        if lang == 'cn':
-            if etype == 704:
-                msg_type = '电量过低'
-            elif etype == 702:
-                msg_type = '摄像头休眠'
-            elif etype == 703:
-                msg_type = '摄像头唤醒'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-                # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-        else:
-            if etype == 704:
-                msg_type = 'Low battery'
-            elif etype == 702:
-                msg_type = 'Camera sleep'
-            elif etype == 703:
-                msg_type = 'Camera wake'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
-        return send_text
-
-    def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
-                 msg_title, msg_text):
-        app_key = JPUSH_CONFIG[appBundleId]['Key']
-        master_secret = JPUSH_CONFIG[appBundleId]['Secret']
-        # 此处换成各自的app_key和master_secre
-        _jpush = jpush.JPush(app_key, master_secret)
-        push = _jpush.create_push()
-        # if you set the logging level to "DEBUG",it will show the debug logging.
-        # _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": event_type, "msg": "",
-                     "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
-        android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
-                                big_text=msg_text, title=msg_title,
-                                extras=push_data)
-        push.notification = jpush.notification(android=android)
-        push.platform = jpush.all_
-        res = push.send()
-        print(res)
-        return res.status_code
-        # try:
-        #     res = push.send()
-        #     print(res)
-        # except Exception as e:
-        #     print("jpush fail")
-        #     print("Exception")
-        #     print(repr(e))
-        #     return
-        # else:
-        #     print("jpush success")
-        #     return
-
-    def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
-        try:
-            serverKey = FCM_CONFIG[appBundleId]
-        except Exception as e:
-            return 'serverKey abnormal'
-        push_service = FCMNotification(api_key=serverKey)
-        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}
-        result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
-                                                   message_body=msg_text, data_message=data,
-                                                   extra_kwargs={
-                                                       'default_vibrate_timings': True,
-                                                       'default_sound': True,
-                                                       'default_light_settings': True
-                                                   })
-        print('fcm push ing')
-        print(result)
-        return result
-
-    def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
-                msg_text):
-        try:
-            cli = apns2.APNSClient(mode=APNS_MODE,
-                                   client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
-
-            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}
-            alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
-            payload = apns2.Payload(alert=alert, custom=push_data)
-
-            # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
-            n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
-            res = cli.push(n=n, device_token=token_val, topic=appBundleId)
-            print(res.status_code)
-
-            #     200, 推送成功。
-            #   400, 请求有问题。
-            #   403, 证书或Token有问题。
-            #   405, 请求方式不正确, 只支持POST请求
-            #   410, 设备的Token与证书不一致
-            if res.status_code == 200:
-                return res.status_code
-            else:
-                print('apns push fail')
-                print(res.reason)
-                return res.status_code
-        except (ValueError, ArithmeticError):
-            return 'The program has a numeric format exception, one of the arithmetic exceptions'
-        except Exception as e:
-            print(repr(e))
-            return repr(e)
-
-    def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
-        if channel == 0:
-            channel = 17
-        else:
-            channel += 1
-        for i in range(1, channel):
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-
 # 这个接口没有调用过,不敢动
 # http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
 # 移动侦测接口

+ 0 - 106
Controller/EquipmentManager.py

@@ -1219,109 +1219,3 @@ def update_uid_set(request):
             return response.json(14)
     else:
         return response.json(tko.code)
-
-
-# 测试环境
-# test.shadow.dvema.com
-# 生产环境
-# shadow.dvema.com
-# http://test.dvema.com/deviceShadow/update?etk=JVJWbFpFU0VOV1FsbEVTMFpOU2xKWFFURXhNVUU9Xz0=&ucode=1234&version=1324&p2p_region=CN
-# 设备影子更新
-def update_device_shadow(request):
-    request.encoding = 'utf-8'
-    response = ResponseObject()
-    if request.method == 'POST':
-        request_dict = request.POST
-    elif request.method == 'GET':
-        request_dict = request.GET
-    else:
-        return response.json(444)
-    etk = request_dict.get('etk', None)
-    eto = ETkObject(etk)
-    uid = eto.uid
-    if uid:
-        # 重置按钮
-        is_reset = request_dict.get('is_reset', None)
-        # 传1则重置设备信息
-        if is_reset == '1':
-
-            UidSetModel.objects.filter(uid=uid).delete()
-            # 重置设备,判断设备为已删除
-            nowTime = int(time.time())
-            uid_bucket = UID_Bucket.objects.filter(uid=uid, endTime__gte=nowTime).values('id', 'has_unused').order_by('addTime')
-            if not uid_bucket.exists():
-                di_qs = Device_Info.objects.filter(UID=uid)
-                di_qs.update(isExist=2)
-
-            # 清除redis缓存
-            # data = di_qs.values()
-            # redisObj = RedisObject(db=8)
-            # for di in data:
-            #     key = 'uid_qs_' + di['userID_id']
-            #     redis_value = redisObj.get_data(key=key)
-            #     if redis_value is not False:
-            #         redisObj.del_data(key)
-
-        ucode = request_dict.get('ucode', None)
-        version = request_dict.get('version', None)
-        p2p_region = request_dict.get('p2p_region', None)
-        tz = request_dict.get('tz', None)
-        video_code = request_dict.get('video_code', None)
-        ip = CommonService.get_ip_address(request)
-        channel = request_dict.get('channel', None)
-        cloud_vod = request_dict.get('cloud_vod', None)
-        push_status = request_dict.get('push_status', None)
-        pwd = request_dict.get('pwd', None)
-        resetTime = request_dict.get('resetTime', None)
-        is_ptz = request_dict.get('is_ptz', None)
-        is_alexa = request_dict.get('is_alexa', None)
-        is_ai = request_dict.get('is_ai', None)
-
-        us_qs = UidSetModel.objects.filter(uid=uid)
-        # 更新
-        nowTime = int(time.time())
-
-        print('-------')
-        print(resetTime)
-        print('-------')
-        qs_dict = {
-            'updTime': nowTime,
-            'ip': ip
-        }
-        if channel:
-            qs_dict['channel'] = channel
-        if p2p_region:
-            qs_dict['p2p_region'] = p2p_region
-        if ucode:
-            qs_dict['ucode'] = ucode
-        if version:
-            qs_dict['version'] = version
-        if tz:
-            qs_dict['tz'] = tz
-        if video_code:
-            qs_dict['video_code'] = video_code
-        if cloud_vod:
-            qs_dict['cloud_vod'] = cloud_vod
-        if push_status:
-            qs_dict['detect_status'] = push_status
-        if pwd:
-            qs_dict['pwd'] = pwd
-        if is_ptz:
-            qs_dict['is_ptz'] = is_ptz
-        if is_alexa:
-            qs_dict['is_alexa'] = is_alexa
-        if is_ai:
-            qs_dict['is_ai'] = is_ai
-        if us_qs.exists():
-            us_qs.update(**qs_dict)
-            # 如果推送状态开启,返回推送url
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
-        # 新增
-        else:
-            qs_dict['uid'] = uid
-            qs_dict['addTime'] = nowTime
-            UidSetModel.objects.create(**qs_dict)
-            # 如果推送状态开启,返回推送url
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
-    else:
-        return JsonResponse(status=200, data={'code': 403, 'msg': 'error etk'})

+ 0 - 165
Controller/ShadowController.py

@@ -1,165 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-"""
-@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
-@AUTHOR: ASJRD018
-@NAME: AnsjerPush
-@software: PyCharm
-@DATE: 2020/2/14 13:54
-@Version: python3.6
-@MODIFY DECORD:ansjer dev
-@file: ShadowController.py
-@Contact: chanjunkai@163.com
-"""
-# 测试环境
-# test.shadow.dvema.com
-# 生产环境
-# shadow.dvema.com
-# 设备影子更新
-from Object.LogUtil import LogUtil
-from Object.ResponseObject import ResponseObject
-from Object.ETkObject import ETkObject
-import time
-from Model.models import Device_Info, UidSetModel, UID_Preview, VoicePromptModel, UID_Bucket
-from Service.CommonService import CommonService
-from django.http import JsonResponse
-from Object.UidTokenObject import UidTokenObject
-
-def generate_utk(request):
-    request.encoding = 'utf-8'
-    response = ResponseObject()
-    if request.method == 'GET':
-        request_dict = request.GET
-    elif request.method == 'POST':
-        request_dict = request.POST
-    else:
-        return response.json(444,'wrong method')
-    username = request_dict.get('username',None)
-    password = request_dict.get('password',None)
-    uid = request_dict.get('uid',None)
-    if username and password:
-        if username == 'debug_user' and password == 'debug_password':
-            # utko = UidTokenObject()
-            # # right
-            # utko.generate(data={'uid': uid})
-            etkObj = ETkObject(etk='')
-            etk = etkObj.encrypt(uid)
-            return response.json(0, {'etk': etk})
-        else:
-            return response.json(404)
-    else:
-        return response.json(444,'username password')
-
-
-# 设备影子更新
-def update_device_shadow(request):
-    request.encoding = 'utf-8'
-    response = ResponseObject()
-    if request.method == 'POST':
-        request_dict = request.POST
-    elif request.method == 'GET':
-        request_dict = request.GET
-    else:
-        return response.json(444)
-    etk = request_dict.get('etk', None)
-    eto = ETkObject(etk)
-    uid = eto.uid
-    if uid:
-        # 重置按钮
-        is_reset = request_dict.get('is_reset', None)
-        # 传1则重置设备信息
-        if is_reset == '1':
-            UidSetModel.objects.filter(uid=uid).delete()
-            # 重置设备,判断设备为已删除
-            nowTime = int(time.time())
-            uid_bucket = UID_Bucket.objects.filter(uid=uid, endTime__gte=nowTime).values('id', 'has_unused').order_by('addTime')
-            if not uid_bucket.exists():
-                di_qs = Device_Info.objects.filter(UID=uid)
-                di_qs.update(isExist=2)
-            # 删除预览图
-            uid_pre_qs = UID_Preview.objects.filter(uid=uid)
-            if uid_pre_qs.exists():
-                uid_pre_qs.delete()
-
-            # 删除语音提示
-            voice_qs = VoicePromptModel.objects.filter(uid=uid)
-            if voice_qs.exists():
-                voice_qs.delete()
-
-        # return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
-        ucode = request_dict.get('ucode', None)
-        version = request_dict.get('version', None)
-        p2p_region = request_dict.get('p2p_region', None)
-        tz = request_dict.get('tz', None)
-        video_code = request_dict.get('video_code', None)
-        ip = CommonService.get_ip_address(request)
-        channel = request_dict.get('channel', None)
-        cloud_vod = request_dict.get('cloud_vod', None)
-        push_status = request_dict.get('push_status', None)
-        pwd = request_dict.get('pwd', None)
-        resetTime = request_dict.get('resetTime', None)
-        is_alexa = request_dict.get('is_alexa', None)
-        is_human = request_dict.get('is_human', None)
-        is_custom_voice = request_dict.get('is_custom', None)
-        double_wifi = request_dict.get('double_wifi', None)
-        mobile_4g = request_dict.get('mobile4G', None)
-        is_ptz = request_dict.get('is_ptz', None)
-        us_qs = UidSetModel.objects.filter(uid=uid)
-        is_ai = request_dict.get('is_ai', None)
-        # 更新
-        nowTime = int(time.time())
-
-        print('-------')
-        print(resetTime)
-        print('-------')
-        qs_dict = {
-            'updTime': nowTime,
-            'ip': ip
-        }
-        if channel:
-            qs_dict['channel'] = channel
-        if p2p_region:
-            qs_dict['p2p_region'] = p2p_region
-        if ucode:
-            qs_dict['ucode'] = ucode
-        if version:
-            qs_dict['version'] = version
-        if tz:
-            qs_dict['tz'] = tz
-        if video_code:
-            qs_dict['video_code'] = video_code
-        if cloud_vod:
-            qs_dict['cloud_vod'] = cloud_vod
-        if push_status:
-            qs_dict['detect_status'] = push_status
-        if pwd:
-            qs_dict['pwd'] = pwd
-        if is_human:
-            qs_dict['is_human'] = is_human
-        if is_custom_voice:
-            qs_dict['is_custom_voice'] = is_custom_voice
-        if double_wifi:
-            qs_dict['double_wifi'] = double_wifi
-        if mobile_4g:
-            qs_dict['mobile_4g'] = int(mobile_4g)
-        if is_ptz:
-            qs_dict['is_ptz'] = is_ptz
-        if is_ai:
-            qs_dict['is_ai'] = is_ai
-        if us_qs.exists():
-            if is_alexa and us_qs[0].is_alexa == 0:
-                qs_dict['is_alexa'] = is_alexa
-            us_qs.update(**qs_dict)
-            # 如果推送状态开启,返回推送url
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
-        # 新增
-        else:
-            if is_alexa:
-                qs_dict['is_alexa'] = is_alexa
-            qs_dict['uid'] = uid
-            qs_dict['addTime'] = nowTime
-            UidSetModel.objects.create(**qs_dict)
-            # 如果推送状态开启,返回推送url
-            return JsonResponse(status=200, data={'code': 0, 'msg': 'success', 'data': {}})
-    else:
-        return JsonResponse(status=200, data={'code': 403, 'msg': 'error etk'})

+ 0 - 708
Controller/TestDetectController.py

@@ -1,708 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-"""
-@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
-@AUTHOR: ASJRD018
-@NAME: AnsjerFormal
-@software: PyCharm
-@DATE: 2019/1/14 15:57
-@Version: python3.6
-@MODIFY DECORD:ansjer dev
-@file: DetectController.py
-@Contact: chanjunkai@163.com
-"""
-import os
-import time
-
-import apns2
-import jpush as jpush
-import oss2
-from django.http import JsonResponse, HttpResponse
-from django.views.generic.base import View
-from pyfcm import FCMNotification
-from Ansjer.config import SERVER_TYPE, JPUSH_CODE, APNS_CODE, APP_TYPE
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, FCM_CONFIG, \
-    APNS_CONFIG, BASE_DIR, APNS_MODE
-from Model.models import Equipment_Info, UidPushModel, SysMsgModel
-from Object.ETkObject import ETkObject
-from Object.RedisObject import RedisObject
-from Object.UidTokenObject import UidTokenObject
-from Service.CommonService import CommonService
-import json
-
-'''
-http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
-http://push.dvema.com/deviceShadow/generateUTK?username=debug_user&password=debug_password&uid=VVDHCVBYDKFMJRWA111A
-'''
-
-
-# 移动侦测接口
-class NotificationView(View):
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.GET, 0)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        return self.validation(request.POST, 1)
-
-    def validation(self, request_dict, request_type):
-        uidToken = request_dict.get('uidToken', None)
-        etk = request_dict.get('etk', 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)
-        # print("aaa")
-        # return JsonResponse(0,safe=False)
-        if not all([channel, n_time]):
-            return JsonResponse(status=200, data={
-                'code': 444,
-                'msg': 'param is wrong'})
-        if etk:
-            eto = ETkObject(etk)
-            uid = eto.uid
-            if len(uid) != 20:
-                return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
-        else:
-            utko = UidTokenObject(uidToken)
-            uid = utko.UID
-        pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
-        # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
-        ykey = '{uid}_redis_qs'.format(uid=uid)
-        dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
-        # 判断redisObj.get_data(key=pkey):不为空
-        redisObj = RedisObject(db=6)
-        have_ykey = redisObj.get_data(key=ykey)  # uid_set 数据库缓存
-        have_pkey = redisObj.get_data(key=pkey)  # 一分钟限制key
-        have_dkey = redisObj.get_data(key=dkey)  # 推送类型限制
-
-        # 一分钟外,推送开启状态
-        detect_med_type = 0  # 0推送旧机制 1存库不推送,2推送存库
-        # 暂时注销
-        if have_pkey:
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'msg': 'Push once every 10 seconds'}
-            else:
-                res_data = {'code': 0, 'msg': 'Push it once a minute'}
-            return JsonResponse(status=200, data=res_data)
-
-        # 数据库读取数据
-        if have_ykey:
-            redis_list = eval(redisObj.get_data(key=ykey))
-        else:
-            # 从数据库查询出来
-            uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                values('token_val', 'app_type', 'appBundleId', 'm_code',
-                       'push_type', 'userID_id', 'userID__NickName', 'userID__username',
-                       'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
-                       'uid_set__channel')
-            # 新建一个list接收数据
-            redis_list = []
-            # 把数据库数据追加进redis_list
-            for qs in uid_push_qs:
-                redis_list.append(qs)
-            # 修改redis数据,并设置过期时间为10分钟
-            redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-            if not redis_list:
-                res_data = {'code': 404, 'msg': 'error !'}
-                return JsonResponse(status=200, data=res_data)
-
-            # 此时应该更新一下redis里面的dkey的有效时间
-            detect_interval = redis_list[0]['uid_set__detect_interval']
-            channel = redis_list[0]['uid_set__channel']
-            self.do_update_detect_interval(uid, channel, redisObj, detect_interval)
-
-
-        if not redis_list:
-            print("没有redi_list")
-            res_data = {'code': 0, 'msg': 'no redi_list success!'}
-            return JsonResponse(status=200, data=res_data)
-
-        is_sys_msg = self.is_sys_msg(int(event_type))
-        nickname = redis_list[0]['uid_set__nickname']
-        detect_interval = redis_list[0]['uid_set__detect_interval']
-        detect_group = redis_list[0]['uid_set__detect_group']
-        now_time = int(time.time())
-        if not nickname:
-            nickname = uid
-        print('detect_group')
-        print(detect_group)
-        print(detect_interval)
-        if detect_group:
-            if have_dkey:
-                detect_med_type = 1  # 1为存库不推送
-            else:
-                detect_med_type = 2  # 为2的话,既推送,又存库
-                # detect_group=0允许全部推送的时候
-                if detect_group == '0':
-                    redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                else:
-                    detect_group_list = detect_group.split(',')
-                    if event_type in detect_group_list:
-                        if detect_interval < 60:
-                            detect_interval = 60
-                        redisObj.set_data(key=dkey, val=1, expire=detect_interval)
-                # 改为1秒
-                # 如果不是正式
-                if SERVER_TYPE!="Ansjer.formal_settings":
-                    redisObj.set_data(key=pkey, val=1, expire=10)
-                else:
-                    redisObj.set_data(key=pkey, val=1, expire=60)
-
-            # 打印have_ykey
-        # return JsonResponse(status=200, data={'pkey': 0, 'have_ykey': have_ykey, 'have_pkey': have_pkey, 'have_ykey': have_dkey})
-
-        # 旧模式并且没有pkey,重新创建一个
-        if not detect_group and not have_pkey:
-            # 设置推送时间为60秒一次
-            # 如果不是正式
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                redisObj.set_data(key=pkey, val=1, expire=10)
-            else:
-                redisObj.set_data(key=pkey, val=1, expire=60)
-        auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-        bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-        kwag_args = {
-            'uid': uid,
-            'channel': channel,
-            'event_type': event_type,
-            'n_time': n_time,
-            # 'appBundleId': appBundleId,
-            # 'token_val': token_val,
-            # 'msg_title': msg_title,
-            # 'msg_text': msg_text
-        }
-        eq_list = []
-        sys_msg_list = []
-        userID_ids = []
-        do_apns_code = ''
-        do_fcm_code = ''
-        do_jpush_code = ''
-        for up in redis_list:
-            push_type = up['push_type']
-            appBundleId = up['appBundleId']
-            token_val = up['token_val']
-            lang = up['lang']
-            tz = up['tz']
-            # 发送标题
-            msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
-            # 发送内容
-            msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                         event_type=event_type)
-            kwag_args['appBundleId'] = appBundleId
-            kwag_args['token_val'] = token_val
-            kwag_args['msg_title'] = msg_title
-            kwag_args['msg_text'] = msg_text
-            #推送
-            if detect_med_type == 2 or detect_med_type == 0:
-                if push_type == 0:  # ios apns
-                    print('do_apns')
-                    # self.do_apns(**kwag_args)
-                    do_apns_code = self.do_apns(**kwag_args)
-                    up['push_code'] = do_apns_code
-                elif push_type == 1:  # android gcm
-                    print('do_fcm')
-                    do_fcm_code = self.do_fcm(**kwag_args)
-                    up['push_code'] = do_fcm_code
-                elif push_type == 2:  # android jpush
-                    print('do_jpush')
-                    do_jpush_code = self.do_jpush(**kwag_args)
-                    up['push_code'] = do_jpush_code
-                    # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
-
-            if detect_med_type == 1:
-                do_apns_code = '只存库不推送'
-                do_fcm_code = '只存库不推送'
-                do_jpush_code = '只存库不推送'
-                up['push_code'] = -1
-
-            # 以下是存库
-            userID_id = up["userID_id"]
-            int_is_st = int(is_st)
-            if userID_id not in userID_ids:
-                eq_list.append(Equipment_Info(
-                    userID_id=userID_id,
-                    eventTime=n_time,
-                    eventType=event_type,
-                    devUid=uid,
-                    devNickName=nickname,
-                    Channel=channel,
-                    alarm='Motion \tChannel:{channel}'.format(channel=channel),
-                    is_st=int_is_st,
-                    receiveTime=n_time,
-                    addTime=now_time
-                ))
-                if is_sys_msg:
-                    sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type, is_sys=1)
-                    sys_msg_list.append(SysMsgModel(
-                        userID_id=userID_id,
-                        msg=sys_msg_text,
-                        addTime=now_time,
-                        updTime=now_time,
-                        uid=uid,
-                        eventType=event_type))
-                userID_ids.append(userID_id)
-        if is_sys_msg:
-            SysMsgModel.objects.bulk_create(sys_msg_list)
-        Equipment_Info.objects.bulk_create(eq_list)
-
-        if is_st == '0' or is_st == '2':
-            print("is_st=0or2")
-            for up in redis_list:
-                # if up['push_type'] == 0:  # ios apns
-                #     up['do_apns_code'] = do_apns_code
-                # elif up['push_type'] == 1:  # android gcm
-                #     up['do_fcm_code'] = do_fcm_code
-                # elif up['push_type'] == 2:  # android jpush
-
-                try:
-
-                    code = up['push_code']
-                    print("push_code is ")
-                    print(code)
-                    if up['push_type'] == 0:
-                        up['push_res'] = '{code} {desc}'.format(code=code, desc=APNS_CODE[code])
-                        up['push_type'] = '苹果推送'
-                    elif up['push_type'] == 1:
-                        up['push_res'] = code
-                        up['push_type'] = '谷歌推送'
-                    elif up['push_type'] == 2:
-                        up['push_res'] = '{code} {desc}'.format(code=code, desc=JPUSH_CODE[code])
-                        up['push_type'] = '极光推送'
-
-
-                except KeyError as ke:
-                    print(ke)
-                else:
-                    del up['push_code']
-
-                #up['test_or_www'] = SERVER_TYPE
-                if SERVER_TYPE == 'Ansjer.formal_settings':
-                    up['server_type'] = '正式服务器'
-                else:
-                    up['server_type'] = '测试服务器'
-
-                up['app_type'] = APP_TYPE[up['app_type']]
-
-                # del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-
-                if request_type == 0:
-                    data = ""
-                    for up in redis_list:
-                        data += ("<p>" + repr(up) + "</p>")
-                    return HttpResponse(repr(data))
-                else:
-                    return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
-
-        elif is_st == '1':
-            print("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)
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-                # 不是正式服务器
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
-
-            return JsonResponse(status=200, data=res_data)
-
-        elif is_st == '3':
-            print("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)
-
-            for up in redis_list:
-                up['do_apns_code'] = do_apns_code
-                up['do_fcm_code'] = do_fcm_code
-                up['do_jpush_code'] = do_jpush_code
-                up['test_or_www'] = SERVER_TYPE
-                del up['push_type']
-                del up['userID_id']
-                del up['userID__NickName']
-                del up['lang']
-                del up['tz']
-                del up['uid_set__nickname']
-                del up['uid_set__detect_interval']
-                del up['uid_set__detect_group']
-
-            # 不是正式服务器
-            if SERVER_TYPE != "Ansjer.formal_settings":
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
-            else:
-                # 是正式服务器的时候
-                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
-            return JsonResponse(status=200, data=res_data)
-
-
-    def get_msg_title(self, appBundleId, nickname):
-        package_title_config = {
-            'com.ansjer.customizedd_a': 'DVS',
-            'com.ansjer.zccloud_a': 'ZosiSmart',
-            'com.ansjer.zccloud_ab': '周视',
-            'com.ansjer.adcloud_a': 'ADCloud',
-            'com.ansjer.adcloud_ab': 'ADCloud',
-            'com.ansjer.accloud_a': 'ACCloud',
-            'com.ansjer.loocamccloud_a': 'Loocam',
-            'com.ansjer.loocamdcloud_a': 'Anlapus',
-            'com.ansjer.customizedb_a': 'COCOONHD',
-            'com.ansjer.customizeda_a': 'Guardian365',
-            'com.ansjer.customizedc_a': 'PatrolSecure',
-        }
-        if appBundleId in package_title_config.keys():
-            return package_title_config[appBundleId] + '(' + nickname + ')'
-        else:
-            return nickname
-
-    def is_sys_msg(self, event_type):
-        event_type_list = [702, 703, 704]
-        if event_type in event_type_list:
-            return True
-        return False
-
-    def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
-        etype = int(event_type)
-        if lang == 'cn':
-            if etype == 704:
-                msg_type = '电量过低'
-            elif etype == 702:
-                msg_type = '摄像头休眠'
-            elif etype == 703:
-                msg_type = '摄像头唤醒'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-                # send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-        else:
-            if etype == 704:
-                msg_type = 'Low battery'
-            elif etype == 702:
-                msg_type = 'Camera sleep'
-            elif etype == 703:
-                msg_type = 'Camera wake'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
-        return send_text
-
-    def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time,
-                 msg_title, msg_text):
-        app_key = JPUSH_CONFIG[appBundleId]['Key']
-        master_secret = JPUSH_CONFIG[appBundleId]['Secret']
-        # 此处换成各自的app_key和master_secre
-        _jpush = jpush.JPush(app_key, master_secret)
-        push = _jpush.create_push()
-        # if you set the logging level to "DEBUG",it will show the debug logging.
-        # _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": event_type, "msg": "",
-                     "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
-        android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
-                                big_text=msg_text, title=msg_title,
-                                extras=push_data)
-        push.notification = jpush.notification(android=android)
-        push.platform = jpush.all_
-        res = push.send()
-        print(res)
-        return res.status_code
-        # try:
-        #     res = push.send()
-        #     print(res)
-        # except Exception as e:
-        #     print("jpush fail")
-        #     print("Exception")
-        #     print(repr(e))
-        #     return
-        # else:
-        #     print("jpush success")
-        #     return
-
-    def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
-        try:
-            serverKey = FCM_CONFIG[appBundleId]
-        except Exception as e:
-            return 'serverKey abnormal'
-        push_service = FCMNotification(api_key=serverKey)
-        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}
-        result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
-                                                   message_body=msg_text, data_message=data,
-                                                   extra_kwargs={
-                                                       'default_vibrate_timings': True,
-                                                       'default_sound': True,
-                                                       'default_light_settings': True
-                                                   })
-        print('fcm push ing')
-        print(result)
-        return result
-
-    def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
-                msg_text):
-        try:
-            cli = apns2.APNSClient(mode=APNS_MODE,
-                                   client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
-
-            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}
-            alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
-            payload = apns2.Payload(alert=alert, custom=push_data)
-
-            # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
-            n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
-            res = cli.push(n=n, device_token=token_val, topic=appBundleId)
-            print(res.status_code)
-
-            #     200, 推送成功。
-            #   400, 请求有问题。
-            #   403, 证书或Token有问题。
-            #   405, 请求方式不正确, 只支持POST请求
-            #   410, 设备的Token与证书不一致
-            if res.status_code == 200:
-                return res.status_code
-            else:
-                print('apns push fail')
-                print(res.reason)
-                return res.status_code
-        except (ValueError, ArithmeticError):
-            return 'The program has a numeric format exception, one of the arithmetic exceptions'
-        except Exception as e:
-            print(repr(e))
-            return repr(e)
-
-
-    def getJPushReport(self, msg_id, appBundleId):
-        app_key = JPUSH_CONFIG[appBundleId]['Key']
-        master_secret = JPUSH_CONFIG[appBundleId]['Secret']
-        _jpush = jpush.JPush(app_key, master_secret)
-        report = _jpush.create_report()
-        res = report.get_received_detail(msg_id)
-        print("getJPushReport")
-        print(res)
-
-    def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
-        if channel == 0:
-            channel = 17
-        else:
-            channel += 1
-        for i in range(1, channel):
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-            tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
-            if tmpDKey is not False:
-                llt = redisObject.get_ttl(tmpDKey)
-                if llt > detect_interval:
-                    redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
-
-
-
-# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
-# 移动侦测接口
-class PushNotificationView(View):
-
-    def get(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        # operation = kwargs.get('operation')
-        return self.validation(request.GET)
-
-    def post(self, request, *args, **kwargs):
-        request.encoding = 'utf-8'
-        # operation = kwargs.get('operation')
-        return self.validation(request.POST)
-
-    def validation(self, request_dict):
-        etk = request_dict.get('etk', 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)
-        eto = ETkObject(etk)
-        uid = eto.uid
-        if len(uid) == 20:
-            redisObj = RedisObject(db=6)
-            # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
-            pkey = '{uid}_ptl'.format(uid=uid)
-            ykey = '{uid}_redis_qs'.format(uid=uid)
-            if redisObj.get_data(key=pkey):
-                res_data = {'code': 0, 'msg': 'success,!33333333333'}
-                return JsonResponse(status=200, data=res_data)
-            else:
-                redisObj.set_data(key=pkey, val=1, expire=60)
-            ##############
-            redis_data = redisObj.get_data(key=ykey)
-            if redis_data:
-                redis_list = eval(redis_data)
-            else:
-                # 设置推送时间为60秒一次
-                redisObj.set_data(key=pkey, val=1, expire=60)
-                print("从数据库查到数据")
-                # 从数据库查询出来
-                uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
-                    values('token_val', 'app_type', 'appBundleId',
-                           'push_type', 'userID_id', 'lang','m_code',
-                           'tz', 'uid_set__nickname')
-                # 新建一个list接收数据
-                redis_list = []
-                # 把数据库数据追加进redis_list
-                for qs in uid_push_qs:
-                    redis_list.append(qs)
-                # 修改redis数据,并设置过期时间为10分钟
-            if redis_list:
-                redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
-                auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
-                bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
-                self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
-                if is_st == '0' or is_st == '2':
-                    return JsonResponse(status=200, data={'code': 0, 'msg': 'success44444444444444444'})
-                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':
-                    # 人形检测带动图
-                    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'})
-        else:
-            return JsonResponse(status=200, data={'code': 404, 'msg': 'wrong etk'})
-
-    def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st, uid):
-        now_time = int(time.time())
-        # 设备昵称
-        userID_ids = []
-        sys_msg_list = []
-        is_sys_msg = self.is_sys_msg(int(event_type))
-        is_st = int(is_st)
-        eq_list = []
-        nickname = uaqs[0]['uid_set__nickname']
-        if not nickname:
-            nickname = uid
-        for ua in uaqs:
-            lang = ua['lang']
-            tz = ua['tz']
-            userID_id = ua["userID_id"]
-            if userID_id not in userID_ids:
-                eq_list.append(Equipment_Info(
-                    userID_id=userID_id,
-                    eventTime=n_time,
-                    eventType=event_type,
-                    devUid=uid,
-                    devNickName=nickname,
-                    Channel=channel,
-                    alarm='Motion \tChannel:{channel}'.format(channel=channel),
-                    is_st=is_st,
-                    receiveTime=n_time,
-                    addTime=now_time
-                ))
-                if is_sys_msg:
-                    sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
-                                                     event_type=event_type, is_sys=1)
-                    sys_msg_list.append(SysMsgModel(
-                        userID_id=userID_id,
-                        msg=sys_msg_text,
-                        addTime=now_time,
-                        updTime=now_time,
-                        uid=uid,
-                        eventType=event_type))
-        if eq_list:
-            print('eq_list')
-            Equipment_Info.objects.bulk_create(eq_list)
-        if is_sys_msg:
-            print('sys_msg')
-            SysMsgModel.objects.bulk_create(sys_msg_list)
-        return True
-
-    def is_sys_msg(self, event_type):
-        event_type_list = [702, 703, 704]
-        if event_type in event_type_list:
-            return True
-        return False
-
-    def get_msg_text(self, channel, n_time, lang, tz, event_type, is_sys=0):
-        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
-        etype = int(event_type)
-        if lang == 'cn':
-            if etype == 704:
-                msg_type = '电量过低'
-            elif etype == 702:
-                msg_type = '摄像头休眠'
-            elif etype == 703:
-                msg_type = '摄像头唤醒'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} 通道:{channel}'.format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} 通道:{channel} 日期:{date}'.format(msg_type=msg_type, channel=channel, date=n_date)
-        else:
-            if etype == 704:
-                msg_type = 'Low battery'
-            elif etype == 702:
-                msg_type = 'Camera sleep'
-            elif etype == 703:
-                msg_type = 'Camera wake'
-            else:
-                msg_type = ''
-            if is_sys:
-                send_text = '{msg_type} channel:{channel}'. \
-                    format(msg_type=msg_type, channel=channel)
-            else:
-                send_text = '{msg_type} channel:{channel} date:{date}'. \
-                    format(msg_type=msg_type, channel=channel, date=n_date)
-        return send_text