chenjunkai 6 سال پیش
والد
کامیت
dc4d1a1fe9
4فایلهای تغییر یافته به همراه44 افزوده شده و 58 حذف شده
  1. 28 56
      Controller/DetectController.py
  2. 7 1
      Controller/UserController.py
  3. 1 0
      Model/models.py
  4. 8 1
      Service/CommonService.py

+ 28 - 56
Controller/DetectController.py

@@ -146,6 +146,7 @@ class DetectControllerView(View):
         m_code = request_dict.get('m_code', None)
         # 设备语言
         lang = request_dict.get('lang', 'en')
+        tz = request_dict.get('tz', '0')
         # interval = request_dict.get('interval', None)
         if not status:
             return response.json(444, 'status')
@@ -168,9 +169,9 @@ class DetectControllerView(View):
         status = int(status)
         if dvqs.exists():
             # 获取用户区域
-            ip = self.ip
-            ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
-            area = ipInfo['country_name']
+            # ip = self.ip
+            # ipInfo = CommonService.getIpIpInfo(ip=ip, lang='EN')
+            # area = ipInfo['country_name']
             # if area == 'China':
             #     DETECT_PUSH_DOMAIN = 'cn.push.dvema.com'
             # else:
@@ -186,7 +187,8 @@ class DetectControllerView(View):
                     'push_type': push_type,
                     'token_val': token_val,
                     'updTime': nowTime,
-                    'lang': lang
+                    'lang': lang,
+                    'tz': tz
                 }
                 uid_set_qs.update(detect_status=status, updTime=nowTime)
                 UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
@@ -230,7 +232,8 @@ class DetectControllerView(View):
                     'm_code': m_code,
                     'addTime': nowTime,
                     'updTime': nowTime,
-                    'lang': lang
+                    'lang': lang,
+                    'tz': tz
                 }
                 # 绑定设备推送
                 UidPushModel.objects.create(**uid_push_create_dict)
@@ -292,8 +295,11 @@ class NotificationView(View):
         if uid_set_qs.exists():
             uid_set_id = uid_set_qs[0].id
             nickname = uid_set_qs[0].nickname
+            if not nickname:
+                nickname = uid
             uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
-                values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang')
+                values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
+                       'tz')
             if uid_set_qs.exists():
                 redisObj = RedisObject(db=6)
                 pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
@@ -341,7 +347,7 @@ class NotificationView(View):
         appBundleId = uaql['appBundleId']
         token_val = uaql['token_val']
         lang = uaql['lang']
-
+        tz = uaql['tz']
         response = ResponseObject()
         app_key = JPUSH_CONFIG[appBundleId]['Key']
         master_secret = JPUSH_CONFIG[appBundleId]['Secret']
@@ -354,24 +360,8 @@ class NotificationView(View):
         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}
-        n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
-        if lang == 'cn':
-            if nickname:
-                # message_title = "周视({nickname})".format(nickname=nickname)
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
-            else:
-                # message_title = "周视({uid})".format(uid=uid)
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
-            send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
-        else:
-            if nickname:
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
-                # message_title = "zosi({nickname})".format(nickname=nickname)
-            else:
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
-
-                # message_title = "zosi({uid})".format(uid=uid)
-            send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
+        message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
+        send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
         android = jpush.android(alert=send_text, priority=1, style=1, alert_type=7,
                                 big_text=send_text, title=message_title,
                                 extras=push_data)
@@ -408,11 +398,19 @@ class NotificationView(View):
         else:
             return nickname
 
+    def get_send_text(self, channel, n_time, lang, tz):
+        n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz)
+        send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
+        if lang == 'cn':
+            send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
+        return send_text
+
     def do_fcm(self, request_dict, uaql, response, uid, channel, nickname):
         n_time = request_dict.get('n_time')
         appBundleId = uaql['appBundleId']
         token_val = uaql['token_val']
         lang = uaql['lang']
+        tz = uaql['tz']
         try:
             serverKey = FCM_CONFIG[appBundleId]
         except Exception as e:
@@ -420,24 +418,8 @@ class NotificationView(View):
         event_type = request_dict.get('event_type', None)
         push_service = FCMNotification(api_key=serverKey)
         registration_id = token_val
