|
@@ -72,57 +72,73 @@ class NotificationView(View):
|
|
|
except Exception as e:
|
|
|
return JsonResponse(status=200, data={'code': 404, 'msg': 'region is not exist'})
|
|
|
|
|
|
- # print("aaa")
|
|
|
- # return JsonResponse(0,safe=False)
|
|
|
if not all([channel, n_time]):
|
|
|
return JsonResponse(status=200, data={
|
|
|
'code': 444,
|
|
|
'msg': 'param is wrong'})
|
|
|
- if etk:
|
|
|
- eto = ETkObject(etk)
|
|
|
- uid = eto.uid
|
|
|
- if len(uid) != 20 and len(uid) != 14:
|
|
|
- return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
- else:
|
|
|
- utko = UidTokenObject(uidToken)
|
|
|
- uid = utko.UID
|
|
|
- logger.info("当前调用推送接口的uid:")
|
|
|
- logger.info(uid)
|
|
|
- pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
- # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
|
|
|
- ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
- # dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
- is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
- if is_sys_msg is True:
|
|
|
- dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
- else:
|
|
|
- dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
|
|
|
-
|
|
|
- # 判断redisObj.get_data(key=pkey):不为空
|
|
|
- redisObj = RedisObject(db=6)
|
|
|
- have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
|
|
|
- have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
|
|
|
- have_dkey = redisObj.get_data(key=dkey) # 推送类型限制
|
|
|
-
|
|
|
- # 一分钟外,推送开启状态
|
|
|
- detect_med_type = 0 # 0推送旧机制 1存库不推送,2推送存库
|
|
|
- # 暂时注销
|
|
|
- if have_pkey:
|
|
|
- if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- res_data = {'code': 0, 'msg': 'Push once every 10 seconds'}
|
|
|
+ try:
|
|
|
+ if etk:
|
|
|
+ eto = ETkObject(etk)
|
|
|
+ uid = eto.uid
|
|
|
+ if len(uid) != 20 and len(uid) != 14:
|
|
|
+ return JsonResponse(status=200, data={'code': 404, 'msg': 'data is not exist'})
|
|
|
else:
|
|
|
- res_data = {'code': 0, 'msg': 'Push it once a minute'}
|
|
|
+ utko = UidTokenObject(uidToken)
|
|
|
+ uid = utko.UID
|
|
|
+ logger.info("当前调用推送接口的uid:{}".format(uid))
|
|
|
+ pkey = '{uid}_{channel}_{event_type}_ptl'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
+ # ykey = 'MUJ887NLR8K8GBM9111A_redis_qs'.format(uid=uid)
|
|
|
+ ykey = '{uid}_redis_qs'.format(uid=uid)
|
|
|
+ # dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
+ is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
+ if is_sys_msg is True:
|
|
|
+ dkey = '{uid}_{channel}_{event_type}_flag'.format(uid=uid, event_type=event_type, channel=channel)
|
|
|
+ else:
|
|
|
+ dkey = '{uid}_{channel}_flag'.format(uid=uid, channel=channel)
|
|
|
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
+ # 判断redisObj.get_data(key=pkey):不为空
|
|
|
+ redisObj = RedisObject(db=6)
|
|
|
+ have_ykey = redisObj.get_data(key=ykey) # uid_set 数据库缓存
|
|
|
+ have_pkey = redisObj.get_data(key=pkey) # 一分钟限制key
|
|
|
+ have_dkey = redisObj.get_data(key=dkey) # 推送类型限制
|
|
|
+
|
|
|
+ # 一分钟外,推送开启状态
|
|
|
+ detect_med_type = 0 # 0推送旧机制 1存库不推送,2推送存库
|
|
|
+ # 暂时注销
|
|
|
+ if have_pkey:
|
|
|
+ if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
+ res_data = {'code': 0, 'msg': 'Push once every 10 seconds'}
|
|
|
+ else:
|
|
|
+ res_data = {'code': 0, 'msg': 'Push it once a minute'}
|
|
|
|
|
|
- # 数据库读取数据
|
|
|
- if have_ykey:
|
|
|
- redis_list = eval(redisObj.get_data(key=ykey))
|
|
|
- print(have_ykey)
|
|
|
- if not redis_list:
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+
|
|
|
+ # 数据库读取数据
|
|
|
+ if have_ykey:
|
|
|
+ redis_list = eval(redisObj.get_data(key=ykey))
|
|
|
+ print(have_ykey)
|
|
|
+ if not redis_list:
|
|
|
+ # 从数据库查询出来
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
+ values('token_val', 'app_type', 'appBundleId', 'm_code',
|
|
|
+ 'push_type', 'userID_id', 'userID__NickName',
|
|
|
+ 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
+ 'uid_set__channel')
|
|
|
+ print(uid_push_qs)
|
|
|
+ # 新建一个list接收数据
|
|
|
+ redis_list = []
|
|
|
+ # 把数据库数据追加进redis_list
|
|
|
+ for qs in uid_push_qs:
|
|
|
+ redis_list.append(qs)
|
|
|
+ # 修改redis数据,并设置过期时间为10分钟
|
|
|
+ redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
|
|
|
+ if not redis_list:
|
|
|
+ res_data = {'code': 404, 'msg': 'error !'}
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+ else:
|
|
|
# 从数据库查询出来
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid, uid_set__detect_status=1). \
|
|
|
- values('token_val', 'app_type', 'appBundleId', 'm_code',
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
|
|
|
+ values('token_val', 'app_type', 'appBundleId','m_code',
|
|
|
'push_type', 'userID_id', 'userID__NickName',
|
|
|
'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
'uid_set__channel')
|
|
@@ -137,281 +153,199 @@ class NotificationView(View):
|
|
|
if not redis_list:
|
|
|
res_data = {'code': 404, 'msg': 'error !'}
|
|
|
return JsonResponse(status=200, data=res_data)
|
|
|
- else:
|
|
|
- # 从数据库查询出来
|
|
|
- uid_push_qs = UidPushModel.objects.filter(uid_set__uid=uid,uid_set__detect_status=1). \
|
|
|
- values('token_val', 'app_type', 'appBundleId','m_code',
|
|
|
- 'push_type', 'userID_id', 'userID__NickName',
|
|
|
- 'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
|
|
|
- 'uid_set__channel')
|
|
|
- print(uid_push_qs)
|
|
|
- # 新建一个list接收数据
|
|
|
- redis_list = []
|
|
|
- # 把数据库数据追加进redis_list
|
|
|
- for qs in uid_push_qs:
|
|
|
- redis_list.append(qs)
|
|
|
- # 修改redis数据,并设置过期时间为10分钟
|
|
|
- redisObj.set_data(key=ykey, val=str(redis_list), expire=600)
|
|
|
- if not redis_list:
|
|
|
- res_data = {'code': 404, 'msg': 'error !'}
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
- # 此时应该更新一下redis里面的dkey的有效时间
|
|
|
- # detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
- # tmp_channel = redis_list[0]['uid_set__channel']
|
|
|
- # self.do_update_detect_interval(uid, tmp_channel, redisObj, detect_interval)
|
|
|
+ # 此时应该更新一下redis里面的dkey的有效时间
|
|
|
+ # detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
+ # tmp_channel = redis_list[0]['uid_set__channel']
|
|
|
+ # self.do_update_detect_interval(uid, tmp_channel, redisObj, detect_interval)
|
|
|
|
|
|
- if not redis_list:
|
|
|
- print("没有redi_list")
|
|
|
- res_data = {'code': 0, 'msg': 'no redi_list success!'}
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
- logger.info("(当前设备从数据库中获取的所有信息)redis_list:")
|
|
|
- logger.info(redis_list)
|
|
|
- # is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
- nickname = redis_list[0]['uid_set__nickname']
|
|
|
- detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
- detect_group = redis_list[0]['uid_set__detect_group']
|
|
|
- now_time = int(time.time())
|
|
|
- if not nickname:
|
|
|
- nickname = uid
|
|
|
-
|
|
|
- if detect_group is not None:
|
|
|
- if have_dkey:
|
|
|
- detect_med_type = 1 # 1为存库不推送
|
|
|
- else:
|
|
|
- detect_med_type = 2 # 为2的话,既推送,又存库
|
|
|
- # detect_group=0允许全部推送的时候
|
|
|
- if detect_group == '0'or detect_group == '':
|
|
|
- redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
+ if not redis_list:
|
|
|
+ print("没有redi_list")
|
|
|
+ res_data = {'code': 0, 'msg': 'no redi_list success!'}
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+ logger.info("(当前设备从数据库中获取的所有信息)redis_list:")
|
|
|
+ logger.info(redis_list)
|
|
|
+ # is_sys_msg = self.is_sys_msg(int(event_type))
|
|
|
+ nickname = redis_list[0]['uid_set__nickname']
|
|
|
+ detect_interval = redis_list[0]['uid_set__detect_interval']
|
|
|
+ detect_group = redis_list[0]['uid_set__detect_group']
|
|
|
+ now_time = int(time.time())
|
|
|
+ if not nickname:
|
|
|
+ nickname = uid
|
|
|
+
|
|
|
+ if detect_group is not None:
|
|
|
+ if have_dkey:
|
|
|
+ detect_med_type = 1 # 1为存库不推送
|
|
|
else:
|
|
|
- detect_group_list = detect_group.split(',')
|
|
|
- if event_type in detect_group_list:
|
|
|
- if detect_interval < 60:
|
|
|
- detect_interval = 60
|
|
|
+ detect_med_type = 2 # 为2的话,既推送,又存库
|
|
|
+ # detect_group=0允许全部推送的时候
|
|
|
+ if detect_group == '0'or detect_group == '':
|
|
|
redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
- # 改为1秒
|
|
|
+ else:
|
|
|
+ detect_group_list = detect_group.split(',')
|
|
|
+ if event_type in detect_group_list:
|
|
|
+ if detect_interval < 60:
|
|
|
+ detect_interval = 60
|
|
|
+ redisObj.set_data(key=dkey, val=1, expire=detect_interval)
|
|
|
+ # 改为1秒
|
|
|
+ # 如果不是正式
|
|
|
+ if SERVER_TYPE!="Ansjer.formal_settings":
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=10)
|
|
|
+ else:
|
|
|
+ redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
+
|
|
|
+ # 旧模式并且没有pkey,重新创建一个
|
|
|
+ if not detect_group and not have_pkey:
|
|
|
+ # 设置推送时间为60秒一次
|
|
|
# 如果不是正式
|
|
|
- if SERVER_TYPE!="Ansjer.formal_settings":
|
|
|
+ if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
redisObj.set_data(key=pkey, val=1, expire=10)
|
|
|
else:
|
|
|
redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
-
|
|
|
- # 打印have_ykey
|
|
|
- # return JsonResponse(status=200, data={'pkey': 0, 'have_ykey': have_ykey, 'have_pkey': have_pkey, 'have_ykey': have_dkey})
|
|
|
-
|
|
|
- # 旧模式并且没有pkey,重新创建一个
|
|
|
- if not detect_group and not have_pkey:
|
|
|
- # 设置推送时间为60秒一次
|
|
|
- # 如果不是正式
|
|
|
- if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=10)
|
|
|
- else:
|
|
|
- redisObj.set_data(key=pkey, val=1, expire=60)
|
|
|
- # auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
|
|
|
- # bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
|
|
|
- aws_s3_guonei = boto3.client(
|
|
|
- 's3',
|
|
|
- aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
- config=botocore.client.Config(signature_version='s3v4'),
|
|
|
- region_name='cn-northwest-1'
|
|
|
- )
|
|
|
- aws_s3_guowai = boto3.client(
|
|
|
- 's3',
|
|
|
- aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
- aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
- config=botocore.client.Config(signature_version='s3v4'),
|
|
|
- region_name='us-east-1'
|
|
|
- )
|
|
|
- kwag_args = {
|
|
|
- 'uid': uid,
|
|
|
- 'channel': channel,
|
|
|
- 'event_type': event_type,
|
|
|
- 'n_time': n_time,
|
|
|
- # 'appBundleId': appBundleId,
|
|
|
- # 'token_val': token_val,
|
|
|
- # 'msg_title': msg_title,
|
|
|
- # 'msg_text': msg_text
|
|
|
- }
|
|
|
- eq_list = []
|
|
|
- sys_msg_list = []
|
|
|
- userID_ids = []
|
|
|
- do_apns_code = ''
|
|
|
- do_fcm_code = ''
|
|
|
- do_jpush_code = ''
|
|
|
- for up in redis_list:
|
|
|
- push_type = up['push_type']
|
|
|
- appBundleId = up['appBundleId']
|
|
|
- token_val = up['token_val']
|
|
|
- lang = up['lang']
|
|
|
- tz = up['tz']
|
|
|
- if tz is None or tz == '':
|
|
|
- tz = 0
|
|
|
- # 发送标题
|
|
|
- msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
- # 发送内容
|
|
|
- msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
- event_type=event_type)
|
|
|
- kwag_args['appBundleId'] = appBundleId
|
|
|
- kwag_args['token_val'] = token_val
|
|
|
- kwag_args['msg_title'] = msg_title
|
|
|
- kwag_args['msg_text'] = msg_text
|
|
|
- logger.info('推送要的数据:')
|
|
|
- logger.info(kwag_args)
|
|
|
- logger.info(detect_med_type)
|
|
|
- push_server_status = 0
|
|
|
- #推送
|
|
|
- if detect_med_type == 2 or detect_med_type == 0:
|
|
|
- if push_type == 0: # ios apns
|
|
|
- print('do_apns')
|
|
|
- logger.info('do_apns')
|
|
|
- # self.do_apns(**kwag_args)
|
|
|
- do_apns_code = self.do_apns(**kwag_args)
|
|
|
- logger.info("出来do_apns了")
|
|
|
- logger.info(do_apns_code)
|
|
|
- if isinstance(do_apns_code, int):
|
|
|
- push_server_status = do_apns_code
|
|
|
- else:
|
|
|
- push_server_status = 400
|
|
|
- elif push_type == 1: # android gcm
|
|
|
- print('do_fcm')
|
|
|
- do_fcm_code = self.do_fcm(**kwag_args)
|
|
|
- push_server_status = 200
|
|
|
- elif push_type == 2: # android jpush
|
|
|
- print('do_jpush')
|
|
|
- do_jpush_code = self.do_jpush(**kwag_args)
|
|
|
- push_server_status = do_jpush_code
|
|
|
- # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
|
|
|
- if detect_med_type == 1:
|
|
|
- do_apns_code = '只存库不推送'
|
|
|
- do_fcm_code = '只存库不推送'
|
|
|
- do_jpush_code = '只存库不推送'
|
|
|
- # 以下是存库
|
|
|
- userID_id = up["userID_id"]
|
|
|
- int_is_st = int(is_st)
|
|
|
- if userID_id not in userID_ids:
|
|
|
-
|
|
|
- if is_sys_msg:
|
|
|
- sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
- event_type=event_type, is_sys=1)
|
|
|
- sys_msg_list.append(SysMsgModel(
|
|
|
- userID_id=userID_id,
|
|
|
- msg=sys_msg_text,
|
|
|
- addTime=now_time,
|
|
|
- updTime=now_time,
|
|
|
- uid=uid,
|
|
|
- eventType=event_type))
|
|
|
- else:
|
|
|
- eq_list.append(Equipment_Info(
|
|
|
- userID_id=userID_id,
|
|
|
- eventTime=n_time,
|
|
|
- eventType=event_type,
|
|
|
- devUid=uid,
|
|
|
- devNickName=nickname,
|
|
|
- Channel=channel,
|
|
|
- alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
- is_st=int_is_st,
|
|
|
- receiveTime=n_time,
|
|
|
- addTime=now_time,
|
|
|
- storage_location=2
|
|
|
- ))
|
|
|
- userID_ids.append(userID_id)
|
|
|
- if is_sys_msg:
|
|
|
- SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
- else:
|
|
|
- Equipment_Info.objects.bulk_create(eq_list)
|
|
|
-
|
|
|
- logger.info("图片信息上传到数据库了")
|
|
|
- if is_st == '0' or is_st == '2':
|
|
|
- logger.info("进到is_st为0或2")
|
|
|
- print("is_st=0or2")
|
|
|
- for up in redis_list:
|
|
|
- if up['push_type'] == 0: # ios apns
|
|
|
- up['do_apns_code'] = do_apns_code
|
|
|
- elif up['push_type'] == 1: # android gcm
|
|
|
- up['do_fcm_code'] = do_fcm_code
|
|
|
- elif up['push_type'] == 2: # android jpush
|
|
|
- up['do_jpush_code'] = do_jpush_code
|
|
|
- up['test_or_www'] = SERVER_TYPE
|
|
|
- del up['push_type']
|
|
|
- del up['userID_id']
|
|
|
- del up['userID__NickName']
|
|
|
- del up['lang']
|
|
|
- del up['tz']
|
|
|
- del up['uid_set__nickname']
|
|
|
- del up['uid_set__detect_interval']
|
|
|
- del up['uid_set__detect_group']
|
|
|
- logger.info(redis_list)
|
|
|
- logger.info("出来了")
|
|
|
- return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2' ,'re_list':redis_list})
|
|
|
-
|
|
|
- elif is_st == '1':
|
|
|
- logger.info("进到is_st为1")
|
|
|
- print("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)
|
|
|
- thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
|
|
|
- if region == 2: # 2:国内
|
|
|
- response_url = aws_s3_guonei.generate_presigned_url(
|
|
|
- ClientMethod='put_object',
|
|
|
- Params={
|
|
|
- 'Bucket': 'push',
|
|
|
- 'Key': thumbspng
|
|
|
- },
|
|
|
- ExpiresIn=3600
|
|
|
- )
|
|
|
- else: # 1:国外
|
|
|
- response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
- ClientMethod='put_object',
|
|
|
- Params={
|
|
|
- 'Bucket': 'foreignpush',
|
|
|
- 'Key': thumbspng
|
|
|
- },
|
|
|
- ExpiresIn=3600
|
|
|
- )
|
|
|
- logger.info("成功生成上传签名url了")
|
|
|
+ aws_s3_guonei = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[0],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='cn-northwest-1'
|
|
|
+ )
|
|
|
+ aws_s3_guowai = boto3.client(
|
|
|
+ 's3',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
+ config=botocore.client.Config(signature_version='s3v4'),
|
|
|
+ region_name='us-east-1'
|
|
|
+ )
|
|
|
+ kwag_args = {
|
|
|
+ 'uid': uid,
|
|
|
+ 'channel': channel,
|
|
|
+ 'event_type': event_type,
|
|
|
+ 'n_time': n_time,
|
|
|
+ # 'appBundleId': appBundleId,
|
|
|
+ # 'token_val': token_val,
|
|
|
+ # 'msg_title': msg_title,
|
|
|
+ # 'msg_text': msg_text
|
|
|
+ }
|
|
|
+ eq_list = []
|
|
|
+ sys_msg_list = []
|
|
|
+ userID_ids = []
|
|
|
+ do_apns_code = ''
|
|
|
+ do_fcm_code = ''
|
|
|
+ do_jpush_code = ''
|
|
|
for up in redis_list:
|
|
|
- up['do_apns_code'] = do_apns_code
|
|
|
- up['do_fcm_code'] = do_fcm_code
|
|
|
- up['do_jpush_code'] = do_jpush_code
|
|
|
- up['test_or_www'] = SERVER_TYPE
|
|
|
- del up['push_type']
|
|
|
- del up['userID_id']
|
|
|
- del up['userID__NickName']
|
|
|
- del up['lang']
|
|
|
- del up['tz']
|
|
|
- del up['uid_set__nickname']
|
|
|
- del up['uid_set__detect_interval']
|
|
|
- del up['uid_set__detect_group']
|
|
|
- # 不是正式服务器
|
|
|
- # response_url = response_url[:4] + response_url[5:]
|
|
|
- if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- # res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
|
|
|
- res_data = {'code': 0, 'img_push': response_url, 'msg': 'success', 're_list': redis_list}
|
|
|
+ push_type = up['push_type']
|
|
|
+ appBundleId = up['appBundleId']
|
|
|
+ token_val = up['token_val']
|
|
|
+ lang = up['lang']
|
|
|
+ tz = up['tz']
|
|
|
+ if tz is None or tz == '':
|
|
|
+ tz = 0
|
|
|
+ # 发送标题
|
|
|
+ msg_title = self.get_msg_title(appBundleId=appBundleId, nickname=nickname)
|
|
|
+ # 发送内容
|
|
|
+ msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
+ event_type=event_type)
|
|
|
+ kwag_args['appBundleId'] = appBundleId
|
|
|
+ kwag_args['token_val'] = token_val
|
|
|
+ kwag_args['msg_title'] = msg_title
|
|
|
+ kwag_args['msg_text'] = msg_text
|
|
|
+ logger.info('推送要的数据:')
|
|
|
+ logger.info(kwag_args)
|
|
|
+ logger.info(detect_med_type)
|
|
|
+ push_server_status = 0
|
|
|
+ #推送
|
|
|
+ if detect_med_type == 2 or detect_med_type == 0:
|
|
|
+ if push_type == 0: # ios apns
|
|
|
+ print('do_apns')
|
|
|
+ logger.info('do_apns')
|
|
|
+ # self.do_apns(**kwag_args)
|
|
|
+ do_apns_code = self.do_apns(**kwag_args)
|
|
|
+ logger.info("出来do_apns了")
|
|
|
+ logger.info(do_apns_code)
|
|
|
+ if isinstance(do_apns_code, int):
|
|
|
+ push_server_status = do_apns_code
|
|
|
+ else:
|
|
|
+ push_server_status = 400
|
|
|
+ elif push_type == 1: # android gcm
|
|
|
+ print('do_fcm')
|
|
|
+ do_fcm_code = self.do_fcm(**kwag_args)
|
|
|
+ push_server_status = 200
|
|
|
+ elif push_type == 2: # android jpush
|
|
|
+ print('do_jpush')
|
|
|
+ do_jpush_code = self.do_jpush(**kwag_args)
|
|
|
+ push_server_status = do_jpush_code
|
|
|
+ # return JsonResponse(status=200, data={'code': 0, '状态:': self.do_jpush(**kwag_args)})
|
|
|
+ if detect_med_type == 1:
|
|
|
+ do_apns_code = '只存库不推送'
|
|
|
+ do_fcm_code = '只存库不推送'
|
|
|
+ do_jpush_code = '只存库不推送'
|
|
|
+ # 以下是存库
|
|
|
+ userID_id = up["userID_id"]
|
|
|
+ int_is_st = int(is_st)
|
|
|
+ if userID_id not in userID_ids:
|
|
|
+
|
|
|
+ if is_sys_msg:
|
|
|
+ sys_msg_text = self.get_msg_text(channel=channel, n_time=n_time, lang=lang, tz=tz,
|
|
|
+ event_type=event_type, is_sys=1)
|
|
|
+ sys_msg_list.append(SysMsgModel(
|
|
|
+ userID_id=userID_id,
|
|
|
+ msg=sys_msg_text,
|
|
|
+ addTime=now_time,
|
|
|
+ updTime=now_time,
|
|
|
+ uid=uid,
|
|
|
+ eventType=event_type))
|
|
|
+ else:
|
|
|
+ eq_list.append(Equipment_Info(
|
|
|
+ userID_id=userID_id,
|
|
|
+ eventTime=n_time,
|
|
|
+ eventType=event_type,
|
|
|
+ devUid=uid,
|
|
|
+ devNickName=nickname,
|
|
|
+ Channel=channel,
|
|
|
+ alarm='Motion \tChannel:{channel}'.format(channel=channel),
|
|
|
+ is_st=int_is_st,
|
|
|
+ receiveTime=n_time,
|
|
|
+ addTime=now_time,
|
|
|
+ storage_location=2
|
|
|
+ ))
|
|
|
+ userID_ids.append(userID_id)
|
|
|
+ if is_sys_msg:
|
|
|
+ SysMsgModel.objects.bulk_create(sys_msg_list)
|
|
|
else:
|
|
|
- # 是正式服务器的时候
|
|
|
- # res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
|
- res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
|
|
|
- logger.info(res_data)
|
|
|
- logger.info("出来了")
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
-
|
|
|
- elif is_st == '3':
|
|
|
- logger.info("进到is_st为3")
|
|
|
- print("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)
|
|
|
+ Equipment_Info.objects.bulk_create(eq_list)
|
|
|
+
|
|
|
+ logger.info("图片信息上传到数据库了")
|
|
|
+ if is_st == '0' or is_st == '2':
|
|
|
+ logger.info("进到is_st为0或2")
|
|
|
+ print("is_st=0or2")
|
|
|
+ for up in redis_list:
|
|
|
+ if up['push_type'] == 0: # ios apns
|
|
|
+ up['do_apns_code'] = do_apns_code
|
|
|
+ elif up['push_type'] == 1: # android gcm
|
|
|
+ up['do_fcm_code'] = do_fcm_code
|
|
|
+ elif up['push_type'] == 2: # android jpush
|
|
|
+ up['do_jpush_code'] = do_jpush_code
|
|
|
+ up['test_or_www'] = SERVER_TYPE
|
|
|
+ del up['push_type']
|
|
|
+ del up['userID_id']
|
|
|
+ del up['userID__NickName']
|
|
|
+ del up['lang']
|
|
|
+ del up['tz']
|
|
|
+ del up['uid_set__nickname']
|
|
|
+ del up['uid_set__detect_interval']
|
|
|
+ del up['uid_set__detect_group']
|
|
|
+ logger.info(redis_list)
|
|
|
+ logger.info("出来了")
|
|
|
+ return JsonResponse(status=200, data={'code': 0, 'msg': 'success 0 or 2' ,'re_list':redis_list})
|
|
|
+
|
|
|
+ elif is_st == '1':
|
|
|
+ logger.info("进到is_st为1")
|
|
|
+ print("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)
|
|
|
-
|
|
|
- thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
|
|
|
- format(uid=uid, channel=channel, filename=n_time, st=i)
|
|
|
+ thumbspng = '{uid}/{channel}/{filename}.jpeg'.format(uid=uid, channel=channel, filename=n_time)
|
|
|
if region == 2: # 2:国内
|
|
|
response_url = aws_s3_guonei.generate_presigned_url(
|
|
|
ClientMethod='put_object',
|
|
@@ -430,36 +364,97 @@ class NotificationView(View):
|
|
|
},
|
|
|
ExpiresIn=3600
|
|
|
)
|
|
|
- # response_url = response_url[:4] + response_url[5:]
|
|
|
- img_url_list.append(response_url)
|
|
|
logger.info("成功生成上传签名url了")
|
|
|
+ for up in redis_list:
|
|
|
+ up['do_apns_code'] = do_apns_code
|
|
|
+ up['do_fcm_code'] = do_fcm_code
|
|
|
+ up['do_jpush_code'] = do_jpush_code
|
|
|
+ up['test_or_www'] = SERVER_TYPE
|
|
|
+ del up['push_type']
|
|
|
+ del up['userID_id']
|
|
|
+ del up['userID__NickName']
|
|
|
+ del up['lang']
|
|
|
+ del up['tz']
|
|
|
+ del up['uid_set__nickname']
|
|
|
+ del up['uid_set__detect_interval']
|
|
|
+ del up['uid_set__detect_group']
|
|
|
+ # 不是正式服务器
|
|
|
+ # response_url = response_url[:4] + response_url[5:]
|
|
|
+ if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
+ # res_data = {'code': 0, 'img_push': url, 'msg': 'success', 're_list': redis_list}
|
|
|
+ res_data = {'code': 0, 'img_push': response_url, 'msg': 'success', 're_list': redis_list}
|
|
|
+ else:
|
|
|
+ # 是正式服务器的时候
|
|
|
+ # res_data = {'code': 0, 'img_push': url, 'msg': 'success'}
|
|
|
+ res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
|
|
|
+ logger.info(res_data)
|
|
|
+ logger.info("出来了")
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
|
|
- # img_url_list.append(url)
|
|
|
+ elif is_st == '3':
|
|
|
+ logger.info("进到is_st为3")
|
|
|
+ print("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)
|
|
|
|
|
|
- for up in redis_list:
|
|
|
- up['do_apns_code'] = do_apns_code
|
|
|
- up['do_fcm_code'] = do_fcm_code
|
|
|
- up['do_jpush_code'] = do_jpush_code
|
|
|
- up['test_or_www'] = SERVER_TYPE
|
|
|
- del up['push_type']
|
|
|
- del up['userID_id']
|
|
|
- del up['userID__NickName']
|
|
|
- del up['lang']
|
|
|
- del up['tz']
|
|
|
- del up['uid_set__nickname']
|
|
|
- del up['uid_set__detect_interval']
|
|
|
- del up['uid_set__detect_group']
|
|
|
-
|
|
|
- # 不是正式服务器
|
|
|
- if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
- res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
|
|
|
- else:
|
|
|
- # 是正式服务器的时候
|
|
|
- res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
|
|
|
- logger.info(res_data)
|
|
|
- logger.info("出来了")
|
|
|
- return JsonResponse(status=200, data=res_data)
|
|
|
+ thumbspng = '{uid}/{channel}/{filename}_{st}.jpeg'. \
|
|
|
+ format(uid=uid, channel=channel, filename=n_time, st=i)
|
|
|
+ if region == 2: # 2:国内
|
|
|
+ response_url = aws_s3_guonei.generate_presigned_url(
|
|
|
+ ClientMethod='put_object',
|
|
|
+ Params={
|
|
|
+ 'Bucket': 'push',
|
|
|
+ 'Key': thumbspng
|
|
|
+ },
|
|
|
+ ExpiresIn=3600
|
|
|
+ )
|
|
|
+ else: # 1:国外
|
|
|
+ response_url = aws_s3_guowai.generate_presigned_url(
|
|
|
+ ClientMethod='put_object',
|
|
|
+ Params={
|
|
|
+ 'Bucket': 'foreignpush',
|
|
|
+ 'Key': thumbspng
|
|
|
+ },
|
|
|
+ ExpiresIn=3600
|
|
|
+ )
|
|
|
+ # response_url = response_url[:4] + response_url[5:]
|
|
|
+ img_url_list.append(response_url)
|
|
|
+ logger.info("成功生成上传签名url了")
|
|
|
|
|
|
+ # img_url_list.append(url)
|
|
|
+
|
|
|
+ for up in redis_list:
|
|
|
+ up['do_apns_code'] = do_apns_code
|
|
|
+ up['do_fcm_code'] = do_fcm_code
|
|
|
+ up['do_jpush_code'] = do_jpush_code
|
|
|
+ up['test_or_www'] = SERVER_TYPE
|
|
|
+ del up['push_type']
|
|
|
+ del up['userID_id']
|
|
|
+ del up['userID__NickName']
|
|
|
+ del up['lang']
|
|
|
+ del up['tz']
|
|
|
+ del up['uid_set__nickname']
|
|
|
+ del up['uid_set__detect_interval']
|
|
|
+ del up['uid_set__detect_group']
|
|
|
+
|
|
|
+ # 不是正式服务器
|
|
|
+ if SERVER_TYPE != "Ansjer.formal_settings":
|
|
|
+ res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3', 're_list': redis_list}
|
|
|
+ else:
|
|
|
+ # 是正式服务器的时候
|
|
|
+ res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
|
|
|
+ logger.info(res_data)
|
|
|
+ logger.info("出来了")
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
+ except Exception as e:
|
|
|
+ logger.info(e)
|
|
|
+ return JsonResponse(status=500)
|
|
|
|
|
|
def get_msg_title(self, appBundleId, nickname):
|
|
|
package_title_config = {
|
|
@@ -480,6 +475,7 @@ class NotificationView(View):
|
|
|
else:
|
|
|
return nickname
|
|
|
|
|
|
+
|
|
|
def is_sys_msg(self, event_type):
|
|
|
event_type_list = [702, 703, 704]
|
|
|
if event_type in event_type_list:
|