|
@@ -16,17 +16,21 @@ import jpush as jpush
|
|
|
import requests
|
|
|
from pyfcm import FCMNotification
|
|
|
|
|
|
-from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, APP_BUNDLE_DICT, XMPUSH_CONFIG
|
|
|
+from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, APP_BUNDLE_DICT, \
|
|
|
+ XMPUSH_CONFIG, VIVOPUSH_CONFIG
|
|
|
from AnsjerPush.config import SERVER_TYPE
|
|
|
from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
|
|
|
DeviceChannelUserPermission
|
|
|
from Object.ETkObject import ETkObject
|
|
|
+from Object.RedisObject import RedisObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
from Service.HuaweiPushService.HuaweiPushService import HuaweiPushObject
|
|
|
from Service.PushService import PushObject
|
|
|
+from Service.VivoPushService.push_admin.APIMessage import PushMessage
|
|
|
+from Service.VivoPushService.push_admin.APISender import APISender
|
|
|
|
|
|
LOGGING = logging.getLogger('info')
|
|
|
|
|
@@ -187,8 +191,7 @@ class DevicePushService:
|
|
|
elif push_type == 4: # android xmpush
|
|
|
result['do_xmpush_code'] = cls.do_xmpush(**kwag_args)
|
|
|
elif push_type == 5:
|
|
|
- kwag_args['app_bundle_id'] = kwag_args.pop('appBundleId')
|
|
|
- result['do_vivopush_code'] = PushObject.android_vivopush(**kwag_args)
|
|
|
+ result['do_vivopush_code'] = cls.do_vivopush(**kwag_args)
|
|
|
return result
|
|
|
except Exception as e:
|
|
|
LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -512,3 +515,50 @@ class DevicePushService:
|
|
|
if not channel_permission_qs.exists():
|
|
|
return False
|
|
|
return True
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def do_vivopush(cls, uid, channel, appBundleId, token_val, event_type, n_time,
|
|
|
+ msg_title, msg_text):
|
|
|
+ logger = logging.getLogger('info')
|
|
|
+ try:
|
|
|
+ authToken = 'authToken_' + appBundleId
|
|
|
+ redisObj = RedisObject()
|
|
|
+ # 获取redis里面的authToken
|
|
|
+ redis_authToken = redisObj.get_data(key=authToken)
|
|
|
+ if msg_title == '':
|
|
|
+ msg_title = '周视'
|
|
|
+ if redis_authToken is not False:
|
|
|
+ app_secret = VIVOPUSH_CONFIG[appBundleId]['Secret']
|
|
|
+ sender_send = APISender(app_secret)
|
|
|
+ sender_send.set_token(redis_authToken)
|
|
|
+ else:
|
|
|
+ app_id = VIVOPUSH_CONFIG[appBundleId]['ID']
|
|
|
+ app_key = VIVOPUSH_CONFIG[appBundleId]['Key']
|
|
|
+ app_secret = VIVOPUSH_CONFIG[appBundleId]['Secret']
|
|
|
+ sender = APISender(app_secret)
|
|
|
+ rec = sender.get_token(app_id, app_key)
|
|
|
+ # 存放authToken,有效期3个小时
|
|
|
+ redisObj = RedisObject()
|
|
|
+ redisObj.set_data(key=authToken, val=rec['authToken'], expire=10800)
|
|
|
+ sender_send = APISender(app_secret)
|
|
|
+ sender_send.set_token(rec['authToken'])
|
|
|
+ push_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
|
|
|
+ 'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
|
|
|
+ 'uid': uid, 'channel': channel
|
|
|
+ }
|
|
|
+ # 推送
|
|
|
+ message = PushMessage() \
|
|
|
+ .reg_id(token_val) \
|
|
|
+ .title(msg_title) \
|
|
|
+ .content(msg_text) \
|
|
|
+ .push_mode(1) \
|
|
|
+ .notify_type(1) \
|
|
|
+ .skip_type('1') \
|
|
|
+ .request_id('123456') \
|
|
|
+ .classification(1) \
|
|
|
+ .client_custom_map(**push_data) \
|
|
|
+ .message_dict()
|
|
|
+ rec2 = sender_send.send(message)
|
|
|
+ logger.info('vivo推送结果:{}'.format(rec2))
|
|
|
+ except Exception as e:
|
|
|
+ logger.info('vivo推送异常:{}'.format(e))
|