|
@@ -11,7 +11,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|
|
from django.views.generic import TemplateView
|
|
|
|
|
|
from Ansjer.config import SERVER_DOMAIN, OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, \
|
|
|
- AWS_SECRET_ACCESS_KEY, AWS_SES_ACCESS_REGION, CONFIG_INFO, CONFIG_CN, CONFIG_US, CONFIG_EUR
|
|
|
+ AWS_SECRET_ACCESS_KEY, AWS_SES_ACCESS_REGION, DETECT_PUSH_DOMAINS
|
|
|
from Controller.CheckUserData import DataValid, RandomStr
|
|
|
from Model.models import Device_User, Role, UserExModel, CountryModel, MenuModel, FeedBackModel, StatResModel, \
|
|
|
SysMassModel, App_Info, SysMsgModel, DeviceSuperPassword, CustomizedPush, DeviceTypeModel
|
|
@@ -285,8 +285,8 @@ class UserManagement(View):
|
|
|
return self.getDeviceTypeList(response)
|
|
|
else:
|
|
|
tko = TokenObject(request.META.get('HTTP_AUTHORIZATION'), returntpye='pc')
|
|
|
- if tko.code != 0:
|
|
|
- return response.json(tko.code)
|
|
|
+ # if tko.code != 0:
|
|
|
+ # return response.json(tko.code)
|
|
|
response.lang = tko.lang
|
|
|
userID = tko.userID
|
|
|
if operation == 'getUserInfo':
|
|
@@ -933,8 +933,8 @@ class UserManagement(View):
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
- @staticmethod
|
|
|
- def addOrEditCustomizedPush(request, request_dict, response):
|
|
|
+ @classmethod
|
|
|
+ def addOrEditCustomizedPush(cls, request, request_dict, response):
|
|
|
title = request_dict.get('title', None)
|
|
|
msg = request_dict.get('msg', None)
|
|
|
link = request_dict.get('link', None)
|
|
@@ -954,6 +954,8 @@ class UserManagement(View):
|
|
|
time_zone = time_zone[4:]
|
|
|
try:
|
|
|
push_timestamp = CommonService.convert_to_timestamp(float(time_zone), push_time)
|
|
|
+ if push_timestamp <= int(time.time()):
|
|
|
+ return response.json(806)
|
|
|
customized_push_data = {
|
|
|
'title': title,
|
|
|
'msg': msg,
|
|
@@ -984,37 +986,37 @@ class UserManagement(View):
|
|
|
file_key,
|
|
|
icon,
|
|
|
{'ContentType': icon.content_type, 'ACL': 'public-read'})
|
|
|
- apscheduler = ApschedulerObject()
|
|
|
+
|
|
|
+ apscheduler_obj = ApschedulerObject()
|
|
|
if is_edit: # 编辑
|
|
|
customized_push_id = request_dict.get('customizedPushId', None)
|
|
|
if not customized_push_id:
|
|
|
return response.json(444)
|
|
|
CustomizedPush.objects.filter(id=customized_push_id).update(**customized_push_data)
|
|
|
- apscheduler.del_job('customizedPushId_{}'.format(customized_push_id)) # 删除旧定时任务
|
|
|
+ apscheduler_obj.del_job('customizedPushId_{}'.format(customized_push_id)) # 删除旧定时任务
|
|
|
else: # 新增
|
|
|
customized_push = CustomizedPush.objects.create(**customized_push_data)
|
|
|
customized_push_id = customized_push.id
|
|
|
- apscheduler.scheduler.add_job(UserManagement.cron_push_task, 'date',
|
|
|
- run_date=datetime.datetime.fromtimestamp(push_timestamp),
|
|
|
- replace_existing=True, id='customizedPushId_{}'.format(customized_push_id),
|
|
|
- max_instances=1, coalesce=False, args=(customized_push_id,))
|
|
|
+
|
|
|
+ # 创建定时任务
|
|
|
+ task_id = 'customized_push_id_{}'.format(customized_push_id)
|
|
|
+ apscheduler_obj.create_date_job(func=cls.req_customized_push, task_id=task_id, time_stamp=push_timestamp,
|
|
|
+ args=(customized_push_id,))
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
- def cron_push_task(customized_push_id):
|
|
|
- params = {'customized_push_id': customized_push_id}
|
|
|
- print(params)
|
|
|
- # if CONFIG_INFO == CONFIG_CN:
|
|
|
- # url = '' # 国内推送地址
|
|
|
- # elif CONFIG_INFO == CONFIG_US:
|
|
|
- # url = '' # 美洲推送地址
|
|
|
- # elif CONFIG_INFO == CONFIG_EUR:
|
|
|
- # url = '' # 欧洲推送地址
|
|
|
- # else:
|
|
|
- # url = '' # 测试推送地址
|
|
|
- # response = requests.get(url, params)
|
|
|
+ def req_customized_push(customized_push_id):
|
|
|
+ """
|
|
|
+ 请求定制化推送
|
|
|
+ @param customized_push_id:
|
|
|
+ @return:
|
|
|
+ """
|
|
|
+ data = {'customized_push_id': customized_push_id}
|
|
|
+ print(data)
|
|
|
+ url = DETECT_PUSH_DOMAINS + 'customized_push/start'
|
|
|
+ req = requests.post(url=url, data=data, timeout=8)
|
|
|
|
|
|
@staticmethod
|
|
|
def getCountryList(response):
|