Browse Source

Merge branch 'test' of http://192.168.136.99:3000/servers/ASJPush into test

locky 3 years ago
parent
commit
a734f1810a
3 changed files with 41 additions and 4 deletions
  1. 4 0
      AnsjerPush/urls.py
  2. 36 4
      Controller/DetectControllerV2.py
  3. 1 0
      Service/CommonService.py

+ 4 - 0
AnsjerPush/urls.py

@@ -16,6 +16,7 @@ Including another URLconf
 from django.contrib import admin
 from django.contrib import admin
 from django.urls import path
 from django.urls import path
 from Controller import DetectController, ShadowController, TestDetectController, EquipmentInfo, DetectControllerV2
 from Controller import DetectController, ShadowController, TestDetectController, EquipmentInfo, DetectControllerV2
+from django.conf.urls import url
 
 
 urlpatterns = [
 urlpatterns = [
     path('admin/', admin.site.urls),
     path('admin/', admin.site.urls),
@@ -27,4 +28,7 @@ urlpatterns = [
     path('test/notify/push', TestDetectController.NotificationView.as_view()),
     path('test/notify/push', TestDetectController.NotificationView.as_view()),
     path('eq/del', EquipmentInfo.deleteExpireEquipmentInfo),
     path('eq/del', EquipmentInfo.deleteExpireEquipmentInfo),
     path('push/healthCheck', EquipmentInfo.healthCheck),
     path('push/healthCheck', EquipmentInfo.healthCheck),
+    path('notifyV2/push', DetectControllerV2.NotificationView.as_view()),
+    url(r'^notifyV2/(?P<operation>.*)$', DetectControllerV2.NotificationView.as_view()),
+
 ]
 ]

+ 36 - 4
Controller/DetectControllerV2.py

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

+ 1 - 0
Service/CommonService.py

@@ -200,6 +200,7 @@ class CommonService:
         print(n_time)
         print(n_time)
         print(tz)
         print(tz)
         print(lang)
         print(lang)
+        tz = tz.replace(':', '.')
         n_time = int(n_time) + 3600 * float(tz)
         n_time = int(n_time) + 3600 * float(tz)
         if lang == 'cn':
         if lang == 'cn':
             return time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(n_time)))
             return time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(n_time)))