|
@@ -102,7 +102,6 @@ class DevicePushService:
|
|
|
detect_interval = new_detect_interval if new_detect_interval > 0 else detect_interval
|
|
|
detect_interval = 60 if detect_interval < 60 else detect_interval
|
|
|
redis_obj.set_data(key=name, val=1, expire=detect_interval - 5)
|
|
|
- LOGGING.info('消息推送-缓存设置APP推送间隔:{}s'.format(detect_interval))
|
|
|
|
|
|
@classmethod
|
|
|
def save_msg_push(cls, uid_set_push_list, **params):
|
|
@@ -247,7 +246,8 @@ class DevicePushService:
|
|
|
# 判断是否进行APP消息推送,如app_push不为空,则不进行推送
|
|
|
if not param['app_push']:
|
|
|
LOGGING.info('APP准备推送:{}, {}'.format(param['uid'], param))
|
|
|
- # 推送显示图片
|
|
|
+
|
|
|
+ # is_st为1或3,且推送类型为apns,gcm,华为,异步推送图片
|
|
|
if (param['is_st'] == 1 or param['is_st'] == 3) and \
|
|
|
(push_type == 0 or push_type == 1 or push_type == 3):
|
|
|
if param['is_st'] == 1:
|
|
@@ -255,17 +255,32 @@ class DevicePushService:
|
|
|
else:
|
|
|
key = '{}/{}/{}_0.jpeg'.format(param['uid'], param['channel'], param['n_time'])
|
|
|
push_thread = threading.Thread(target=cls.async_send_picture_push, args=(
|
|
|
- push_type, param['aws_s3_client'], param['bucket'], key, param['uid'], param['appBundleId'],
|
|
|
- param['token_val'], param['event_type'], param['n_time'],
|
|
|
+ push_type, param['aws_s3_client'], param['bucket'], key,
|
|
|
+ param['uid'], param['appBundleId'], param['token_val'], param['event_type'], param['n_time'],
|
|
|
param['kwag_args']['msg_title'], param['kwag_args']['msg_text'], param['channel']))
|
|
|
push_thread.start()
|
|
|
+ # 不推图
|
|
|
else:
|
|
|
if push_type == 0: # ios apns
|
|
|
- result['do_apns_code'] = cls.do_apns(**kwargs)
|
|
|
+ result['do_apns_code'] = PushObject.ios_apns_push(param['uid'], param['appBundleId'],
|
|
|
+ param['token_val'], param['n_time'],
|
|
|
+ param['event_type'],
|
|
|
+ param['kwag_args']['msg_title'],
|
|
|
+ param['kwag_args']['msg_text'],
|
|
|
+ param['uid'], param['channel'])
|
|
|
elif push_type == 1: # android gcm
|
|
|
- result['do_fcm_code'] = cls.do_fcm(**kwargs)
|
|
|
+ result['do_fcm_code'] = PushObject.android_fcm_push(param['uid'], param['appBundleId'],
|
|
|
+ param['token_val'], param['n_time'],
|
|
|
+ param['event_type'],
|
|
|
+ param['kwag_args']['msg_title'],
|
|
|
+ param['kwag_args']['msg_text'],
|
|
|
+ param['uid'], param['channel'])
|
|
|
elif push_type == 2: # android jpush
|
|
|
- result['do_jpush_code'] = cls.do_jpush(**kwargs)
|
|
|
+ result['do_jpush_code'] = PushObject.android_jpush(param['uid'], param['appBundleId'],
|
|
|
+ param['token_val'], param['n_time'],
|
|
|
+ param['event_type'],
|
|
|
+ param['kwag_args']['msg_title'],
|
|
|
+ param['kwag_args']['msg_text'])
|
|
|
elif push_type == 3:
|
|
|
huawei_push_object = HuaweiPushObject()
|
|
|
huawei_push_object.send_push_notify_message(**kwargs)
|
|
@@ -464,93 +479,6 @@ class DevicePushService:
|
|
|
send_text = '{}'.format(msg_type)
|
|
|
return send_text
|
|
|
|
|
|
- @staticmethod
|
|
|
- def do_jpush(uid, channel, appBundleId, token_val, event_type, n_time,
|
|
|
- msg_title, msg_text):
|
|
|
- """
|
|
|
- android 国内极光APP消息提醒推送
|
|
|
- """
|
|
|
- app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
|
- master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
|
- _jpush = jpush.JPush(app_key, master_secret)
|
|
|
- push = _jpush.create_push()
|
|
|
- push.audience = jpush.registration_id(token_val)
|
|
|
- push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- android = jpush.android(alert=msg_text, priority=1, style=1, alert_type=7,
|
|
|
- big_text=msg_text, title=msg_title,
|
|
|
- extras=push_data)
|
|
|
- push.notification = jpush.notification(android=android)
|
|
|
- push.platform = jpush.all_
|
|
|
- res = push.send()
|
|
|
- LOGGING.info('{}极光推送响应:{}'.format(uid, res))
|
|
|
- print(res)
|
|
|
- return res.status_code
|
|
|
-
|
|
|
- @staticmethod
|
|
|
- def do_fcm(uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
- """
|
|
|
- android 谷歌APP消息提醒推送
|
|
|
- """
|
|
|
- try:
|
|
|
- serverKey = FCM_CONFIG[appBundleId]
|
|
|
- except Exception as e:
|
|
|
- LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return 'serverKey abnormal'
|
|
|
- push_service = FCMNotification(api_key=serverKey)
|
|
|
- data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "sound.aif", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- result = push_service.notify_single_device(registration_id=token_val, message_title=msg_title,
|
|
|
- message_body=msg_text, data_message=data,
|
|
|
- extra_kwargs={
|
|
|
- 'default_vibrate_timings': True,
|
|
|
- 'default_sound': True,
|
|
|
- 'default_light_settings': True
|
|
|
- })
|
|
|
- return result
|
|
|
-
|
|
|
- @staticmethod
|
|
|
- def do_apns(uid, channel, appBundleId, token_val, event_type, n_time, msg_title,
|
|
|
- msg_text):
|
|
|
- """
|
|
|
- ios 消息提醒推送
|
|
|
- """
|
|
|
- LOGGING.info("进来do_apns函数了")
|
|
|
- LOGGING.info(token_val)
|
|
|
- LOGGING.info(APNS_MODE)
|
|
|
- LOGGING.info(os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
|
- try:
|
|
|
- cli = apns2.APNSClient(
|
|
|
- mode=APNS_MODE, client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
|
-
|
|
|
- push_data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
|
- "received_at": n_time, "sound": "", "uid": uid, "zpush": "1", "channel": channel}
|
|
|
- alert = apns2.PayloadAlert(body=msg_text, title=msg_title)
|
|
|
- payload = apns2.Payload(alert=alert, custom=push_data, sound="default")
|
|
|
-
|
|
|
- # return uid, channel, appBundleId, str(token_val), event_type, n_time, msg_title,msg_text
|
|
|
- n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
- res = cli.push(n=n, device_token=token_val, topic=appBundleId)
|
|
|
- print(res.status_code)
|
|
|
- LOGGING.info("apns_推送状态:")
|
|
|
- LOGGING.info(res.status_code)
|
|
|
-
|
|
|
- if res.status_code == 200:
|
|
|
- return res.status_code
|
|
|
- else:
|
|
|
- print('apns push fail')
|
|
|
- print(res.reason)
|
|
|
- LOGGING.info('apns push fail')
|
|
|
- LOGGING.info(res.reason)
|
|
|
- return res.status_code
|
|
|
- except (ValueError, ArithmeticError):
|
|
|
- return 'The program has a numeric format exception, one of the arithmetic exceptions'
|
|
|
- except Exception as e:
|
|
|
- print(repr(e))
|
|
|
- print('do_apns函数错误行号', e.__traceback__.tb_lineno)
|
|
|
- LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
- return repr(e)
|
|
|
-
|
|
|
@staticmethod
|
|
|
def do_xmpush(channel_id, uid, channel, appBundleId, token_val, event_type, n_time,
|
|
|
msg_title, msg_text):
|