Browse Source

更新华为推送和推送显示内容

locky 2 years ago
parent
commit
21aacf9e52

+ 2 - 0
AnsjerPush/config.py

@@ -131,6 +131,8 @@ APP_BUNDLE_DICT = {
     'com.ansjer.customizedc_a': 'PatrolSecure',
 }
 
+MULTI_CHANNEL_TYPE_LIST = [1, 2, 3, 4, 10001]
+
 # AI识别标签
 AI_IDENTIFICATION_TAGS_DICT = {
     '1': 'Person',

+ 2 - 2
Controller/DetectController.py

@@ -127,7 +127,7 @@ class NotificationView(View):
             params = {'nickname': nickname, 'uid': uid, 'kwag_args': kwag_args, 'is_st': is_st,
                       'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
                       'electricity': '', 'bucket': bucket, 'app_push': '', 'storage_location': 1, 'ai_type': 0,
-                      'dealings_type': 0, 'detection': 0}
+                      'dealings_type': 0, 'detection': 0, 'device_type': 1}
             #  推送以及报警消息存库
             result = DevicePushService.save_msg_push(uid_set_push_list=uid_push_list, **params)
             if result['code_date'] is None:
@@ -212,7 +212,7 @@ class NotificationView(View):
                 res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
                 return JsonResponse(status=200, data=res_data)
         except Exception as e:
