|
@@ -14,7 +14,7 @@
|
|
|
import logging
|
|
|
import os
|
|
|
import time
|
|
|
-
|
|
|
+import json
|
|
|
import apns2
|
|
|
import jpush as jpush
|
|
|
import oss2
|
|
@@ -50,6 +50,9 @@ class NotificationView(View):
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
|
+ operation = kwargs.get('operation')
|
|
|
+ if operation == 'test_apns':
|
|
|
+ return self.test_apns(request.POST)
|
|
|
return self.validation(request.POST)
|
|
|
|
|
|
def validation(self, request_dict):
|
|
@@ -156,6 +159,9 @@ class NotificationView(View):
|
|
|
do_apns_code = ''
|
|
|
do_fcm_code = ''
|
|
|
do_jpush_code = ''
|
|
|
+ logger.info('进入手机推送------')
|
|
|
+ logger.info('uid={}'.format(uid))
|
|
|
+ logger.info(redis_list)
|
|
|
for up in redis_list:
|
|
|
push_type = up['push_type']
|
|
|
appBundleId = up['appBundleId']
|
|
@@ -179,6 +185,8 @@ class NotificationView(View):
|
|
|
if not have_dkey:
|
|
|
if push_type == 0: # ios apns
|
|
|
do_apns_code = self.do_apns(**kwag_args)
|
|
|
+ logger.info('进入do_apns,uid={}'.format(uid))
|
|
|
+ logger.info('do_apns_code===={}'.format(do_apns_code))
|
|
|
elif push_type == 1: # android gcm
|
|
|
do_fcm_code = self.do_fcm(**kwag_args)
|
|
|
elif push_type == 2: # android jpush
|
|
@@ -291,7 +299,26 @@ class NotificationView(View):
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
except Exception as e:
|
|
|
logger.info('移动侦测接口异常: {}'.format(e))
|
|
|
- return JsonResponse(status=500)
|
|
|
+ logger.info('错误文件', e.__traceback__.tb_frame.f_globals['__file__'])
|
|
|
+ logger.info('错误行号', e.__traceback__.tb_lineno)
|
|
|
+ data = {
|
|
|
+ 'errLine': e.__traceback__.tb_lineno,
|
|
|
+ 'errMsg': repr(e),
|
|
|
+ }
|
|
|
+ return JsonResponse(status=200, data=json.dumps(data), safe=False)
|
|
|
+ def test_apns(self,request_dict):
|
|
|
+ kwag_args = {
|
|
|
+ 'uid': request_dict.get('uid', None),
|
|
|
+ 'channel': request_dict.get('channel', None),
|
|
|
+ 'event_type': request_dict.get('event_type', None),
|
|
|
+ 'n_time': request_dict.get('n_time', None),
|
|
|
+ 'appBundleId':request_dict.get('appBundleId', None),
|
|
|
+ 'token_val':request_dict.get('token_val', None),
|
|
|
+ 'msg_title':request_dict.get('msg_title', None),
|
|
|
+ 'msg_text':request_dict.get('msg_text', None),
|
|
|
+ }
|
|
|
+ do_apns_code = self.do_apns(**kwag_args)
|
|
|
+ return JsonResponse(status=500,data={'do_apns_code':do_apns_code})
|
|
|
|
|
|
def get_msg_title(self, appBundleId, nickname):
|
|
|
package_title_config = {
|
|
@@ -387,9 +414,11 @@ class NotificationView(View):
|
|
|
# return
|
|
|
|
|
|
def do_fcm(self, uid, channel, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
|
|
|
+ logger = logging.getLogger('info')
|
|
|
try:
|
|
|
serverKey = FCM_CONFIG[appBundleId]
|
|
|
except Exception as e:
|
|
|
+ logger.info('------fcm_error:{}'.format(repr(e)))
|
|
|
return 'serverKey abnormal'
|
|
|
push_service = FCMNotification(api_key=serverKey)
|
|
|
data = {"alert": "Motion ", "event_time": n_time, "event_type": event_type, "msg": "",
|
|
@@ -401,6 +430,8 @@ class NotificationView(View):
|
|
|
'default_sound': True,
|
|
|
'default_light_settings': True
|
|
|
})
|
|
|
+ logger.info('------fcm_status:')
|
|
|
+ logger.info(result)
|
|
|
print('fcm push ing')
|
|
|
print(result)
|
|
|
return result
|
|
@@ -425,7 +456,7 @@ class NotificationView(View):
|
|
|
n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
res = cli.push(n=n, device_token=token_val, topic=appBundleId)
|
|
|
print(res.status_code)
|
|
|
- logger.info("推送状态:")
|
|
|
+ logger.info("apns_推送状态:")
|
|
|
logger.info(res.status_code)
|
|
|
|
|
|
# 200, 推送成功。
|
|
@@ -445,7 +476,8 @@ class NotificationView(View):
|
|
|
return 'The program has a numeric format exception, one of the arithmetic exceptions'
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
- logger.info(repr(e))
|
|
|
+ print('do_apns函数错误行号', e.__traceback__.tb_lineno)
|
|
|
+ logger.info('do_apns错误:{}'.format(repr(e)))
|
|
|
return repr(e)
|
|
|
|
|
|
def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
|