|
@@ -26,13 +26,13 @@ from django.views.generic.base import View
|
|
|
from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
|
from Ansjer.config import BASE_DIR
|
|
|
from Ansjer.config import SERVER_DOMAIN
|
|
|
-from Model.models import Device_Info, VodHlsModel, UID_App
|
|
|
-from Model.models import Equipment_Info
|
|
|
+from Model.models import Device_Info, VodHlsModel, UID_App, Equipment_Info, UidSetModel, UidPushModel
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.UidTokenObject import UidTokenObject
|
|
|
from django.http import JsonResponse
|
|
|
from Object.RedisObject import RedisObject
|
|
|
+from django.db import transaction
|
|
|
|
|
|
|
|
|
# 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
|
|
@@ -130,7 +130,7 @@ class DetectControllerView(View):
|
|
|
res.append(p)
|
|
|
return response.json(0, {'datas': res, 'count': count})
|
|
|
|
|
|
- def do_change_status(self, userID, request_dict, response):
|
|
|
+ def do_change_status11(self, userID, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
token_val = request_dict.get('token_val', None)
|
|
|
appBundleId = request_dict.get('appBundleId', None)
|
|
@@ -197,14 +197,91 @@ class DetectControllerView(View):
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
|
|
|
+ def do_change_status(self, userID, request_dict, response):
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ token_val = request_dict.get('token_val', None)
|
|
|
+ appBundleId = request_dict.get('appBundleId', None)
|
|
|
+ app_type = request_dict.get('app_type', None)
|
|
|
+ push_type = request_dict.get('push_type', None)
|
|
|
+ status = request_dict.get('status', None)
|
|
|
+ m_code = request_dict.get('m_code', None)
|
|
|
+ # interval = request_dict.get('interval', None)
|
|
|
+ print('status:' + status)
|
|
|
+ if not status:
|
|
|
+ return response.json(444, 'status')
|
|
|
+ # 关闭推送
|
|
|
+ if not all([appBundleId, app_type, token_val, uid, m_code]):
|
|
|
+ return response.json(444, 'appBundleId,app_type,token_val,uid,m_code')
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, UID=uid)
|
|
|
+ status = int(status)
|
|
|
+ if dvqs.exists():
|
|
|
+ nowTime = int(time.time())
|
|
|
+ uid_set_qs = UidSetModel.objects. \
|
|
|
+ filter(uid=uid, uidpushmodel__userID_id=userID, uidpushmodel__m_code=m_code)
|
|
|
+ # 判断是否有曾经开启过
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_push_update_dict = {
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'push_type': push_type,
|
|
|
+ 'token_val': token_val,
|
|
|
+ 'updTime': nowTime
|
|
|
+ }
|
|
|
+ uid_set_qs.update(detect_status=status, updTime=nowTime)
|
|
|
+ UidPushModel.objects.filter(userID_id=userID, m_code=m_code, uid_set__uid=uid). \
|
|
|
+ update(**uid_push_update_dict)
|
|
|
+ utko = UidTokenObject()
|
|
|
+ # right
|
|
|
+ utko.generate(data={'uid': uid})
|
|
|
+ detectUrl = "{SERVER_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
+ format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return response.json(0, {'detectUrl': detectUrl})
|
|
|
+ else:
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid)
|
|
|
+ # 判断uid push是否绑定
|
|
|
+ if not uid_set_qs.exists():
|
|
|
+ uid_set_create_dict = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime,
|
|
|
+ 'detect_status': status
|
|
|
+ }
|
|
|
+ # 添加设备配置
|
|
|
+ uid_set_qs = UidSetModel.objects.create(**uid_set_create_dict)
|
|
|
+ # from var_dump import var_dump
|
|
|
+ # var_dump(uid_set_qs)
|
|
|
+ # print(uid_set_qs)
|
|
|
+ uid_set_id = uid_set_qs.id
|
|
|
+ else:
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
+ uid_push_create_dict = {
|
|
|
+ 'uid_set_id': uid_set_id,
|
|
|
+ 'userID_id': userID,
|
|
|
+ 'appBundleId': appBundleId,
|
|
|
+ 'app_type': app_type,
|
|
|
+ 'push_type': push_type,
|
|
|
+ 'token_val': token_val,
|
|
|
+ 'm_code': m_code,
|
|
|
+ 'addTime': nowTime,
|
|
|
+ 'updTime': nowTime
|
|
|
+ }
|
|
|
+ # 绑定设备推送
|
|
|
+ UidPushModel.objects.create(**uid_push_create_dict)
|
|
|
+ utko = UidTokenObject()
|
|
|
+ utko.generate(data={'uid': uid})
|
|
|
+ detectUrl = "{SERVER_DOMAIN}notify/push?uidToken={uidToken}". \
|
|
|
+ format(uidToken=utko.token, SERVER_DOMAIN=SERVER_DOMAIN)
|
|
|
+ return response.json(0, {'detectUrl': detectUrl})
|
|
|
+ else:
|
|
|
+ return response.json(14)
|
|
|
+
|
|
|
def do_update_interval(self, userID, request_dict, response):
|
|
|
uid = request_dict.get('uid', None)
|
|
|
interval = request_dict.get('interval', None)
|
|
|
- # now_time = int(time.time())
|
|
|
- uid_app_qs = UID_App.objects.filter(userID_id=userID, uid=uid)
|
|
|
- if uid_app_qs.exists():
|
|
|
- UID_App.objects.filter(uid=uid).update(interval=int(interval))
|
|
|
- return response.json(0)
|
|
|
+ uid_set_qs = UidSetModel.objects. \
|
|
|
+ filter(uid=uid, uidpushmodel__userID_id=userID)
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_qs.update(interval=int(interval))
|
|
|
else:
|
|
|
return response.json(173)
|
|
|
|
|
@@ -238,51 +315,57 @@ class NotificationView(View):
|
|
|
# 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',
|
|
|
- 'interval')
|
|
|
- if uaqs.exists():
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
-
|
|
|
- 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']
|
|
|
- pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
- if redisObj.get_data(key=pkey):
|
|
|
- res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
- else:
|
|
|
- if ua['interval']:
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
|
|
|
- # ios apns
|
|
|
- if push_type == 0:
|
|
|
- self.do_apns(request_dict, ua, response)
|
|
|
- # android gcm
|
|
|
- elif push_type == 1:
|
|
|
- self.do_gmc(request_dict, ua, response)
|
|
|
- # android jpush
|
|
|
- elif push_type == 2:
|
|
|
- self.do_jpush(request_dict, ua, response)
|
|
|
-
|
|
|
- # 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' or is_st == '2':
|
|
|
- return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
+ uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ uid_set_id = uid_set_qs[0].id
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id).values('token_val', 'app_type',
|
|
|
+ 'appBundleId', 'push_type', 'uid',
|
|
|
+ 'userID_id', 'userID__NickName',
|
|
|
+ 'interval')
|
|
|
+ if uid_set_qs.exists():
|
|
|
+ pass
|
|
|
else:
|
|
|
- # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
- 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)
|
|
|
- ############
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
else:
|
|
|
- return JsonResponse(status=200, data={
|
|
|
- 'code': 404,
|
|
|
- 'msg': 'data is not exist'})
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
+
|
|
|
+ # if uaqs.exists():
|
|
|
+ # redisObj = RedisObject(db=6)
|
|
|
+ #
|
|
|
+ # 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']
|
|
|
+ # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
+ # if redisObj.get_data(key=pkey):
|
|
|
+ # res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
+ # return JsonResponse(status=200, data=res_data)
|
|
|
+ # else:
|
|
|
+ # if ua['interval']:
|
|
|
+ # redisObj.set_data(key=pkey, val=1, expire=ua['interval'])
|
|
|
+ # # ios apns
|
|
|
+ # if push_type == 0:
|
|
|
+ # self.do_apns(request_dict, ua, response)
|
|
|
+ # # android gcm
|
|
|
+ # elif push_type == 1:
|
|
|
+ # self.do_gmc(request_dict, ua, response)
|
|
|
+ # # android jpush
|
|
|
+ # elif push_type == 2:
|
|
|
+ # self.do_jpush(request_dict, ua, response)
|
|
|
+ #
|
|
|
+ # # 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' or is_st == '2':
|
|
|
+ # return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
+ # else:
|
|
|
+ # # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
+ # 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)
|
|
|
|
|
|
def do_jpush(self, request_dict, uaql, response):
|
|
|
event_type = request_dict.get('event_type', None)
|