|
@@ -1,5 +1,5 @@
|
|
|
# @Author : peng
|
|
|
-# @File : LogoutPushController.py
|
|
|
+# @File : TransparentTransmissionPushController.py
|
|
|
# @Time : 2024年7月9日17:22:19
|
|
|
import json
|
|
|
import threading
|
|
@@ -16,7 +16,7 @@ from Service.HuaweiPushService.push_admin import messaging
|
|
|
from AnsjerPush.config import LOGGER
|
|
|
|
|
|
|
|
|
-class LogoutPushView(View):
|
|
|
+class TransparentTransmissionPushView(View):
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
request.encoding = 'utf-8'
|
|
@@ -30,8 +30,10 @@ class LogoutPushView(View):
|
|
|
|
|
|
def validation(self, request_dict, operation):
|
|
|
response = ResponseObject()
|
|
|
- if operation == 'push': # 强制退出推送
|
|
|
+ if operation == 'logout-push': # 强制退出推送
|
|
|
return self.logout_push(request_dict, response)
|
|
|
+ elif operation == 'del-device-push': # 删除设备推送
|
|
|
+ return self.del_device_push(request_dict, response)
|
|
|
|
|
|
@staticmethod
|
|
|
def logout_push(request_dict, response):
|
|
@@ -44,16 +46,34 @@ class LogoutPushView(View):
|
|
|
'token_val', 'appBundleId', 'push_type', 'jg_token_val').distinct()
|
|
|
if not uid_push_qs.exists():
|
|
|
return response.json(173)
|
|
|
- push_thread = threading.Thread(target=LogoutPushView.thread_logout_push, args=(uid_push_qs, user_id,))
|
|
|
+ push_thread = threading.Thread(target=TransparentTransmissionPushView.thread_push,
|
|
|
+ args=(uid_push_qs, user_id, '强制登出', '强制登出', 705))
|
|
|
+ push_thread.start()
|
|
|
+ # 删除推送信息
|
|
|
+ UidPushModel.objects.filter(userID=user_id).exclude(token_val=push_token).delete()
|
|
|
+ return response.json(0)
|
|
|
+ except Exception as e:
|
|
|
+ return HttpResponse(repr(e), status=500)
|
|
|
+
|
|
|
+ @staticmethod
|
|
|
+ def del_device_push(request_dict, response):
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
+ if not all([uid]):
|
|
|
+ return response.json(444)
|
|
|
+ try:
|
|
|
+ uid_push_qs = UidPushModel.objects.filter(uid_set_uid=uid).values(
|
|
|
+ 'token_val', 'appBundleId', 'push_type', 'jg_token_val')
|
|
|
+ if not uid_push_qs.exists():
|
|
|
+ return response.json(173)
|
|
|
+ push_thread = threading.Thread(target=TransparentTransmissionPushView.thread_push,
|
|
|
+ args=(uid_push_qs, uid, '删除设备', '删除设备'))
|
|
|
push_thread.start()
|
|
|
return response.json(0)
|
|
|
except Exception as e:
|
|
|
return HttpResponse(repr(e), status=500)
|
|
|
|
|
|
@staticmethod
|
|
|
- def thread_logout_push(qs, user_id):
|
|
|
- title = '强制登出'
|
|
|
- content = '强制登出'
|
|
|
+ def thread_push(qs, user_id, title, content, event_type):
|
|
|
now_time = int(time.time())
|
|
|
for push_item in qs:
|
|
|
kwargs = {
|
|
@@ -61,7 +81,7 @@ class LogoutPushView(View):
|
|
|
'app_bundle_id': push_item['appBundleId'],
|
|
|
'token_val': push_item['token_val'],
|
|
|
'n_time': now_time,
|
|
|
- 'event_type': 705,
|
|
|
+ 'event_type': event_type,
|
|
|
'msg_title': title,
|
|
|
'msg_text': content,
|
|
|
}
|
|
@@ -74,7 +94,7 @@ class LogoutPushView(View):
|
|
|
push_item['token_val'], kwargs)
|
|
|
|
|
|
elif push_item['push_type'] == 3: # 华为
|
|
|
- LogoutPushView.huawei_transparent_transmission(user_id=user_id, **kwargs)
|
|
|
+ TransparentTransmissionPushView.huawei_transparent_transmission(user_id=user_id, **kwargs)
|
|
|
elif push_item['push_type'] == 4: # 小米
|
|
|
channel_id = XM_PUSH_CHANNEL_ID['device_reminder']
|
|
|
PushObject.android_xmpush(channel_id=channel_id, **kwargs)
|
|
@@ -86,9 +106,7 @@ class LogoutPushView(View):
|
|
|
elif push_item['push_type'] == 7: # 魅族
|
|
|
PushObject.android_meizupush(**kwargs)
|
|
|
elif push_item['push_type'] == 8: # 荣耀
|
|
|
- LogoutPushView.honor_transparent_transmission(**kwargs)
|
|
|
- # 删除推送信息
|
|
|
- UidPushModel.objects.filter(userID=user_id, token_val=push_item['token_val']).delete()
|
|
|
+ TransparentTransmissionPushView.honor_transparent_transmission(**kwargs)
|
|
|
|
|
|
@staticmethod
|
|
|
def huawei_transparent_transmission(nickname, app_bundle_id, token_val, n_time, event_type, msg_title,
|
|
@@ -132,7 +150,7 @@ class LogoutPushView(View):
|
|
|
LOGGER.info('退出登录,华为透传推送异常: {}'.format(repr(e)))
|
|
|
|
|
|
@staticmethod
|
|
|
- def honor_transparent_transmission(token_val, n_time, event_type, msg_title, msg_text, app_bundle_id, nickname=''):
|
|
|
+ def honor_transparent_transmission(token_val, n_time, event_type, msg_title, msg_text, app_bundle_id, nickname=''):
|
|
|
"""
|
|
|
android honor 推送
|
|
|
@param nickname: 设备昵称
|
|
@@ -164,7 +182,7 @@ class LogoutPushView(View):
|
|
|
'timestamp': str(int(time.time()) * 1000)}
|
|
|
extra_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
|
|
|
'received_at': n_time, 'event_time': n_time, 'event_type': str(event_type),
|
|
|
- 'nickname': nickname, 'title': msg_title, 'body': msg_text}
|
|
|
+ 'nickname': nickname, 'title': msg_title, 'body': msg_text}
|
|
|
# 透传推送
|
|
|
push_data = {
|
|
|
"data": json.dumps(extra_data),
|