|
@@ -10,13 +10,14 @@ import apns2
|
|
from _ssl import SSLError
|
|
from _ssl import SSLError
|
|
from django.http import HttpResponse
|
|
from django.http import HttpResponse
|
|
from django.views import View
|
|
from django.views import View
|
|
-from AnsjerPush.config import CONFIG_INFO
|
|
|
|
|
|
+from AnsjerPush.config import CONFIG_INFO, CONFIG_CN
|
|
|
|
|
|
from Model.models import Device_Info, SceneLog, EquipmentInfo1
|
|
from Model.models import Device_Info, SceneLog, EquipmentInfo1
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
-from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, DATA_PUSH_EVENT_TYPE_LIST
|
|
|
|
|
|
+from AnsjerPush.config import APNS_MODE, BASE_DIR, APNS_CONFIG, DATA_PUSH_EVENT_TYPE_LIST
|
|
from Object.S3Email import S3Email
|
|
from Object.S3Email import S3Email
|
|
|
|
+from Object.enums.ConstantEnum import ConstantEnum
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
|
|
|
|
ERROR_INFO_LOGGER = logging.getLogger('error_info')
|
|
ERROR_INFO_LOGGER = logging.getLogger('error_info')
|
|
@@ -62,34 +63,41 @@ class InitView(View):
|
|
def check_apns_pem():
|
|
def check_apns_pem():
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
try:
|
|
try:
|
|
- server_id = os.environ.get('ServerID', 0)
|
|
|
|
|
|
+ # server_id = os.environ.get('ServerID', 0)
|
|
n_time = int(time.time())
|
|
n_time = int(time.time())
|
|
uid, msg_title, msg_text, launch_image, event_type, channel, nickname, token_val = \
|
|
uid, msg_title, msg_text, launch_image, event_type, channel, nickname, token_val = \
|
|
'', '', '', '', 1, '', '', ''
|
|
'', '', '', '', 1, '', '', ''
|
|
app_bundle_id_list = [
|
|
app_bundle_id_list = [
|
|
- 'com.ansjer.zccloud', 'com.ansjer.loocamccloud', 'com.cloudlife.commissionf', 'com.ansjer.customizeda',
|
|
|
|
- 'com.ansjer.customizedb', 'com.ansjer.customizedc', 'com.ansjer.customizedd', 'com.ansjer.customizede'
|
|
|
|
|
|
+ ConstantEnum.LOOCAM_APP_BUNDLE_ID_IOS.value, ConstantEnum.VSEES_APP_BUNDLE_ID_IOS.value
|
|
]
|
|
]
|
|
|
|
+ if CONFIG_INFO != CONFIG_CN:
|
|
|
|
+ app_bundle_id_list.append(ConstantEnum.ZOSI_APP_BUNDLE_ID_IOS.value)
|
|
|
|
+ else:
|
|
|
|
+ app_bundle_id_list.append(ConstantEnum.ZOSI_CN_APP_BUNDLE_ID_IOS.value)
|
|
|
|
+
|
|
for app_bundle_id in app_bundle_id_list:
|
|
for app_bundle_id in app_bundle_id_list:
|
|
- pem_path = os.path.join(BASE_DIR, APNS_CONFIG[app_bundle_id]['pem_path'])
|
|
|
|
- cli = apns2.APNSClient(mode=APNS_MODE, client_cert=pem_path)
|
|
|
|
- alert = apns2.PayloadAlert(title=msg_title, body=msg_text, launch_image=launch_image)
|
|
|
|
- # 跳转类型,1:推送消息,2:系统消息,3:音视频通话消息
|
|
|
|
- jump_type = CommonService.get_jump_type(event_type)
|
|
|
|
- push_data = {
|
|
|
|
- 'alert': msg_text, 'msg': '', 'sound': '', 'zpush': '1', 'uid': uid, 'channel': channel,
|
|
|
|
- 'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
|
|
|
|
- 'image_url': launch_image, 'jump_type': jump_type
|
|
|
|
- }
|
|
|
|
- sound = 'call_phone.mp3' if event_type in DATA_PUSH_EVENT_TYPE_LIST else 'default'
|
|
|
|
- payload = apns2.Payload(alert=alert, custom=push_data, sound=sound, category='myCategory',
|
|
|
|
- mutable_content=True)
|
|
|
|
- n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
|
try:
|
|
try:
|
|
- res = cli.push(n=n, device_token=token_val, topic=app_bundle_id)
|
|
|
|
- except SSLError as e:
|
|
|
|
- email_content = '{}服第{}台服务器苹果推送证书过期: {}'.format(CONFIG_INFO, server_id, pem_path)
|
|
|
|
- S3Email().faEmail(email_content, 'servers@ansjer.com')
|
|
|
|
|
|
+ pem_path = os.path.join(BASE_DIR, APNS_CONFIG[app_bundle_id]['pem_path'])
|
|
|
|
+ cli = apns2.APNSClient(mode=APNS_MODE, client_cert=pem_path)
|
|
|
|
+ alert = apns2.PayloadAlert(title=msg_title, body=msg_text, launch_image=launch_image)
|
|
|
|
+ # 跳转类型,1:推送消息,2:系统消息,3:音视频通话消息
|
|
|
|
+ jump_type = CommonService.get_jump_type(event_type)
|
|
|
|
+ push_data = {
|
|
|
|
+ 'alert': msg_text, 'msg': '', 'sound': '', 'zpush': '1', 'uid': uid, 'channel': channel,
|
|
|
|
+ 'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
|
|
|
|
+ 'image_url': launch_image, 'jump_type': jump_type
|
|
|
|
+ }
|
|
|
|
+ sound = 'call_phone.mp3' if event_type in DATA_PUSH_EVENT_TYPE_LIST else 'default'
|
|
|
|
+ payload = apns2.Payload(alert=alert, custom=push_data, sound=sound, category='myCategory',
|
|
|
|
+ mutable_content=True)
|
|
|
|
+ n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
|
|
|
|
+ try:
|
|
|
|
+ res = cli.push(n=n, device_token=token_val, topic=app_bundle_id)
|
|
|
|
+ except SSLError as e:
|
|
|
|
+ email_content = '{}服务器苹果推送证书过期: {}'.format(CONFIG_INFO, pem_path)
|
|
|
|
+ S3Email().faEmail(email_content, 'servers@ansjer.com')
|
|
|
|
+ except Exception as e:
|
|
|
|
+ continue
|
|
return response.json(0)
|
|
return response.json(0)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
return response.json(0, 'error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
return response.json(0, 'error_line:{},error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|