-            logger.info('消息推送-异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            logger.info('旧推送接口异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             data = {
                 'errLine': e.__traceback__.tb_lineno,
                 'errMsg': repr(e),

+ 8 - 6
Controller/DetectControllerV2.py

@@ -96,9 +96,11 @@ class NotificationV2View(View):
             redisObj.set_data(key=req_limiting, val=1, expire=60)  # 当缓存不存在限流数据 重新设置一分钟请求一次
             uid_push_qs = DevicePushService.query_uid_push(uid, event_type)  # 查询uid_set与push数据列表
             if not uid_push_qs.exists():
-                logger.info('消息推送-uid_push 数据不存在')
+                logger.info('消息推送-{}uid_push数据不存在'.format(uid))
                 return JsonResponse(status=200, data={'code': 176, 'msg': 'no uid_push data'})
             ai_type = uid_push_qs.first()['uid_set__ai_type']
+            device_type = uid_push_qs.first()['uid_set__device_type']
+            logger.info('ai_type: {}, device_type: {}'.format(ai_type, device_type))
             # 将uid_set以及uid_push 转数组列表
             uid_set_push_list = DevicePushService.cache_uid_push(uid_push_qs)
             nickname = uid_set_push_list[0]['uid_set__nickname']
@@ -126,12 +128,12 @@ class NotificationV2View(View):
             params = {'nickname': nickname, 'uid': uid, 'kwag_args': kwag_args, 'is_st': is_st, 'region': region,
                       'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
                       'electricity': electricity, 'bucket': bucket, 'aws_s3_client': aws_s3_client,
-                      'app_push': cache_app_push, 'storage_location': 2, 'ai_type': ai_type,
+                      'app_push': cache_app_push, 'storage_location': 2, 'ai_type': ai_type, 'device_type': device_type,
                       'dealings_type': int(dealings_type), 'detection': detection}
-            logger.info('已创建s3对象,推送数据为:{}'.format(params))
-            # APP消息推送与获取报警消息数据列表
+            logger.info('推送数据参数:{}'.format(params))
+            # 推送消息,生成推送数据列表
             result = DevicePushService.save_msg_push(uid_set_push_list, **params)
-            # 批量系统消息&报警消息数据存库
+            # 保存推送数据
             DevicePushService.save_sys_msg(is_sys_msg, result['local_date_time'],
                                            result['sys_msg_list'], result['new_device_info_list'])
             params['aws_s3_client'] = aws_s3_client
@@ -140,7 +142,7 @@ class NotificationV2View(View):
             result_dict = DevicePushService.get_push_url(**params)  # 获取S3对象上传链接
             return JsonResponse(status=200, data=result_dict)
         except Exception as e:
-            logger.info('消息推送-异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+            logger.info('V2推送接口异常, errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             data = {
                 'errLine': e.__traceback__.tb_lineno,
                 'errMsg': repr(e),

+ 55 - 48
Service/DevicePushService.py

@@ -19,7 +19,7 @@ import requests
 from pyfcm import FCMNotification
 
 from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE
-from AnsjerPush.config import CONFIG_INFO, CONFIG_CN
+from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST
 from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, XMPUSH_CONFIG, OPPOPUSH_CONFIG
 from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
     DeviceChannelUserPermission, UidSetModel
@@ -60,12 +60,12 @@ class DevicePushService:
             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', 'uid_set__ai_type', 'uid_set__new_detect_interval')
+                       'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
         else:
             uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
                 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', 'uid_set__ai_type', 'uid_set__new_detect_interval')
+                       'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval')
         return uid_push_qs
 
     @staticmethod
@@ -99,10 +99,10 @@ class DevicePushService:
     @classmethod
     def save_msg_push(cls, uid_set_push_list, **params):
         """
-        APP消息推送以及报警消息存库
-        @nickname 设备名称
-        @channel 通道
-        @event_type 事件类型
+        推送消息,返回推送数据列表
+        @param uid_set_push_list: redis对象
+        @param params: 推送参数
+        @return: dict
         """
         new_device_info_list = []
         sys_msg_list = []
@@ -123,10 +123,11 @@ class DevicePushService:
                 # 发送标题
                 msg_title = cls.get_msg_title(nickname=params['nickname'])
                 # 发送内容
-                msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
-                                            tz=tz, event_type=params['event_type'],
-                                            electricity=params['electricity'], dealings_type=params['dealings_type'],
-                                            ai_type=params['ai_type'])
+                msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang, tz=tz,
+                                            event_type=params['event_type'], ai_type=params['ai_type'],
+                                            device_type=params['device_type'], electricity=params['electricity'],
+                                            dealings_type=params['dealings_type']
+                                            )
                 kwag_args['appBundleId'] = appBundleId
                 kwag_args['token_val'] = token_val
                 kwag_args['msg_title'] = msg_title
@@ -142,10 +143,10 @@ class DevicePushService:
                     now_time = int(time.time())
                     if params['is_sys_msg']:
                         sys_msg_text = cls.get_msg_text(channel=params['channel'], n_time=params['n_time'], lang=lang,
-                                                        tz=tz,
+                                                        tz=tz, is_sys=1, device_type=params['device_type'],
                                                         event_type=params['event_type'],
                                                         electricity=params['electricity'],
-                                                        is_sys=1)
+                                                        )
                         sys_msg_list.append(SysMsgModel(userID_id=userID_id, msg=sys_msg_text, addTime=now_time,
                                                         updTime=now_time, uid=params['uid'],
                                                         eventType=params['event_type']))
@@ -322,73 +323,79 @@ class DevicePushService:
         return nickname
 
     @staticmethod
-    def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0,
-                     ai_type=0):
+    def get_msg_text(channel, n_time, lang, tz, event_type, electricity='', is_sys=0, dealings_type=0, ai_type=0,
+                     device_type=0):
         """
         获取消息文本
         """
         n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
-        etype = int(event_type)
+        msg_type = ''
+        event_type = int(event_type)
+        device_type = int(device_type)
         if lang == 'cn':
-            if etype == 704:
+            if event_type == 704:
                 msg_type = '剩余电量 ' + electricity
-            elif etype == 702:
+            elif event_type == 702:
                 msg_type = '摄像头休眠'
-            elif etype == 703:
+            elif event_type == 703:
                 msg_type = '摄像头唤醒'
-            elif etype == 606:
+            elif event_type == 606:
                 msg_type = '有人呼叫,请点击查看'
             elif ai_type > 0:
