|
@@ -6,6 +6,8 @@
|
|
|
@Email : zhangdongming@asj6.wecom.work
|
|
|
@Software: PyCharm
|
|
|
"""
|
|
|
+import hashlib
|
|
|
+import json
|
|
|
import logging
|
|
|
import os
|
|
|
import threading
|
|
@@ -17,7 +19,7 @@ import requests
|
|
|
from pyfcm import FCMNotification
|
|
|
|
|
|
from AnsjerPush.config import JPUSH_CONFIG, FCM_CONFIG, APNS_CONFIG, BASE_DIR, APNS_MODE, APP_BUNDLE_DICT, \
|
|
|
- XMPUSH_CONFIG, VIVOPUSH_CONFIG
|
|
|
+ XMPUSH_CONFIG, VIVOPUSH_CONFIG, OPPOPUSH_CONFIG
|
|
|
from AnsjerPush.config import SERVER_TYPE
|
|
|
from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
|
|
|
DeviceChannelUserPermission
|
|
@@ -192,6 +194,8 @@ class DevicePushService:
|
|
|
result['do_xmpush_code'] = cls.do_xmpush(**kwag_args)
|
|
|
elif push_type == 5: # android vivopush
|
|
|
result['do_vivopush_code'] = cls.do_vivopush(**kwag_args)
|
|
|
+ elif push_type == 6: # android oppopush
|
|
|
+ result['do_oppopush_code'] = cls.do_oppopush(**kwag_args)
|
|
|
return result
|
|
|
except Exception as e:
|
|
|
LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
@@ -394,6 +398,54 @@ class DevicePushService:
|
|
|
if response.status_code == 200:
|
|
|
return response.json()
|
|
|
|
|
|
+ @classmethod
|
|
|
+ def do_oppopush(cls, uid, channel, appBundleId, token_val, event_type, n_time,
|
|
|
+ msg_title, msg_text):
|
|
|
+ """
|
|
|
+ android 国内oppo APP消息提醒推送
|
|
|
+ """
|
|
|
+ app_key = OPPOPUSH_CONFIG[appBundleId]['Key']
|
|
|
+ master_secret = OPPOPUSH_CONFIG[appBundleId]['Secret']
|
|
|
+ url = 'https://api.push.oppomobile.com/'
|
|
|
+ now_time = str(round(time.time() * 1000))
|
|
|
+ # 1、实例化一个sha256对象
|
|
|
+ sha256 = hashlib.sha256()
|
|
|
+ # 2、调用update方法进行加密
|
|
|
+ sha256.update((app_key + now_time + master_secret).encode('utf-8'))
|
|
|
+ # 3、调用hexdigest方法,获取加密结果
|
|
|
+ sign = sha256.hexdigest()
|
|
|
+ # 获取auth_token
|
|
|
+ get_token_url = url + 'server/v1/auth'
|
|
|
+ post_data = {
|
|
|
+ 'app_key': app_key,
|
|
|
+ 'sign': sign,
|
|
|
+ 'timestamp': now_time
|
|
|
+ }
|
|
|
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
|
+ response = requests.post(get_token_url, data=post_data, headers=headers)
|
|
|
+ result = response.json()
|
|
|
+ # 发送推送
|
|
|
+ push_url = url + 'server/v1/message/notification/unicast'
|
|
|
+ push_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
|
|
|
+ 'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
|
|
|
+ 'uid': uid, 'channel': channel}
|
|
|
+ message = {
|
|
|
+ "target_type": 2,
|
|
|
+ "target_value": token_val,
|
|
|
+ "notification": {
|
|
|
+ "title": msg_title,
|
|
|
+ "content": msg_text,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ push_data = {
|
|
|
+ 'auth_token': result['data']['auth_token'],
|
|
|
+ 'message': json.dumps(message)
|
|
|
+ }
|
|
|
+
|
|
|
+ response = requests.post(push_url, data=push_data, headers=headers)
|
|
|
+ if response.status_code == 200:
|
|
|
+ return response.json()
|
|
|
+
|
|
|
@classmethod
|
|
|
def async_send_picture_push(cls, push_type, aws_s3_client, bucket, key, uid, appBundleId,
|
|
|
token_val, event_type, n_time, msg_title, msg_text, channel):
|
|
@@ -418,6 +470,9 @@ class DevicePushService:
|
|
|
elif push_type == 4:
|
|
|
PushObject.android_xmpush(uid, appBundleId, token_val, n_time, event_type, msg_title,
|
|
|
msg_text, uid, channel, image_url)
|
|
|
+ elif push_type == 6:
|
|
|
+ PushObject.android_oppopush(uid, appBundleId, token_val, n_time, event_type, msg_title,
|
|
|
+ msg_text, uid, channel, image_url)
|
|
|
except Exception as e:
|
|
|
LOGGING.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
|
@@ -559,6 +614,6 @@ class DevicePushService:
|
|
|
.client_custom_map(**push_data) \
|
|
|
.message_dict()
|
|
|
rec2 = sender_send.send(message)
|
|
|
- return rec2
|
|
|
+ logger.info('vivo推送结果:{}'.format(rec2))
|
|
|
except Exception as e:
|
|
|
logger.info('vivo推送异常:{}'.format(e))
|