|
@@ -11,32 +11,32 @@
|
|
|
@file: DetectController.py
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
+import datetime
|
|
|
+import json
|
|
|
import logging
|
|
|
import os
|
|
|
import time
|
|
|
-import json
|
|
|
+
|
|
|
import apns2
|
|
|
+import boto3
|
|
|
+import botocore
|
|
|
import jpush as jpush
|
|
|
-import oss2
|
|
|
+from botocore import client
|
|
|
from django.http import JsonResponse
|
|
|
from django.views.generic.base import View
|
|
|
from pyfcm import FCMNotification
|
|
|
-from AnsjerPush.config import SERVER_TYPE
|
|
|
-from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, JPUSH_CONFIG, FCM_CONFIG, \
|
|
|
+
|
|
|
+from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
|
|
|
+from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, \
|
|
|
APNS_CONFIG, BASE_DIR, APNS_MODE
|
|
|
+from AnsjerPush.config import SERVER_TYPE
|
|
|
from Model.models import Equipment_Info, UidPushModel, SysMsgModel
|
|
|
from Object.ETkObject import ETkObject
|
|
|
-from Object.LogUtil import LogUtil
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
+from Object.utils import LocalDateTimeUtil
|
|
|
from Service.CommonService import CommonService
|
|
|
-import boto3
|
|
|
-from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
|
|
|
-import botocore
|
|
|
-from botocore import client
|
|
|
-import datetime
|
|
|
from Service.EquipmentInfoService import EquipmentInfoService
|
|
|
-from Object.utils import LocalDateTimeUtil
|
|
|
|
|
|
'''
|
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
@@ -148,7 +148,7 @@ class NotificationView(View):
|
|
|
detect_interval = 60
|
|
|
redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
|
|
|
- if is_st == 1 or is_st == 3: # 使用aws s3
|
|
|
+ if is_st == 1 or is_st == 3: # 使用aws s3
|
|
|
aws_s3_client = s3_client(region=region)
|
|
|
kwag_args = {
|
|
|
'uid': uid,
|
|
@@ -167,6 +167,10 @@ class NotificationView(View):
|
|
|
logger.info(redis_list)
|
|
|
new_device_info_list = []
|
|
|
local_date_now = str(datetime.datetime.fromtimestamp(int(n_time)).date())
|
|
|
+ timeArray = time.localtime(n_time)
|
|
|
+ str_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
|
|
|
+ logging.info('设备格式化后时间{},设备时间戳{}'.format(str_time, n_time))
|
|
|
+ logger.info('日期{},时间戳{}'.format(local_date_now, n_time))
|
|
|
for up in redis_list:
|
|
|
push_type = up['push_type']
|
|
|
appBundleId = up['appBundleId']
|
|
@@ -246,7 +250,8 @@ class NotificationView(View):
|
|
|
elif push_type == 2: # android jpush
|
|
|
do_jpush_code = self.do_jpush(**kwag_args)
|
|
|
except Exception as e:
|
|
|
- logger.info("errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno,errMsg=repr(e)))
|
|
|
+ logger.info(
|
|
|
+ "errLine={errLine}, errMsg={errMsg}".format(errLine=e.__traceback__.tb_lineno, errMsg=repr(e)))
|
|
|
continue
|
|
|
if is_sys_msg:
|
|
|
SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
@@ -283,7 +288,7 @@ class NotificationView(View):
|
|
|
Params = {'Key': thumbspng}
|
|
|
if region == 2: # 2:国内
|
|
|
Params['Bucket'] = 'push'
|
|
|
- else: # 1:国外
|
|
|
+ else: # 1:国外
|
|
|
Params['Bucket'] = 'foreignpush'
|
|
|
response_url = generate_s3_url(aws_s3_client, Params)
|
|
|
for up in redis_list:
|
|
@@ -306,7 +311,7 @@ class NotificationView(View):
|
|
|
img_url_list = []
|
|
|
if region == 2: # 2:国内
|
|
|
Params = {'Bucket': 'push'}
|
|
|
- else: # 1:国外
|
|
|
+ else: # 1:国外
|
|
|
Params = {'Bucket': 'foreignpush'}
|
|
|
for i in range(is_st):
|
|
|
thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
|
|
@@ -339,19 +344,20 @@ class NotificationView(View):
|
|
|
'errMsg': repr(e),
|
|
|
}
|
|
|
return JsonResponse(status=200, data=json.dumps(data), safe=False)
|
|
|
- def test_apns(self,request_dict):
|
|
|
+
|
|
|
+ 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),
|
|
|
+ '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})
|
|
|
+ return JsonResponse(status=500, data={'do_apns_code': do_apns_code})
|
|
|
|
|
|
def get_msg_title(self, appBundleId, nickname):
|
|
|
package_title_config = {
|
|
@@ -372,7 +378,6 @@ class NotificationView(View):
|
|
|
else:
|
|
|
return nickname
|
|
|
|
|
|
-
|
|
|
def is_sys_msg(self, event_type):
|
|
|
event_type_list = [702, 703, 704]
|
|
|
if event_type in event_type_list:
|
|
@@ -380,7 +385,7 @@ class NotificationView(View):
|
|
|
return False
|
|
|
|
|
|
def get_msg_text(self, channel, n_time, lang, tz, event_type, electricity='', is_sys=0):
|
|
|
- n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
|
|
|
etype = int(event_type)
|
|
|
if lang == 'cn':
|
|
|
if etype == 704:
|
|
@@ -577,7 +582,7 @@ class PushNotificationView(View):
|
|
|
# 从数据库查询出来
|
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
values('token_val', 'app_type', 'appBundleId',
|
|
|
- 'push_type', 'userID_id', 'lang','m_code',
|
|
|
+ 'push_type', 'userID_id', 'lang', 'm_code',
|
|
|
'tz', 'uid_set__nickname')
|
|
|
# 新建一个list接收数据
|
|
|
redis_list = []
|
|
@@ -621,7 +626,7 @@ class PushNotificationView(View):
|
|
|
},
|
|
|
ExpiresIn=3600
|
|
|
)
|
|
|
- else: # 1:国外
|
|
|
+ else: # 1:国外
|
|
|
response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
ClientMethod='put_object',
|
|
|
Params={
|
|
@@ -654,7 +659,7 @@ class PushNotificationView(View):
|
|
|
},
|
|
|
ExpiresIn=3600
|
|
|
)
|
|
|
- else: # 1:国外
|
|
|
+ else: # 1:国外
|
|
|
response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
ClientMethod='put_object',
|
|
|
Params={
|
|
@@ -763,8 +768,6 @@ class PushNotificationView(View):
|
|
|
return send_text
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
# 低电量推送接口
|
|
|
class PWnotificationView(View):
|
|
|
|
|
@@ -830,7 +833,7 @@ class PWnotificationView(View):
|
|
|
msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
# 发送内容
|
|
|
msg_text = self.get_msg_text(channel=channel, n_time=now_time, lang=lang, tz=tz,
|
|
|
- event_type=event_type, electricity= electricity)
|
|
|
+ event_type=event_type, electricity=electricity)
|
|
|
kwag_args['appBundleId'] = appBundleId
|
|
|
kwag_args['token_val'] = token_val
|
|
|
kwag_args['msg_title'] = msg_title
|
|
@@ -891,7 +894,7 @@ class PWnotificationView(View):
|
|
|
return False
|
|
|
|
|
|
def get_msg_text(self, channel, n_time, lang, tz, event_type, electricity, is_sys=0):
|
|
|
- n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz,lang=lang)
|
|
|
+ n_date = CommonService.get_now_time_str(n_time=n_time, tz=tz, lang=lang)
|
|
|
etype = int(event_type)
|
|
|
if lang == 'cn':
|
|
|
if etype == 704:
|