|
@@ -42,10 +42,10 @@ class NotificationView(View):
|
|
# operation = kwargs.get('operation')
|
|
# operation = kwargs.get('operation')
|
|
return self.validation(request.GET)
|
|
return self.validation(request.GET)
|
|
|
|
|
|
- def post(self, request, *args, **kwargs):
|
|
|
|
- request.encoding = 'utf-8'
|
|
|
|
- # operation = kwargs.get('operation')
|
|
|
|
- return self.validation(request.POST)
|
|
|
|
|
|
+ # def post(self, request, *args, **kwargs):
|
|
|
|
+ # request.encoding = 'utf-8'
|
|
|
|
+ # # operation = kwargs.get('operation')
|
|
|
|
+ # return self.validation(request.POST)
|
|
|
|
|
|
def validation11(self, request_dict):
|
|
def validation11(self, request_dict):
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
@@ -71,9 +71,12 @@ class NotificationView(View):
|
|
# 设置推送间隔60秒一次
|
|
# 设置推送间隔60秒一次
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
uid_set_qs = UidSetModel.objects.filter(uid=uid, detect_status=1)
|
|
|
|
+ # redisObj.set_data(key=pkey, val=list[0], expire=600)
|
|
|
|
+ return response.json(0)
|
|
if uid_set_qs.exists():
|
|
if uid_set_qs.exists():
|
|
uid_set_id = uid_set_qs[0].id
|
|
uid_set_id = uid_set_qs[0].id
|
|
nickname = uid_set_qs[0].nickname
|
|
nickname = uid_set_qs[0].nickname
|
|
|
|
+ # if not is ==none
|
|
if not nickname:
|
|
if not nickname:
|
|
nickname = uid
|
|
nickname = uid
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
@@ -136,31 +139,46 @@ class NotificationView(View):
|
|
'code': 444,
|
|
'code': 444,
|
|
'msg': 'param is wrong'})
|
|
'msg': 'param is wrong'})
|
|
# return response.json(444)
|
|
# return response.json(444)
|
|
|
|
+ # 执行下面utko窗口会输出{'uid',""}
|
|
utko = UidTokenObject(uidToken)
|
|
utko = UidTokenObject(uidToken)
|
|
uid = utko.UID
|
|
uid = utko.UID
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
- pkey = '{uid}_ptl'.format(uid=uid)
|
|
|
|
|
|
+ pkey = '{uid}_pptl'.format(uid=uid)
|
|
|
|
+ # 判断redisObj.get_data(key=pkey):不为空
|
|
if redisObj.get_data(key=pkey):
|
|
if redisObj.get_data(key=pkey):
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
+ # 查询key对应的value
|
|
|
|
+ res = redisObj.get_data(key=pkey)
|
|
|
|
+ # redis中的字符串转回list
|
|
|
|
+ redis_list = eval(res)
|
|
else:
|
|
else:
|
|
- # 设置推送间隔60秒一次
|
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
|
- # uid_set_id = uid_set_qs[0].id
|
|
|
|
-
|
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
|
|
|
|
- values('token_val', 'app_type', 'appBundleId',
|
|
|
|
- 'push_type', 'userID_id', 'userID__NickName',
|
|
|
|
- 'lang', 'tz','uid_set__nickname')
|
|
|
|
-
|
|
|
|
- if uid_push_qs.exists():
|
|
|
|
- nickname = uid_push_qs[0]['uid_set__nickname']
|
|
|
|
|
|
+ # 从数据库查询出来
|
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid). \
|
|
|
|
+ values('token_val', 'app_type', 'appBundleId',
|
|
|
|
+ 'push_type', 'userID_id', 'userID__NickName',
|
|
|
|
+ 'lang', 'tz', 'uid_set__nickname')
|
|
|
|
+ # 新建一个list接收数据
|
|
|
|
+ uid_push_qs_list = []
|
|
|
|
+ print("从数据库查到数据")
|
|
|
|
+ # 把数据库数据追加进uid_push_qs_list
|
|
|
|
+ for qs in uid_push_qs:
|
|
|
|
+ uid_push_qs_list.append(qs)
|
|
|
|
+ print(str(uid_push_qs_list))
|
|
|
|
+ # 修改redis数据,并设置过期时间为10分钟
|
|
|
|
+ redisObj.set_data(key=pkey, val=str(uid_push_qs_list), expire=600)
|
|
|
|
+ # 查询key对应的value
|
|
|
|
+ res = redisObj.get_data(key=pkey)
|
|
|
|
+ # 把redis中的字符串转回list
|
|
|
|
+ redis_list = eval(res)
|
|
|
|
+ # return JsonResponse(status=200, data={'code': 0, 'msg': "Data has been saved in redis"})
|
|
|
|
+ if redis_list:
|
|
|
|
+ nickname = redis_list[0]['uid_set__nickname']
|
|
if not nickname:
|
|
if not nickname:
|
|
nickname = uid
|
|
nickname = uid
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
- for up in uid_push_qs:
|
|
|
|
|
|
+ for up in redis_list:
|
|
push_type = up['push_type']
|
|
push_type = up['push_type']
|
|
# ios apns
|
|
# ios apns
|
|
print(push_type)
|
|
print(push_type)
|
|
@@ -175,7 +193,7 @@ class NotificationView(View):
|
|
self.do_jpush(request_dict, up, response, uid, channel, nickname)
|
|
self.do_jpush(request_dict, up, response, uid, channel, nickname)
|
|
# self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
# self.do_save_equipment_info(ua, n_time, channel, event_type, is_st)
|
|
# 需求不一样,所以这么做的
|
|
# 需求不一样,所以这么做的
|
|
- self.do_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
|
|
|
|
|
|
+ self.do_bulk_create_info(redis_list, n_time, channel, event_type, is_st, uid)
|
|
if is_st == '0' or is_st == '2':
|
|
if is_st == '0' or is_st == '2':
|
|
return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
elif is_st == '1':
|
|
elif is_st == '1':
|
|
@@ -200,6 +218,7 @@ class NotificationView(View):
|
|
else:
|
|
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'})
|
|
|
|
|
|
|
|
+######
|
|
def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
|
|
def do_jpush(self, request_dict, uaql, response, uid, channel, nickname):
|
|
event_type = request_dict.get('event_type', None)
|
|
event_type = request_dict.get('event_type', None)
|
|
n_time = request_dict.get('n_time', None)
|
|
n_time = request_dict.get('n_time', None)
|
|
@@ -307,7 +326,6 @@ class NotificationView(View):
|
|
send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
|
|
send_text = self.get_send_text(channel=channel, n_time=n_time, lang=lang, tz=tz, event_type=event_type)
|
|
try:
|
|
try:
|
|
print('---')
|
|
print('---')
|
|
-
|
|
|
|
cli = apns2.APNSClient(mode=APNS_MODE,
|
|
cli = apns2.APNSClient(mode=APNS_MODE,
|
|
client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
client_cert=os.path.join(BASE_DIR, APNS_CONFIG[appBundleId]['pem_path']))
|
|
# password=APNS_CONFIG[appBundleId]['password'])
|
|
# password=APNS_CONFIG[appBundleId]['password'])
|
|
@@ -387,7 +405,6 @@ class PushNotificationView(View):
|
|
redisObj = RedisObject(db=6)
|
|
redisObj = RedisObject(db=6)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
pkey = '{uid}_ptl'.format(uid=uid)
|
|
- # 推送时间限制
|
|
|
|
if redisObj.get_data(key=pkey):
|
|
if redisObj.get_data(key=pkey):
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
return JsonResponse(status=200, data=res_data)
|
|
return JsonResponse(status=200, data=res_data)
|