|
@@ -458,3 +458,70 @@ class AiView(View):
|
|
|
except Exception as e:
|
|
|
print('AI标签存储异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
return False
|
|
|
+
|
|
|
+ def do_jpush(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
+ app_key = JPUSH_CONFIG[appBundleId]['Key']
|
|
|
+ master_secret = JPUSH_CONFIG[appBundleId]['Secret']
|
|
|
+ # 此处换成各自的app_key和master_secre
|
|
|
+ _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()
|
|
|
+ print(res)
|
|
|
+ return res.status_code
|
|
|
+
|
|
|
+ def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
+ try:
|
|
|
+
|
|
|
+ serverKey = FCM_CONFIG[appBundleId]
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ print('fcm push ing')
|
|
|
+ print(result)
|
|
|
+ return result
|
|
|
+ except Exception as e:
|
|
|
+ return 'serverKey abnormal'
|
|
|
+
|
|
|
+ def do_apns(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
+ logger = logging.getLogger('info')
|
|
|
+ logger.info("进来do_apns函数了")
|
|
|
+ logger.info(token_val)
|
|
|
+ logger.info(APNS_MODE)
|
|
|
+ logger.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")
|
|
|
+ n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
+ res = cli.push(n=n, device_token=token_val, topic=appBundleId)
|
|
|
+
|
|
|
+ if res.status_code == 200:
|
|
|
+ return res.status_code
|
|
|
+ else:
|
|
|
+ logger.info('apns push fail')
|
|
|
+ logger.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))
|
|
|
+ logger.info(repr(e))
|
|
|
+ return repr(e)
|