|
@@ -6,7 +6,7 @@ import oss2
|
|
from django.http import JsonResponse
|
|
from django.http import JsonResponse
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
|
|
|
|
-from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, CONFIG_US, CONFIG_EUR, CONFIG_TEST
|
|
|
|
|
|
+from AnsjerPush.config import CONFIG_INFO, CONFIG_CN
|
|
from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Service.DevicePushService import DevicePushService
|
|
from Service.DevicePushService import DevicePushService
|
|
@@ -52,7 +52,6 @@ class NotificationView(View):
|
|
|
|
|
|
V1_PUSH_LOGGER.info('旧移动侦测接口uid:{},时间戳:{},事件类型:{}'.format(uid, n_time, event_type))
|
|
V1_PUSH_LOGGER.info('旧移动侦测接口uid:{},时间戳:{},事件类型:{}'.format(uid, n_time, event_type))
|
|
|
|
|
|
- is_st = int(is_st)
|
|
|
|
event_type = int(event_type)
|
|
event_type = int(event_type)
|
|
pkey = '{}_{}_{}_ptl'.format(uid, event_type, channel)
|
|
pkey = '{}_{}_{}_ptl'.format(uid, event_type, channel)
|
|
ykey = '{}_redis_qs'.format(uid)
|
|
ykey = '{}_redis_qs'.format(uid)
|
|
@@ -116,18 +115,6 @@ class NotificationView(View):
|
|
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')
|
|
|
|
|
|
- # 对象存储区域
|
|
|
|
- # region: 国外(1), 国内(2)
|
|
|
|
- # 测试/国内: 阿里云(1), 美洲: oci凤凰城(3), 欧洲: oci伦敦(4)
|
|
|
|
- region = 1
|
|
|
|
- if CONFIG_INFO == CONFIG_US or CONFIG_INFO == CONFIG_TEST:
|
|
|
|
- storage_location = 3
|
|
|
|
- elif CONFIG_INFO == CONFIG_EUR:
|
|
|
|
- storage_location = 4
|
|
|
|
- else:
|
|
|
|
- region = 2
|
|
|
|
- storage_location = 1
|
|
|
|
-
|
|
|
|
# 推送相关参数
|
|
# 推送相关参数
|
|
push_kwargs = {
|
|
push_kwargs = {
|
|
'uid': uid,
|
|
'uid': uid,
|
|
@@ -135,13 +122,11 @@ class NotificationView(View):
|
|
'event_type': event_type,
|
|
'event_type': event_type,
|
|
'n_time': n_time,
|
|
'n_time': n_time,
|
|
}
|
|
}
|
|
- params = {
|
|
|
|
- 'nickname': nickname, 'uid': uid, 'push_kwargs': push_kwargs, 'is_st': is_st, 'is_sys_msg': is_sys_msg,
|
|
|
|
- 'channel': channel, 'event_type': event_type, 'n_time': n_time, 'electricity': '', 'bucket': bucket,
|
|
|
|
- 'app_push': have_dkey, 'storage_location': storage_location, 'ai_type': 0, 'dealings_type': 0,
|
|
|
|
- 'detection': 0, 'device_type': 1, 'app_push_config': '', 'uid_set_push_list': uid_push_list,
|
|
|
|
- 'redis_obj': redis_obj
|
|
|
|
- }
|
|
|
|
|
|
+ params = {'nickname': nickname, 'uid': uid, 'push_kwargs': push_kwargs, 'is_st': is_st,
|
|
|
|
+ 'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
|
|
|
|
+ 'electricity': '', 'bucket': bucket, 'app_push': have_dkey, 'storage_location': 1, 'ai_type': 0,
|
|
|
|
+ 'dealings_type': 0, 'detection': 0, 'device_type': 1, 'app_push_config': '',
|
|
|
|
+ 'uid_set_push_list': uid_push_list, 'redis_obj': redis_obj}
|
|
|
|
|
|
# 异步推送消息和保存数据
|
|
# 异步推送消息和保存数据
|
|
push_thread = threading.Thread(
|
|
push_thread = threading.Thread(
|
|
@@ -149,18 +134,24 @@ class NotificationView(View):
|
|
kwargs=params)
|
|
kwargs=params)
|
|
push_thread.start()
|
|
push_thread.start()
|
|
|
|
|
|
- # 获取图片上传链接
|
|
|
|
- kwargs = {
|
|
|
|
- 'is_st': is_st,
|
|
|
|
- 'uid': uid,
|
|
|
|
- 'channel': channel,
|
|
|
|
- 'n_time': n_time,
|
|
|
|
- 'region': region,
|
|
|
|
- 'aws_s3_client': '',
|
|
|
|
- 'storage_location': storage_location,
|
|
|
|
- 'oss_bucket': bucket
|
|
|
|
- }
|
|
|
|
- res_data = DevicePushService.get_res_data(**kwargs)
|
|
|
|
|
|
+ res_data = {}
|
|
|
|
+ if is_st == '0' or is_st == '2':
|
|
|
|
+ res_data = {'code': 0, 'msg': 'success 0 or 2'}
|
|
|
|
+ return JsonResponse(status=200, data=res_data)
|
|
|
|
+
|
|
|
|
+ elif is_st == '1':
|
|
|
|
+ obj = '{}/{}/{}.jpeg'.format(uid, channel, n_time)
|
|
|
|
+ url = bucket.sign_url('PUT', obj, 3600)
|
|
|
|
+ res_data = {'code': 0, 'img_push': url, 'msg': 'success 1'}
|
|
|
|
+
|
|
|
|
+ elif is_st == '3':
|
|
|
|
+ img_url_list = []
|
|
|
|
+ for i in range(int(is_st)):
|
|
|
|
+ obj = '{}/{}/{}_{}.jpeg'.format(uid, channel, n_time, i)
|
|
|
|
+ url = bucket.sign_url('PUT', obj, 3600)
|
|
|
|
+ img_url_list.append(url)
|
|
|
|
+
|
|
|
|
+ res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
|
|
|
|
|
|
V1_PUSH_LOGGER.info('旧推送接口响应,uid:{},n_time:{},事件类型:{},响应:{}'.
|
|
V1_PUSH_LOGGER.info('旧推送接口响应,uid:{},n_time:{},事件类型:{},响应:{}'.
|
|
format(uid, n_time, event_type, json.dumps(res_data)))
|
|
format(uid, n_time, event_type, json.dumps(res_data)))
|