|
@@ -31,7 +31,6 @@ from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from django.http import JsonResponse
|
|
|
-from Service.CommonService import CommonService
|
|
|
|
|
|
|
|
|
# http://192.168.136.40:8077/detect/changeStatus?uid=JW3684H8BSHG9TTM111A&token_val=18071adc03536302f34&appBundleId=com.ansjer.zccloud_ab&push_type=2&token=local&status=1&app_type=1
|
|
@@ -81,7 +80,7 @@ class DetectControllerView(View):
|
|
|
dvqs = Device_Info.objects.filter(UID=uid).values('Type')
|
|
|
uid_type_dict = {uid: dvqs[0]['Type']}
|
|
|
else:
|
|
|
- dvqs = Device_Info.objects.filter(userID_id=userID).values('UID','Type')
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID).values('UID', 'Type')
|
|
|
uid_type_dict = {}
|
|
|
for dv in dvqs:
|
|
|
uid_type_dict[dv['UID']] = dv['Type']
|
|
@@ -100,7 +99,11 @@ class DetectControllerView(View):
|
|
|
p['img'] = bucket.sign_url('GET',
|
|
|
'{uid}/{channel}/{time}.jpeg'.format(uid=p['devUid'], channel=p['Channel'],
|
|
|
time=p['eventTime']), 300)
|
|
|
- p['uid_type'] = uid_type_dict[p['devUid']]
|
|
|
+ uid_type_s = ''
|
|
|
+ if p['devUid'] in uid_type_dict.keys():
|
|
|
+ uid_type_s = uid_type_dict[p['devUid']]
|
|
|
+ p['uid_type'] = uid_type_s
|
|
|
+
|
|
|
res.append(p)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
@@ -112,10 +115,11 @@ class DetectControllerView(View):
|
|
|
push_type = request_dict.get('push_type', None)
|
|
|
status = request_dict.get('status', None)
|
|
|
m_code = request_dict.get('m_code', None)
|
|
|
- print('status')
|
|
|
- print(status)
|
|
|
+ interval = request_dict.get('interval', None)
|
|
|
+ print('status:' + status)
|
|
|
if not status:
|
|
|
return response.json(444, 'status')
|
|
|
+ # 关闭推送
|
|
|
if status == '0':
|
|
|
if not all([app_type, appBundleId, uid, m_code]):
|
|
|
return response.json(444, 'app_type,appBundleId,uid,m_code')
|
|
@@ -126,6 +130,7 @@ class DetectControllerView(View):
|
|
|
return response.json(0)
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
+ # 开启推
|
|
|
elif status == '1':
|
|
|
if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
@@ -138,19 +143,25 @@ class DetectControllerView(View):
|
|
|
uid=uid, m_code=m_code)
|
|
|
print(uid_app_qs)
|
|
|
if uid_app_qs.exists():
|
|
|
- uid_app_qs.update(status=1)
|
|
|
+ update_dict = {status: 1}
|
|
|
+ if interval:
|
|
|
+ update_dict['interval'] = int(interval)
|
|
|
+ uid_app_qs.update(**update_dict)
|
|
|
else:
|
|
|
- UID_App.objects.create(
|
|
|
- uid=uid,
|
|
|
- userID_id=userID,
|
|
|
- appBundleId=appBundleId,
|
|
|
- app_type=app_type,
|
|
|
- push_type=push_type,
|
|
|
- token_val=token_val,
|
|
|
- status=1,
|
|
|
- m_code=m_code,
|
|
|
- addTime=now_time,
|
|
|
- updTime=now_time)
|
|
|
+ create_dict = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'userID_id': userID,
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'push_type': push_type,
|
|
|
+ 'token_val': token_val,
|
|
|
+ 'status': 1,
|
|
|
+ 'm_code': m_code,
|
|
|
+ 'addTime': now_time,
|
|
|
+ 'updTime': now_time}
|
|
|
+ if interval:
|
|
|
+ create_dict['interval'] = int(interval)
|
|
|
+ UID_App.objects.create(**create_dict)
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
return response.json(10, repr(e))
|
|
@@ -187,13 +198,19 @@ class NotificationView(View):
|
|
|
event_type = request_dict.get('event_type', None)
|
|
|
is_st = request_dict.get('is_st', None)
|
|
|
if not all([uidToken, channel, n_time]):
|
|
|
- return JsonResponse(status=404, data={})
|
|
|
+ return JsonResponse(status=200, data={
|
|
|
+ 'code': 444,
|
|
|
+ 'msg': 'param is wrong'})
|
|
|
# return response.json(444)
|
|
|
utko = UidTokenObject(uidToken)
|
|
|
uid = utko.UID
|
|
|
uaqs = UID_App.objects.filter(uid=uid, status=1). \
|
|
|
- values('token_val', 'app_type', 'appBundleId', 'push_type', 'uid', 'userID_id', 'userID__NickName')
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'push_type', 'uid', 'userID_id', 'userID__NickName',
|
|
|
+ 'interval')
|
|
|
if uaqs.exists():
|
|
|
+
|
|
|
+ auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
+ bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
for ua in uaqs:
|
|
|
push_type = ua['push_type']
|
|
|
# ios apns
|
|
@@ -204,20 +221,15 @@ class NotificationView(View):
|
|
|
self.do_gmc(request_dict, ua, response)
|
|
|
# android jpush
|
|
|
elif push_type == 2:
|
|
|
- print('===============')
|
|
|
- print(push_type)
|
|
|
- print('=============')
|
|
|
self.do_jpush(request_dict, ua, response)
|
|
|
- self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
- #############
|
|
|
- # 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
|
|
|
|
|
+ # self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
|
+ # 需求不一样,所以这么做的
|
|
|
+ self.do_bulk_create_info(uaqs, n_time, channel, event_type, is_st)
|
|
|
if is_st == '0':
|
|
|
return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
else:
|
|
|
- auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
# Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
- bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
obj = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
|
|
|
# 设置此签名URL在60秒内有效。
|
|
|
url = bucket.sign_url('PUT', obj, 7200)
|
|
@@ -226,7 +238,7 @@ class NotificationView(View):
|
|
|
############
|
|
|
else:
|
|
|
return JsonResponse(status=200, data={
|
|
|
- 'code': 173,
|
|
|
+ 'code': 404,
|
|
|
'msg': 'data is not exist'})
|
|
|
|
|
|
def do_jpush(self, request_dict, uaql, response):
|
|
@@ -274,10 +286,6 @@ class NotificationView(View):
|
|
|
response = ResponseObject()
|
|
|
app_key = jpush_config[appBundleId]['Key']
|
|
|
master_secret = jpush_config[appBundleId]['Secret']
|
|
|
- print('===============')
|
|
|
- print(app_key)
|
|
|
- print(master_secret)
|
|
|
- print('=============')
|
|
|
# 此处换成各自的app_key和master_secre
|
|
|
_jpush = jpush.JPush(app_key, master_secret)
|
|
|
push = _jpush.create_push()
|
|
@@ -287,13 +295,6 @@ 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"}
|
|
|
- push_msg = json.dumps(push_data)
|
|
|
- # push.notification = jpush.notification(alert="hello jpush api")
|
|
|
- # push.notification = jpush.notification(alert=push_msg)
|
|
|
- # android = jpush.android(alert="Hello, Android msg",extras=push_data)
|
|
|
-
|
|
|
- # push.notification = jpush.notification(alert="Hello, JPush!", android=android)
|
|
|
- # push.notification = jpush.message(msg_content=push_data, extras=push_data)
|
|
|
push.message = jpush.message('Motion', extras=push_data, title='KPNS', content_type='text')
|
|
|
push.platform = jpush.all_
|
|
|
try:
|
|
@@ -378,3 +379,28 @@ class NotificationView(View):
|
|
|
alarm='0',
|
|
|
is_st=int(is_st),
|
|
|
receiveTime=n_time)
|
|
|
+
|
|
|
+ def do_bulk_create_info(self, uaqs, n_time, channel, event_type, is_st):
|
|
|
+ #
|
|
|
+ qs_list = []
|
|
|
+ for dv in uaqs:
|
|
|
+ add_data = {
|
|
|
+ 'userID_id': dv["userID_id"],
|
|
|
+ 'eventTime': n_time,
|
|
|
+ 'eventType': event_type,
|
|
|
+ 'devUid': dv['uid'],
|
|
|
+ 'devNickName': dv['userID__NickName'],
|
|
|
+ 'Channel': channel,
|
|
|
+ 'alarm': 'Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
+ 'is_st': int(is_st),
|
|
|
+ 'receiveTime': n_time
|
|
|
+ }
|
|
|
+ qs_list.append(Equipment_Info(**add_data))
|
|
|
+ if qs_list:
|
|
|
+ print(1)
|
|
|
+ Equipment_Info.objects.bulk_create(qs_list)
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
+ else:
|
|
|
+ return False
|