|
@@ -11,22 +11,26 @@
|
|
|
@file: DetectController.py
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
+import json
|
|
|
+import os
|
|
|
+import time
|
|
|
+
|
|
|
+import apns2
|
|
|
+import jpush as jpush
|
|
|
+import oss2
|
|
|
+import requests
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic.base import View
|
|
|
-import time
|
|
|
-import apns2
|
|
|
-from Object.ResponseObject import ResponseObject
|
|
|
-import os
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
-from Object.TokenObject import TokenObject
|
|
|
-import jpush as jpush
|
|
|
-from Model.models import Device_User, Device_Info, Equipment_Info, App_Info, UID_App
|
|
|
-from Object.UidTokenObject import UidTokenObject
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
-import json
|
|
|
-import requests
|
|
|
+from Model.models import Device_Info, App_Info, UID_App
|
|
|
from Model.models import Equipment_Info
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
+from Object.UidTokenObject import UidTokenObject
|
|
|
+from django.http import JsonResponse
|
|
|
|
|
|
|
|
|
# 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
|
|
@@ -69,8 +73,13 @@ class DetectControllerView(View):
|
|
|
print('status')
|
|
|
print(status)
|
|
|
if status == '0':
|
|
|
- UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, token_val=token_val, uid=uid).delete()
|
|
|
- return response.json(0)
|
|
|
+ uid_app_qs = UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, token_val=token_val,
|
|
|
+ uid=uid)
|
|
|
+ if uid_app_qs.exists():
|
|
|
+ uid_app_qs.update(status=0)
|
|
|
+ return response.json(0)
|
|
|
+ else:
|
|
|
+ return response.json(173)
|
|
|
elif status == '1':
|
|
|
# return response.json(10)
|
|
|
|
|
@@ -81,18 +90,25 @@ class DetectControllerView(View):
|
|
|
if dvqs.exists() and aiqs.exists():
|
|
|
now_time = int(time.time())
|
|
|
try:
|
|
|
- UID_App.objects.create(
|
|
|
- uid=uid,
|
|
|
- userID_id=userID,
|
|
|
- appBundleId=appBundleId,
|
|
|
- app_type=aiqs[0]['app_type'],
|
|
|
- push_type=push_type,
|
|
|
- token_val=token_val,
|
|
|
- addTime=now_time,
|
|
|
- updTime=now_time)
|
|
|
+ uid_app_qs = UID_App.objects.filter(appBundleId=appBundleId, userID_id=userID, token_val=token_val,
|
|
|
+ uid=uid)
|
|
|
+ print(uid_app_qs)
|
|
|
+ if uid_app_qs.exists():
|
|
|
+ uid_app_qs.update(status=1)
|
|
|
+ else:
|
|
|
+ UID_App.objects.create(
|
|
|
+ uid=uid,
|
|
|
+ userID_id=userID,
|
|
|
+ appBundleId=appBundleId,
|
|
|
+ app_type=aiqs[0]['app_type'],
|
|
|
+ push_type=push_type,
|
|
|
+ token_val=token_val,
|
|
|
+ status=1,
|
|
|
+ addTime=now_time,
|
|
|
+ updTime=now_time)
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
- return response.json(10,repr(e))
|
|
|
+ return response.json(10, repr(e))
|
|
|
else:
|
|
|
utko = UidTokenObject()
|
|
|
utko.generate(data={'uid': uid})
|
|
@@ -102,6 +118,8 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
|
|
|
+
|
|
|
+# http://192.168.136.40:8077/notify/push?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJUTjdNUEUzMjExVUU3NkFQMTExQSJ9.k501567VdnhFpn_ygzGRDat3Kqlz5CsEA9jAC2dDk_g&obj=12341234&n_time=1234561234
|
|
|
# 移动侦测接口
|
|
|
class NotificationView(View):
|
|
|
|
|
@@ -118,6 +136,11 @@ class NotificationView(View):
|
|
|
def validation(self, request_dict):
|
|
|
response = ResponseObject()
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
|
+ channel = request_dict.get('channel', None)
|
|
|
+ n_time = request_dict.get('n_time')
|
|
|
+ if not all([uidToken, channel, n_time]):
|
|
|
+ return JsonResponse(status=404)
|
|
|
+ # return response.json(444)
|
|
|
utko = UidTokenObject(uidToken)
|
|
|
uid = utko.UID
|
|
|
uaqs = UID_App.objects.filter(uid=uid). \
|
|
@@ -134,11 +157,26 @@ class NotificationView(View):
|
|
|
# android jpush
|
|
|
elif push_type == 2:
|
|
|
self.do_jpush(request_dict, ua, response)
|
|
|
- n_time = request_dict.get('n_time')
|
|
|
- self.do_save_equipment_info(ua, n_time)
|
|
|
- return response.json(0)
|
|
|
+ self.do_save_equipment_info(ua, n_time, channel)
|
|
|
+ #############
|
|
|
+ # 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
|
|
+ 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)
|
|
|
+ res_data = {
|
|
|
+ 'code': 0,
|
|
|
+ 'img_push': url,
|
|
|
+ 'msg': 'success'
|
|
|
+ }
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+ ############
|
|
|
else:
|
|
|
- return response.json(173)
|
|
|
+ return JsonResponse(status=200, data={
|
|
|
+ 'code': 173,
|
|
|
+ 'msg': 'data is not exist'})
|
|
|
|
|
|
def do_jpush(self, request_dict, uaql, response):
|
|
|
jpush_config = {
|
|
@@ -266,20 +304,19 @@ class NotificationView(View):
|
|
|
# assert res.status_code == 200, res.reason
|
|
|
# assert res.apns_id
|
|
|
if res.status_code == 200:
|
|
|
- # self.do_save_equipment_info(uaql, n_time)
|
|
|
return response.json(0)
|
|
|
else:
|
|
|
return response.json(404, res.reason)
|
|
|
except Exception as e:
|
|
|
return response.json(10, repr(e))
|
|
|
|
|
|
- def do_save_equipment_info(self, uaql, n_time):
|
|
|
+ def do_save_equipment_info(self, uaql, n_time, channel):
|
|
|
Equipment_Info.objects.create(
|
|
|
userID_id=uaql['userID_id'],
|
|
|
eventTime=n_time,
|
|
|
eventType=1,
|
|
|
devUid=uaql['uid'],
|
|
|
devNickName=uaql['userID__NickName'],
|
|
|
- Channel='0',
|
|
|
+ Channel=channel,
|
|
|
alarm='0',
|
|
|
receiveTime=n_time)
|