linhaohong 1 рік тому
батько
коміт
4c77bc9f3f

+ 1 - 1
Controller/ComboCron/ComboCronPushController.py

@@ -227,7 +227,7 @@ class ComboCronPushView(View):
                 PushObject.ios_apns_push(**kwargs)
             # android gcm
             elif push_type == 1:
-                PushObject.android_fcm_push(**kwargs)
+                PushObject.android_fcm_push_v1(**kwargs)
             # android 极光推送
             elif push_type == 2:
                 PushObject.android_jpush(**kwargs)

+ 1 - 1
Controller/PowerWarningController.py

@@ -90,7 +90,7 @@ class PowerWarningView(View):
                     if push_type == 0:  # ios apns
                         PushObject.ios_apns_push(**kwargs)
                     elif push_type == 1:  # android gcm
-                        PushObject.android_fcm_push(**kwargs)
+                        PushObject.android_fcm_push_v1(**kwargs)
                     elif push_type == 2:  # android jpush
                         kwargs.pop('uid')
                         PushObject.android_jpush(**kwargs)

+ 1 - 1
Controller/gatewayController.py

@@ -448,7 +448,7 @@ class GatewayView(View):
         if push_type == 0:  # ios apns
             PushObject.ios_apns_push(**kwargs)
         elif push_type == 1:  # android gcm
-            PushObject.android_fcm_push(**kwargs)
+            PushObject.android_fcm_push_v1(**kwargs)
         elif push_type == 2:  # android 极光推送
             PushObject.android_jpush(**kwargs)
         elif push_type == 3:

+ 1 - 1
Object/SageMakerAiObject.py

@@ -251,7 +251,7 @@ class SageMakerAiObject:
             if push_type == 0:  # ios apns
                 PushObject.ios_apns_push(**kwargs)
             elif push_type == 1:  # android gcm
-                PushObject.android_fcm_push(**kwargs)
+                PushObject.android_fcm_push_v1(**kwargs)
             elif push_type == 2:  # android jpush
                 kwargs.pop('uid')
                 PushObject.android_jpush(**kwargs)

+ 1 - 1
Service/CustomizedPushService.py

@@ -173,7 +173,7 @@ class CustomizedPushObject:
                 if icon_link is None:
                     icon_link = ''
                 push_kwargs['image'] = icon_link
-                return PushObject.android_fcm_push(**push_kwargs)
+                return PushObject.android_fcm_push_v1(**push_kwargs)
             # 极光
             elif push_type == 2:
                 return PushObject.android_jpush(**push_kwargs)

+ 2 - 2
Service/DevicePushService.py

@@ -398,7 +398,7 @@ class DevicePushService:
                     if push_type == 0:  # ios apns
                         push_result = PushObject.ios_apns_push(**kwargs)
                     elif push_type == 1:  # android gcm
-                        push_result = PushObject.android_fcm_push(**kwargs)
+                        push_result = PushObject.android_fcm_push_v1(**kwargs)
                     elif push_type == 2:  # android jpush
                         kwargs.pop('uid')
                         push_result = PushObject.android_jpush(**kwargs)
@@ -686,7 +686,7 @@ class DevicePushService:
                 push_result = PushObject.ios_apns_push(
                     uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
             elif push_type == 1:
-                push_result = PushObject.android_fcm_push(
+                push_result = PushObject.android_fcm_push_v1(
                     uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, uid, channel, image_url)
             elif push_type == 3:
                 huawei_push_object = HuaweiPushObject()

+ 45 - 0
Service/PushService.py

@@ -12,8 +12,10 @@ import os
 import time
 
 import apns2
+import firebase_admin
 import jpush
 import requests
+from firebase_admin import messaging, credentials
 from pyfcm import FCMNotification
 
 from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
@@ -181,6 +183,49 @@ class PushObject:
             LOGGER.info('fcm推送异常:{}'.format(repr(e)))
             return False
 
+    @staticmethod
+    def android_fcm_push_v1(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
+                            uid='', channel='1', image=''):
+        """
+        android fcm 推送
+        @param nickname: 设备昵称
+        @param app_bundle_id: app包id
+        @param token_val: 推送token
+        @param n_time: 当前时间
+        @param event_type: 事件类型
+        @param msg_title: 推送标题
+        @param msg_text: 推送内容
+        @param uid: uid
+        @param channel: 通道
+        @param image: 推送图片链接
+        @return: bool
+        """
+        try:
+            # See documentation on defining a message payload.
+            cred = credentials.Certificate(
+                BASE_DIR + '/static/fcm/adcloud-fdf9b-firebase-adminsdk-dcvn1-d53e047cc8.json')
+            firebase_admin.initialize_app(cred)
+            push_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'image': image,
+                         'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
+                         'uid': uid, 'channel': channel
+                         }
+            if event_type in [606, 607]:
+                push_data['priority'] = 'high'
+                push_data['content_available'] = True
+                push_data['direct_boot_ok'] = True
+            message = messaging.Message(
+                data=push_data,
+                token=token_val,
+            )
+            # Send a message to the device corresponding to the provided
+            # registration token.
+            result = messaging.send(message)
+            LOGGER.info('fcm推送结果:{}'.format(result))
+            return True
+        except Exception as e:
+            LOGGER.info('fcm推送异常:{}'.format(repr(e)))
+            return False
+
     @staticmethod
     def android_jpush(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text, channel=1):
         """