-        n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
-        if lang == 'cn':
-            if nickname:
-                # message_title = "周视({nickname})".format(nickname=nickname)
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
-            else:
-                # message_title = "周视({uid})".format(uid=uid)
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
-            send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
-        else:
-            if nickname:
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
-                # message_title = "zosi({nickname})".format(nickname=nickname)
-            else:
-                message_title = self.get_message_title(appBundleId=appBundleId, nickname=uid)
-
-                # message_title = "zosi({uid})".format(uid=uid)
-            send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
+        message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
+        send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
         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=registration_id, message_title=message_title,
@@ -456,19 +438,9 @@ class NotificationView(View):
         lang = uaql['lang']
         n_time = request_dict.get('n_time')
         appBundleId = uaql['appBundleId']
-        n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(int(n_time)))
-        if lang == 'cn':
-            if nickname:
-                message_title = "周视({nickname})".format(nickname=nickname)
-            else:
-                message_title = "周视({uid})".format(uid=uid)
-            send_text = '通道:{channel} 日期:{date}'.format(channel=channel, date=n_date)
-        else:
-            if nickname:
-                message_title = "zosi({nickname})".format(nickname=nickname)
-            else:
-                message_title = "zosi({uid})".format(uid=uid)
-            send_text = 'channel:{channel} date:{date}'.format(channel=channel, date=n_date)
+        tz = uaql['tz']
+        message_title = self.get_message_title(appBundleId=appBundleId, nickname=nickname)
+        send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz)
         try:
             cli = apns2.APNSClient(mode="dev", client_cert=APNS_CONFIG[appBundleId]['pem_path'],
                                    password=APNS_CONFIG[appBundleId]['password'])

+ 7 - 1
Controller/UserController.py

@@ -1264,6 +1264,7 @@ class InitInfoView(View):
         m_code = request_dict.get('m_code', None)
         push_type = request_dict.get('push_type', None)
         appBundleId = request_dict.get('appBundleId', None)
+        tz = request_dict.get('tz', None)
         if all([token_val, push_type, appBundleId]):
             if push_type == 0:
                 if appBundleId not in APNS_CONFIG.keys():
@@ -1281,8 +1282,13 @@ class InitInfoView(View):
                 uid_set_id_list = UidSetModel.objects.filter(uid__in=uid_list, detect_status=1).values_list('id',
                                                                                                             flat=True)
                 if uid_set_id_list:
+                    update_dict = {
+                        'token_val': token_val,
+                        'push_type': push_type,
+                        'tz': tz
+                    }
                     UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set_id__in=uid_set_id_list). \
-                        update(token_val=token_val, push_type=push_type)
+                        update(**update_dict)
         res = {
             'usmsg': sm_count
         }

+ 1 - 0
Model/models.py

@@ -693,6 +693,7 @@ class UidPushModel(models.Model):
     addTime = models.IntegerField(verbose_name='添加时间', default=0)
     updTime = models.IntegerField(verbose_name='更新时间', default=0)
     lang = models.CharField(max_length=8, verbose_name='推送语言类型', default='en')  # en英文 cn中文
+    tz = models.CharField(max_length=8, verbose_name='utc时区', default='0')
 
     class Meta:
         db_table = 'uid_push'

+ 8 - 1
Service/CommonService.py

@@ -102,7 +102,7 @@ class CommonService:
 
     # 通过ip检索ipip指定信息 lang为CN或EN
     @staticmethod
-    def getIpIpInfo(ip,lang,update=False):
+    def getIpIpInfo(ip, lang, update=False):
         ipbd_dir = BASE_DIR + "/DB/mydata4vipday2.ipdb"
         db = ipdb.City(ipbd_dir)
         if update:
@@ -193,3 +193,10 @@ class CommonService:
                     ps['data_joined'] = ''
             res.append(ps)
         return res
+
+    # 获取当前时间
+    @staticmethod
+    def get_now_time_str(n_time, tz):
+        n_time = n_time + 3600 * float(tz)
+        n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(n_time)))
+        return n_date