|
@@ -23,6 +23,7 @@ from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG,
|
|
|
from Model.models import UidPushModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.S3Email import S3Email
|
|
|
+from Object.enums.EventTypeEnum import EventTypeEnumObj
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.VivoPushService.push_admin.APIMessage import PushMessage
|
|
|
from Service.VivoPushService.push_admin.APISender import APISender
|
|
@@ -282,6 +283,48 @@ class PushObject:
|
|
|
LOGGER.info('uid:{},time:{},极光推送异常:{}'.format(nickname, n_time, repr(e)))
|
|
|
return False
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def jpush(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text, channel=1):
|
|
|
+ """
|
|
|
+ android 极光 推送
|
|
|
+ @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 channel: 设备通道
|
|
|
+ @return: bool
|
|
|
+ """
|
|
|
+ try:
|
|
|
+ app_key = JPUSH_CONFIG[app_bundle_id]['Key']
|
|
|
+ master_secret = JPUSH_CONFIG[app_bundle_id]['Secret']
|
|
|
+ # 换成各自的app_key和master_secret
|
|
|
+ _jpush = jpush.JPush(app_key, master_secret)
|
|
|
+ push = _jpush.create_push()
|
|
|
+ push.audience = jpush.registration_id(token_val)
|
|
|
+ if event_type in EventTypeEnumObj.DATA_PUSH_EVENT_TYPE_LIST.value:
|
|
|
+ channel_id = '111934'
|
|
|
+ else:
|
|
|
+ channel_id = '1'
|
|
|
+ push_data = {'alert': msg_text, 'msg': '', 'sound': 'sound.aif', 'zpush': '1', 'uid': nickname,
|
|
|
+ 'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
|
|
|
+ 'channel': channel
|
|
|
+ }
|
|
|
+ android = jpush.android(title=msg_title, big_text=msg_text, alert=msg_text, extras=push_data,
|
|
|
+ priority=1, style=1, alert_type=7, channel_id=channel_id
|
|
|
+ )
|
|
|
+ push.notification = jpush.notification(android=android)
|
|
|
+ push.platform = jpush.all_
|
|
|
+ res = push.send()
|
|
|
+ assert res.status_code == 200
|
|
|
+ LOGGER.info('极光推送响应:{}, 参数:{}, 令牌:{}'.format(res, push_data, token_val))
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info('极光推送异常:{}'.format(repr(e)))
|
|
|
+ return False
|
|
|
+
|
|
|
@staticmethod
|
|
|
def android_xmpush(channel_id, nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
|
|
|
uid='', channel='1', image=''):
|