-                if etype == 1024 and dealings_type == 1:
+                if event_type == 1024 and dealings_type == 1:
                     msg_type = '有人进入'
-                elif etype == 1024 and dealings_type == 2:
+                elif event_type == 1024 and dealings_type == 2:
                     msg_type = '有人离开'
-                elif etype == 512:
+                elif event_type == 512:
                     msg_type = '长时间无人出现'
-                elif etype == 256:
+                elif event_type == 256:
                     msg_type = '有人徘徊'
-                elif etype == 128:
+                elif event_type == 128:
                     msg_type = '区域离开'
-                elif etype == 64:
+                elif event_type == 64:
                     msg_type = '区域闯入'
-                else:
-                    msg_type = ''
-            else:
-                msg_type = ''
             if is_sys:
-                send_text = '{} 通道:{}'.format(msg_type, channel)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} 通道:{}'.format(msg_type, channel)
+                else:
+                    send_text = msg_type
             else:
-                send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} 通道:{} 日期:{}'.format(msg_type, channel, n_date)
+                else:
+                    send_text = '{} 日期:{}'.format(msg_type, channel, n_date)
         else:
-            if etype == 704:
+            if event_type == 704:
                 msg_type = 'Battery remaining ' + electricity
-            elif etype == 702:
+            elif event_type == 702:
                 msg_type = 'Camera sleep'
-            elif etype == 703:
+            elif event_type == 703:
                 msg_type = 'Camera wake'
-            elif etype == 606:
+            elif event_type == 606:
                 msg_type = 'Someone is calling, please click to view'
             elif ai_type > 0:
-                if etype == 1024 and int(dealings_type) == 1:
+                if event_type == 1024 and int(dealings_type) == 1:
                     msg_type = 'Someone entered'
-                elif etype == 1024 and int(dealings_type) == 2:
+                elif event_type == 1024 and int(dealings_type) == 2:
                     msg_type = 'Someone left'
-                elif etype == 512:
+                elif event_type == 512:
                     msg_type = 'No one shows up for a long time'
-                elif etype == 256:
+                elif event_type == 256:
                     msg_type = 'Someone wanders'
-                elif etype == 128:
+                elif event_type == 128:
                     msg_type = 'Area departure'
-                elif etype == 64:
+                elif event_type == 64:
                     msg_type = 'Area break-in'
-                else:
-                    msg_type = ''
-            else:
-                msg_type = ''
             if is_sys:
-                send_text = '{} channel:{}'.format(msg_type, channel)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} channel:{}'.format(msg_type, channel)
+                else:
+                    send_text = msg_type
             else:
-                send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
+                if device_type in MULTI_CHANNEL_TYPE_LIST:
+                    send_text = '{} channel:{} date:{}'.format(msg_type, channel, n_date)
+                else:
+                    send_text = '{} date:{}'.format(msg_type, channel, n_date)
         return send_text
 
     @staticmethod

+ 65 - 14
Service/HuaweiPushService/HuaweiPushService.py

