|
@@ -12,8 +12,10 @@ import os
|
|
import time
|
|
import time
|
|
|
|
|
|
import apns2
|
|
import apns2
|
|
|
|
+import firebase_admin
|
|
import jpush
|
|
import jpush
|
|
import requests
|
|
import requests
|
|
|
|
+from firebase_admin import messaging
|
|
from pyfcm import FCMNotification
|
|
from pyfcm import FCMNotification
|
|
|
|
|
|
from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
|
|
from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
|
|
@@ -193,6 +195,52 @@ class PushObject:
|
|
LOGGER.info('uid:{},evnet_type:{},time:{},fcm推送异常:{}'.format(uid, event_type, n_time, repr(e)))
|
|
LOGGER.info('uid:{},evnet_type:{},time:{},fcm推送异常:{}'.format(uid, event_type, n_time, repr(e)))
|
|
return False
|
|
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:
|
|
|
|
+ event_type = str(event_type)
|
|
|
|
+ n_time = str(n_time)
|
|
|
|
+ push_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
|
|
|
|
+ '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(
|
|
|
|
+ notification=messaging.Notification(
|
|
|
|
+ title=msg_title,
|
|
|
|
+ body=msg_text,
|
|
|
|
+ image=image
|
|
|
|
+ ),
|
|
|
|
+ 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
|
|
@staticmethod
|
|
def android_jpush(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text, channel=1):
|
|
def android_jpush(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text, channel=1):
|
|
"""
|
|
"""
|