|
@@ -17,7 +17,7 @@ import time
|
|
import apns2
|
|
import apns2
|
|
import jpush as jpush
|
|
import jpush as jpush
|
|
import oss2
|
|
import oss2
|
|
-from django.http import JsonResponse
|
|
|
|
|
|
+from django.http import JsonResponse, HttpResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
from pyfcm import FCMNotification
|
|
from pyfcm import FCMNotification
|
|
from AnsjerPush.config import SERVER_TYPE, JPUSH_CODE, APNS_CODE, APP_TYPE
|
|
from AnsjerPush.config import SERVER_TYPE, JPUSH_CODE, APNS_CODE, APP_TYPE
|
|
@@ -28,6 +28,7 @@ from Object.ETkObject import ETkObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
from Object.UidTokenObject import UidTokenObject
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
+import json
|
|
|
|
|
|
'''
|
|
'''
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
|
|
@@ -40,13 +41,13 @@ class NotificationView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
def get(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
- return self.validation(request.GET)
|
|
|
|
|
|
+ return self.validation(request.GET, 0)
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
def post(self, request, *args, **kwargs):
|
|
request.encoding = 'utf-8'
|
|
request.encoding = 'utf-8'
|
|
- return self.validation(request.POST)
|
|
|
|
|
|
+ return self.validation(request.POST, 1)
|
|
|
|
|
|
- def validation(self, request_dict):
|
|
|
|
|
|
+ def validation(self, request_dict, request_type):
|
|
uidToken = request_dict.get('uidToken', None)
|
|
uidToken = request_dict.get('uidToken', None)
|
|
etk = request_dict.get('etk', None)
|
|
etk = request_dict.get('etk', None)
|
|
channel = request_dict.get('channel', '1')
|
|
channel = request_dict.get('channel', '1')
|
|
@@ -95,7 +96,8 @@ class NotificationView(View):
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code',
|
|
values('token_val', 'app_type', 'appBundleId', 'm_code',
|
|
'push_type', 'userID_id', 'userID__NickName', 'userID__username',
|
|
'push_type', 'userID_id', 'userID__NickName', 'userID__username',
|
|
- 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group')
|
|
|
|
|
|
+ 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
|
+ 'uid_set__channel')
|
|
# 新建一个list接收数据
|
|
# 新建一个list接收数据
|
|
redis_list = []
|
|
redis_list = []
|
|
# 把数据库数据追加进redis_list
|
|
# 把数据库数据追加进redis_list
|
|
@@ -107,6 +109,12 @@ class NotificationView(View):
|
|
res_data = {'code': 404, 'msg': 'error !'}
|
|
res_data = {'code': 404, 'msg': 'error !'}
|
|
return JsonResponse(status=200, data=res_data)
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
|
|
+ # 此时应该更新一下redis里面的dkey的有效时间
|
|
|
|
+ detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
|
+ channel = redis_list[0]['uid_set__channel']
|
|
|
|
+ self.do_update_detect_interval(uid, channel, redisObj, detect_interval)
|
|
|
|
+
|
|
|
|
+
|
|
if not redis_list:
|
|
if not redis_list:
|
|
print("没有redi_list")
|
|
print("没有redi_list")
|
|
res_data = {'code': 0, 'msg': 'no redi_list success!'}
|
|
res_data = {'code': 0, 'msg': 'no redi_list success!'}
|
|
@@ -119,6 +127,9 @@ class NotificationView(View):
|
|
now_time = int(time.time())
|
|
now_time = int(time.time())
|
|
if not nickname:
|
|
if not nickname:
|
|
nickname = uid
|
|
nickname = uid
|
|
|
|
+ print('detect_group')
|
|
|
|
+ print(detect_group)
|
|
|
|
+ print(detect_interval)
|
|
if detect_group:
|
|
if detect_group:
|
|
if have_dkey:
|
|
if have_dkey:
|
|
detect_med_type = 1 # 1为存库不推送
|
|
detect_med_type = 1 # 1为存库不推送
|
|
@@ -284,7 +295,14 @@ class NotificationView(View):
|
|
del up['uid_set__nickname']
|
|
del up['uid_set__nickname']
|
|
del up['uid_set__detect_interval']
|
|
del up['uid_set__detect_interval']
|
|
del up['uid_set__detect_group']
|
|
del up['uid_set__detect_group']
|
|
- return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2' ,'re_list':redis_list})
|
|
|
|
|
|
+
|
|
|
|
+ if request_type == 0:
|
|
|
|
+ data = ""
|
|
|
|
+ for up in redis_list:
|
|
|
|
+ data += ("<p>" + repr(up) + "</p>")
|
|
|
|
+ return HttpResponse(repr(data))
|
|
|
|
+ else:
|
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2', 're_list': redis_list})
|
|
|
|
|
|
elif is_st == '1':
|
|
elif is_st == '1':
|
|
print("is_st=1")
|
|
print("is_st=1")
|
|
@@ -503,6 +521,25 @@ class NotificationView(View):
|
|
print("getJPushReport")
|
|
print("getJPushReport")
|
|
print(res)
|
|
print(res)
|
|
|
|
|
|
|
|
+ def do_update_detect_interval(self, uid, channel, redisObject, detect_interval):
|
|
|
|
+ if channel == 0:
|
|
|
|
+ channel = 17
|
|
|
|
+ else:
|
|
|
|
+ channel += 1
|
|
|
|
+ for i in range(1, channel):
|
|
|
|
+ tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=51, channel=i)
|
|
|
|
+ if tmpDKey is not False:
|
|
|
|
+ llt = redisObject.get_ttl(tmpDKey)
|
|
|
|
+ if llt > detect_interval:
|
|
|
|
+ redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
|
|
|
|
+
|
|
|
|
+ tmpDKey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=54, channel=i)
|
|
|
|
+ if tmpDKey is not False:
|
|
|
|
+ llt = redisObject.get_ttl(tmpDKey)
|
|
|
|
+ if llt > detect_interval:
|
|
|
|
+ redisObject.set_data(key=tmpDKey, val=1, expire=detect_interval)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
# http://test.dvema.com/detect/add?uidToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJQMldOR0pSRDJFSEE1RVU5MTExQSJ9.xOCI5lerk8JOs5OcAzunrKCfCrtuPIZ3AnkMmnd-bPY&n_time=1526845794&channel=1&event_type=51&is_st=0
|
|
# 移动侦测接口
|
|
# 移动侦测接口
|