@@ -35,8 +35,28 @@ class HuaweiPushObject:
         @return:
         """
         logger = logging.getLogger('info')
-        logger.info('华为推送参数:{}, {}, {}, {}'.format(token_val, msg_title, msg_text, image_url))
+        logger.info(
+            '华为推送参数: token_val:{}, msg_title:{}, msg_text:{}, image_url:{}, uid:{}, event_type:{}, n_time:{}'.format(
+                token_val, msg_title, msg_text, image_url, uid, event_type, n_time))
 
+        self.send_notify_message(msg_title, msg_text, image_url, uid, nickname, event_type, n_time, token_val, logger)
+        if event_type == '606':
+            self.send_data_message(uid, event_type, n_time, token_val, logger)
+
+    def send_notify_message(self, msg_title, msg_text, image_url, uid, nickname, event_type, n_time, token_val, logger):
+        """
+        发送通知推送
+        @param msg_title:
+        @param msg_text:
+        @param image_url:
+        @param uid:
+        @param nickname:
+        @param event_type:
+        @param n_time:
+        @param token_val:
+        @param logger:
+        @return: None
+        """
         msg_title = '设备昵称: {}'.format(msg_title)
         notification = messaging.Notification(
             title=msg_title,
@@ -45,13 +65,14 @@ class HuaweiPushObject:
         )
 
         # 自定义键值对
-        data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'uid': uid, 'nickname': nickname,
-                'event_type': event_type, 'received_at': n_time, 'event_time': n_time,
-                'action': 'com.ansjer.zccloud_a.AJ_MainView.AJ_Home.AJMainActivity'
+        data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'uid': uid,
+                'nickname': nickname, 'event_type': event_type, 'received_at': n_time, 'event_time': n_time
                 }
         data = json.dumps(data)
         # 推送通知内容配置
-        android_notification = self.android_notification(msg_title, msg_text)
+        intent = 'intent://com.vivo.pushvideo/detail?#Intent;scheme=vpushscheme;launchFlags=0x10000000;S.uid={};S.event_type={};S.event_time={};end'.format(
+            uid, event_type, n_time)
+        android_notification = self.android_notification(msg_title, msg_text, intent)
         # 安卓配置
         android = messaging.AndroidConfig(
             data=data,
@@ -70,20 +91,49 @@ class HuaweiPushObject:
         )
 
         try:
-            # Case 1: Local CA sample code
-            # response = messaging.send_message(message, verify_peer='../Push-CA-Root.pem')
-            # Case 2: No verification of HTTPS's certificate
-            # response = messaging.send_message(message)
-            # Case 3: use certifi Library
             import certifi
             response = messaging.send_message(message, verify_peer=certifi.where())
-            logger.info('华为推送响应: {}'.format(json.dumps(vars(response))))
+            logger.info('华为通知推送响应: {}'.format(json.dumps(vars(response))))
+            assert (response.code == '80000000')
+        except Exception as e:
+            logger.info('华为通知推送异常: {}'.format(repr(e)))
+
+    @staticmethod
+    def send_data_message(uid, event_type, n_time, token_val, logger):
+        """
+        发送透传推送
+        @param uid:
+        @param event_type:
+        @param n_time:
+        @param token_val:
+        @param logger:
+        @return: None
+        """
+        data = {'uid': uid, 'event_type': event_type, 'event_time': n_time}
+        data = json.dumps(data)
+        android = messaging.AndroidConfig(
+            collapse_key=-1,
+            urgency=messaging.AndroidConfig.HIGH_PRIORITY,
+            ttl='10000s',
+            bi_tag='the_sample_bi_tag_for_receipt_service'
+        )
+
+        message = messaging.Message(
+            data=data,
+            android=android,
+            token=[token_val]
+        )
+
+        try:
+            import certifi
+            response = messaging.send_message(message, verify_peer=certifi.where())
+            logger.info('华为透传推送响应: {}'.format(json.dumps(vars(response))))
             assert (response.code == '80000000')
         except Exception as e:
-            logger.info('华为推送异常: {}'.format(repr(e)))
+            logger.info('华为透传推送异常: {}'.format(repr(e)))
 
     @staticmethod
-    def android_notification(msg_title, msg_text):
+    def android_notification(msg_title, msg_text, intent):
         return messaging.AndroidNotification(
             icon='/raw/ic_launcher2',
             color='#AACCDD',
@@ -91,7 +141,8 @@ class HuaweiPushObject:
             default_sound=True,
             click_action=messaging.AndroidClickAction(
                 action_type=1,
-                intent='intent://com.huawei.codelabpush/deeplink?#Intent;scheme=pushscheme;launchFlags=0x4000000;i.age=180;S.name=abc;end'),
+                intent=intent
+            ),
             body_loc_key='M.String.body',
             body_loc_args=('boy', 'dog'),
             title_loc_key='M.String.title',