|
@@ -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):
|
|
|
"""
|