|
@@ -48,87 +48,6 @@ class NotificationView(View):
|
|
|
# # operation = kwargs.get('operation')
|
|
|
# return self.validation(request.POST)
|
|
|
|
|
|
- def validation(self, request_dict):
|
|
|
- response = ResponseObject()
|
|
|
- uidToken = request_dict.get('uidToken', None)
|
|
|
- etk = request_dict.get('etk', None)
|
|
|
- channel = request_dict.get('channel', '1')
|
|
|
- n_time = request_dict.get('n_time', None)
|
|
|
- event_type = request_dict.get('event_type', None)
|
|
|
- is_st = request_dict.get('is_st', None)
|
|
|
- if not all([channel, n_time]):
|
|
|
- return JsonResponse(status=200, data={
|
|
|
- 'code': 444,
|
|
|
- 'msg': 'param is wrong'})
|
|
|
- # return response.json(444)
|
|
|
- utko = UidTokenObject(uidToken)
|
|
|
- uid = utko.UID
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
- # pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
- pkey = '{uid}_ptl'.format(uid=uid)
|
|
|
- if redisObj.get_data(key=pkey):
|
|
|
- res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
- else:
|
|
|
- # 设置推送间隔60秒一次
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
- 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():
|
|
|
- uid_set_id = uid_set_qs[0].id
|
|
|
- nickname = uid_set_qs[0].nickname
|
|
|
- # if not is ==none
|
|
|
- if not nickname:
|
|
|
- nickname = uid
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__id=uid_set_id). \
|
|
|
- values('token_val', 'app_type', 'appBundleId', 'push_type', 'userID_id', 'userID__NickName', 'lang',
|
|
|
- 'tz')
|
|
|
- if uid_push_qs.exists():
|
|
|
- auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
- for up in uid_push_qs:
|
|
|
- push_type = up['push_type']
|
|
|
- # ios apns
|
|
|
- print(push_type)
|
|
|
- if push_type == 0:
|
|
|
- self.do_apns(request_dict, up, response, uid, channel, nickname)
|
|
|
- # android gcm
|
|
|
- elif push_type == 1:
|
|
|
- self.do_fcm(request_dict, up, response, uid, channel, nickname)
|
|
|
- # self.do_gmc(request_dict, up, response, uid, channel,nickname)
|
|
|
- # android jpush
|
|
|
- elif push_type == 2:
|
|
|
- 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_bulk_create_info(uid_push_qs, n_time, channel, event_type, is_st, uid)
|
|
|
- if is_st == '0' or is_st == '2':
|
|
|
- return JsonResponse(status=200, data={'code': 0, 'msg': 'success'})
|
|
|
- elif is_st == '1':
|
|
|
- # 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)
|
|
|
- elif is_st == '3':
|
|
|
- # 人形检测带动图
|
|
|
- # Endpoint以杭州为例,其它Region请按实际情况填写。
|
|
|
- img_url_list = []
|
|
|
- for i in range(int(is_st)):
|
|
|
- obj = '{uid}/{channel}/{filename}_{st}.jpeg'. \
|
|
|
- format(uid=uid, channel=channel, filename=n_time, st=i)
|
|
|
- # 设置此签名URL在60秒内有效。
|
|
|
- url = bucket.sign_url('PUT', obj, 7200)
|
|
|
- img_url_list.append(url)
|
|
|
- res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success'}
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
- else:
|
|
|
- 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'})
|
|
|
-
|
|
|
def validation(self, request_dict):
|
|
|
response = ResponseObject()
|
|
|
uidToken = request_dict.get('uidToken', None)
|
|
@@ -146,34 +65,28 @@ class NotificationView(View):
|
|
|
uid = utko.UID
|
|
|
redisObj = RedisObject(db=6)
|
|
|
# pkey = '{uid}_{channel}_ptl'.format(uid=uid, channel=channel)
|
|
|
- pkey = '{uid}_pptl'.format(uid=uid)
|
|
|
+ pkey = '{uid}_ptl'.format(uid=uid)
|
|
|
+ ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
# 判断redisObj.get_data(key=pkey):不为空
|
|
|
if redisObj.get_data(key=pkey):
|
|
|
res_data = {'code': 0, 'msg': 'success,!'}
|
|
|
- # 查询key对应的value
|
|
|
- res = redisObj.get_data(key=pkey)
|
|
|
- # redis中的字符串转回list
|
|
|
- redis_list = eval(res)
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
else:
|
|
|
+ # 设置推送时间为60秒一次
|
|
|
+ redisObj.set_data(key=pkey,val=1,expire=60)
|
|
|
+ print("从数据库查到数据")
|
|
|
# 从数据库查询出来
|
|
|
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
|
|
|
+ redis_list = []
|
|
|
+ # 把数据库数据追加进redis_list
|
|
|
for qs in uid_push_qs:
|
|
|
- uid_push_qs_list.append(qs)
|
|
|
- print(str(uid_push_qs_list))
|
|
|
+ redis_list.append(qs)
|
|
|
# 修改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"})
|
|
|
+ redisObj.set_data(key=ykey, val=str(redis_list), expire=60)
|
|
|
if redis_list:
|
|
|
nickname = redis_list[0]['uid_set__nickname']
|
|
|
if not nickname:
|
|
@@ -183,7 +96,6 @@ class NotificationView(View):
|
|
|
for up in redis_list:
|
|
|
push_type = up['push_type']
|
|
|
# ios apns
|
|
|
- print(push_type)
|
|
|
if push_type == 0:
|
|
|
self.do_apns(request_dict, up, response, uid, channel, nickname)
|
|
|
# android gcm
|