|
@@ -24,7 +24,7 @@ from Object.RedisObject import RedisObject
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, DETECT_PUSH_DOMAIN, \
|
|
|
JPUSH_CONFIG, \
|
|
|
FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, DETECT_PUSH_DOMAINS, DETECT_PUSH_DOMAIN_JIUAN, \
|
|
|
- DETECT_PUSH_DOMAINS_JIUAN
|
|
|
+ DETECT_PUSH_DOMAINS_JIUAN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_ARN
|
|
|
from Model.models import Device_Info, VodHlsModel, Equipment_Info, UidSetModel, UidPushModel, CompanyModel
|
|
|
from Object.ETkObject import ETkObject
|
|
|
from Object.RedisObject import RedisObject
|
|
@@ -33,6 +33,9 @@ from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from Service.CommonService import CommonService
|
|
|
from Service.ModelService import ModelService
|
|
|
+import boto3
|
|
|
+import botocore
|
|
|
+from botocore import client
|
|
|
|
|
|
'''
|
|
|
http://test.push.dvema.com/notify/push?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJUNEFaM0NVS0NFUkg5RlpBMTExQSJ9.GtrXeq5gb2Z9M3mKECxi9eNQbPxqC-6PtgJkOOg6PwI&n_time=1598456451&channel=1&event_type=1&is_st=1
|
|
@@ -73,12 +76,17 @@ class DetectControllerViewV2(View):
|
|
|
if operation == 'changeStatus':
|
|
|
print("进入changeStatus")
|
|
|
return self.do_change_status(userID, request_dict, response)
|
|
|
+ # 查询推送信息
|
|
|
+ elif operation == 'queryInfo':
|
|
|
+ return self.do_query(request_dict, response, userID)
|
|
|
+ # 更新推送延迟
|
|
|
+ elif operation == 'updateInterval':
|
|
|
+ return self.do_update_interval(userID, request_dict, response)
|
|
|
else:
|
|
|
return response.json(414)
|
|
|
else:
|
|
|
return response.json(tko.code)
|
|
|
|
|
|
-
|
|
|
def do_change_status(self, userID, request_dict, response):
|
|
|
token_val = request_dict.get('token_val', None)
|
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
@@ -91,6 +99,10 @@ class DetectControllerViewV2(View):
|
|
|
lang = request_dict.get('lang', 'en')
|
|
|
tz = request_dict.get('tz', '0')
|
|
|
company_secrete = request_dict.get('company_secrete', None)
|
|
|
+ region = request_dict.get('region', None) # app必须传:2:国内 1:国外
|
|
|
+ if not region:
|
|
|
+ return response.json(444, 'region')
|
|
|
+ region = int(region)
|
|
|
# 消息提醒功能新增
|
|
|
|
|
|
# 如果传空上来,就默认为0
|
|
@@ -225,10 +237,10 @@ class DetectControllerViewV2(View):
|
|
|
else:
|
|
|
url = DETECT_PUSH_DOMAIN_JIUAN
|
|
|
urls = DETECT_PUSH_DOMAINS_JIUAN
|
|
|
- detectUrl = "{DETECT_PUSH_DOMAIN}notifyV2/push?etk={etk}&company_secrete={company_secrete}". \
|
|
|
- format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN=url)
|
|
|
- detectUrls = "{DETECT_PUSH_DOMAIN_V2}notifyV2/push?etk={etk}&company_secrete={company_secrete}". \
|
|
|
- format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN_V2=urls)
|
|
|
+ detectUrl = "{DETECT_PUSH_DOMAIN}notifyV2/push?etk={etk}&company_secrete={company_secrete}®ion={region}". \
|
|
|
+ format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN=url, region=region)
|
|
|
+ detectUrls = "{DETECT_PUSH_DOMAIN_V2}notifyV2/push?etk={etk}&company_secrete={company_secrete}®ion={region}". \
|
|
|
+ format(etk=etk, company_secrete=company_secrete, DETECT_PUSH_DOMAIN_V2=urls, region=region)
|
|
|
return response.json(0, {'detectUrl': detectUrl, 'detectUrls': detectUrls})
|
|
|
else:
|
|
|
return response.json(14)
|
|
@@ -248,3 +260,140 @@ class DetectControllerViewV2(View):
|
|
|
redisObj.set_data(key=key, val=1, expire=detect_interval)
|
|
|
else:
|
|
|
redisObj.del_data(key=key)
|
|
|
+
|
|
|
+ def do_query(self, request_dict, response, userID):
|
|
|
+ page = int(request_dict.get('page', None))
|
|
|
+ line = int(request_dict.get('line', None))
|
|
|
+ if not page or not line:
|
|
|
+ return response.json(444, 'page,line')
|
|
|
+ startTime = request_dict.get('startTime', None)
|
|
|
+ endTime = request_dict.get('endTime', None)
|
|
|
+ eventType = request_dict.get('eventType', None)
|
|
|
+ region = request_dict.get('region', None)
|
|
|
+ if not region:
|
|
|
+ return response.json(444, 'region')
|
|
|
+ region = int(region)
|
|
|
+ qs = Equipment_Info.objects.filter(userID_id=userID).order_by('-eventTime')
|
|
|
+ if startTime and endTime:
|
|
|
+ qs = qs.filter(eventTime__range=(startTime, endTime))
|
|
|
+ if eventType:
|
|
|
+ qs = qs.filter(eventType=eventType)
|
|
|
+ uids = request_dict.get('uids', None)
|
|
|
+ if uids:
|
|
|
+ uid_list = uids.split(',')
|
|
|
+ qs = qs.filter(devUid__in=uid_list)
|
|
|
+ dvqs = Device_Info.objects.filter(UID__in=uid_list, userID_id=userID).values('UID', 'Type', 'NickName')
|
|
|
+ uid_type_dict = {}
|
|
|
+ for dv in dvqs:
|
|
|
+ uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
|
+ else:
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type', 'NickName')
|
|
|
+ uid_type_dict = {}
|
|
|
+ for dv in dvqs:
|
|
|
+ uid_type_dict[dv['UID']] = {'type': dv['Type'], 'NickName': dv['NickName']}
|
|
|
+ # print(uid_type_dict)
|
|
|
+ if not qs.exists():
|
|
|
+ return response.json(0, {'datas': [], 'count': 0})
|
|
|
+ qs = qs.values('id', 'devUid', 'devNickName', 'Channel', 'eventType', 'status', 'alarm', 'eventTime',
|
|
|
+ 'receiveTime', 'is_st', 'addTime')
|
|
|
+
|
|
|
+ count = qs.count()
|
|
|
+ qr = qs[(page - 1) * line:page * line]
|
|
|
+ res = []
|
|
|
+ aws_s3_guonei = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='cn-northwest-1'
|
|
|
+ )
|
|
|
+ aws_s3_guowai = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='us-east-1'
|
|
|
+ )
|
|
|
+ # vod_time_list = []
|
|
|
+ for p in qr:
|
|
|
+ devUid = p['devUid']
|
|
|
+ eventTime = p['eventTime']
|
|
|
+ channel = p['Channel']
|
|
|
+ if p['is_st'] == 1:
|
|
|
+ thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime)
|
|
|
+ if region == 2: # 2:国内
|
|
|
+ response_url = aws_s3_guonei.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'push', 'Key': thumbspng}, ExpiresIn=3600)
|
|
|
+ p['img'] = response_url
|
|
|
+ p['img_list'] = [response_url]
|
|
|
+ else: # 1:国外
|
|
|
+ response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'foreignpush', 'Key': thumbspng}, ExpiresIn=3600)
|
|
|
+ p['img'] = response_url
|
|
|
+ p['img_list'] = [response_url]
|
|
|
+
|
|
|
+ elif p['is_st'] == 2:
|
|
|
+ # 列表装载回放时间戳标记
|
|
|
+ vodqs = VodHlsModel.objects.filter(uid=devUid, channel=channel, time=int(eventTime)) \
|
|
|
+ .values("bucket__bucket", "bucket__endpoint")
|
|
|
+ # print(vodqs)
|
|
|
+ if vodqs.exists():
|
|
|
+ bucket_name = vodqs[0]['bucket__bucket']
|
|
|
+ endpoint = vodqs[0]['bucket__endpoint']
|
|
|
+ # bucket = oss2.Bucket(auth, endpoint, bucket_name)
|
|
|
+ ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'], etime=eventTime)
|
|
|
+ if region == 2: # 2:国内
|
|
|
+ thumb = aws_s3_guonei.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'push', 'Key': ts}, ExpiresIn=3600)
|
|
|
+ else: # 1:国外
|
|
|
+ thumb = aws_s3_guowai.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'foreignpush', 'Key': ts}, ExpiresIn=3600)
|
|
|
+ p['img_list'] = [thumb]
|
|
|
+ # thumb0 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_0000,w_700'})
|
|
|
+ # thumb1 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_1000,w_700'})
|
|
|
+ # thumb2 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
|
|
|
+ # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
|
|
|
+ # p['img_list'] = [thumb0, thumb1, thumb2]
|
|
|
+ elif p['is_st'] == 3:
|
|
|
+ # 列表装载回放时间戳标记
|
|
|
+ p['img_list'] = []
|
|
|
+ for i in range(p['is_st']):
|
|
|
+ thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime, st=i)
|
|
|
+ if region == 2: # 2:国内
|
|
|
+ response_url = aws_s3_guonei.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'push', 'Key': thumbspng}, ExpiresIn=3600)
|
|
|
+ img = response_url
|
|
|
+ else: # 1:国外
|
|
|
+ response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
+ 'get_object',
|
|
|
+ Params={'Bucket': 'foreignpush', 'Key': thumbspng}, ExpiresIn=3600)
|
|
|
+ img = response_url
|
|
|
+ p['img_list'].append(img)
|
|
|
+ if devUid in uid_type_dict.keys():
|
|
|
+ p['uid_type'] = uid_type_dict[devUid]['type']
|
|
|
+ p['devNickName'] = uid_type_dict[devUid]['NickName']
|
|
|
+ else:
|
|
|
+ p['uid_type'] = ''
|
|
|
+ res.append(p)
|
|
|
+ return response.json(0, {'datas': res, 'count': count})
|
|
|
+
|
|
|
+ def do_update_interval(self, userID, request_dict, response):
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ interval = request_dict.get('interval', None)
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ if dvqs.exists():
|
|
|
+ uid_set_qs = UidSetModel.objects. \
|
|
|
+ filter(uid=uid, uidpushmodel__userID_id=userID)
|
|
|
+ # redisObj = RedisObject(db=8)
|
|
|
+ # redisObj.del_data(key='uid_qs_' + userID)
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_qs.update(interval=int(interval))
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
+ else:
|
|
|
+ return response.json(0)
|