|
@@ -17,7 +17,7 @@ import requests
|
|
|
from pyfcm import FCMNotification
|
|
|
|
|
|
from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
|
|
|
- , VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG, CONFIG_INFO
|
|
|
+ , VIVOPUSH_CONFIG, OPPOPUSH_CONFIG, MEIZUPUSH_CONFIG, CONFIG_INFO, HONORPUSH_CONFIG
|
|
|
from Model.models import UidPushModel
|
|
|
from Object.RedisObject import RedisObject
|
|
|
from Object.S3Email import S3Email
|
|
@@ -480,6 +480,69 @@ class PushObject:
|
|
|
LOGGER.info("魅族推送异常:{}".format(repr(e)))
|
|
|
return False
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def android_honorpush(nickname, token_val, n_time, event_type, msg_title, msg_text,
|
|
|
+ uid='', channel='1', image='', app_bundle_id='', appBundleId='', channel_id=''):
|
|
|
+ """
|
|
|
+ android honor 推送
|
|
|
+ @param channel_id: 通知通道id
|
|
|
+ @param nickname: 设备昵称
|
|
|
+ @param app_bundle_id: app包id
|
|
|
+ @param appBundleId: app包id
|
|
|
+ @param token_val: 推送token
|
|
|
+ @param n_time: 当前时间
|
|
|
+ @param event_type: 事件类型
|
|
|
+ @param msg_title: 推送标题
|
|
|
+ @param msg_text: 推送内容
|
|
|
+ @param uid: uid
|
|
|
+ @param channel: 通道
|
|
|
+ @param image: 推送图片链接
|
|
|
+ @return: bool
|
|
|
+ """
|
|
|
+ app_bundle_id = appBundleId if appBundleId else app_bundle_id
|
|
|
+ try:
|
|
|
+ client_id = HONORPUSH_CONFIG[app_bundle_id]['client_id']
|
|
|
+ client_secret = HONORPUSH_CONFIG[app_bundle_id]['client_secret']
|
|
|
+ app_id = HONORPUSH_CONFIG[app_bundle_id]['app_id']
|
|
|
+ get_access_token_url = 'https://iam.developer.hihonor.com/auth/token'
|
|
|
+ post_data = {
|
|
|
+ 'grant_type': 'client_credentials',
|
|
|
+ 'client_id': client_id,
|
|
|
+ 'client_secret': client_secret
|
|
|
+ }
|
|
|
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
|
|
+ access_token_response = requests.post(get_access_token_url, data=post_data, headers=headers)
|
|
|
+ access_result = access_token_response.json()
|
|
|
+ authorization_token = 'Bearer ' + access_result['access_token']
|
|
|
+ # 发送推送
|
|
|
+ push_url = 'https://push-api.cloud.hihonor.com/api/v1/{}/sendMessage'.format(app_id)
|
|
|
+ headers = {'Content-Type': 'application/json', 'Authorization': authorization_token,
|
|
|
+ 'timestamp': str(n_time * 1000)}
|
|
|
+ extra_data = {'alert': 'Motion', 'msg': '', 'sound': 'sound.aif', 'zpush': '1',
|
|
|
+ 'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
|
|
|
+ 'uid': uid, 'channel': channel
|
|
|
+ }
|
|
|
+ push_data = {
|
|
|
+ "android": {
|
|
|
+ "data": json.dumps(extra_data),
|
|
|
+ "notification": {
|
|
|
+ "body": msg_text,
|
|
|
+ "title": msg_title,
|
|
|
+ "clickAction": {
|
|
|
+ "type": 3
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "notification": {},
|
|
|
+ "token": [token_val]
|
|
|
+ }
|
|
|
+ response = requests.post(push_url, json=push_data, headers=headers)
|
|
|
+ LOGGER.info("荣耀推送返回值:{}".format(response.json()))
|
|
|
+ return True
|
|
|
+ except Exception as e:
|
|
|
+ LOGGER.info("荣耀推送异常:{}".format(repr(e)))
|
|
|
+ return False
|
|
|
+
|
|
|
@staticmethod
|
|
|
def jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, token_val, extra_data):
|
|
|
"""
|