Browse Source

oppo推送

peng 2 years ago
parent
commit
37bb347305

+ 7 - 0
AnsjerPush/cn_config/cn_formal_config.py

@@ -180,4 +180,11 @@ VIVOPUSH_CONFIG = {
         'Key':'531bf5befece8840d31b654a166db91c',
         'Secret':'9d6f19ef-5cdb-47ee-9433-d74c7d11fa50'
     }
+}
+
+OPPOPUSH_CONFIG = {
+    'com.ansjer.zccloud_ab': {
+        'Key': '882266a2000e4407990932be0b7043f5',
+        'Secret': '1037f29469c8416e87ab9cb8537c68ce'
+    }
 }

+ 7 - 0
AnsjerPush/dev_config/local_config.py

@@ -163,5 +163,12 @@ VIVOPUSH_CONFIG = {
     }
 }
 
+OPPOPUSH_CONFIG = {
+    'com.ansjer.zccloud_ab': {
+        'Key': '882266a2000e4407990932be0b7043f5',
+        'Secret': '1037f29469c8416e87ab9cb8537c68ce'
+    }
+}
+
 APNS_MODE = 'dev'
 REDIS_ADDRESS = '127.0.0.1'

+ 7 - 0
AnsjerPush/eur_config/eur_formal_config.py

@@ -180,4 +180,11 @@ VIVOPUSH_CONFIG = {
         'Key':'531bf5befece8840d31b654a166db91c',
         'Secret':'9d6f19ef-5cdb-47ee-9433-d74c7d11fa50'
     }
+}
+
+OPPOPUSH_CONFIG = {
+    'com.ansjer.zccloud_ab': {
+        'Key': '882266a2000e4407990932be0b7043f5',
+        'Secret': '1037f29469c8416e87ab9cb8537c68ce'
+    }
 }

+ 7 - 0
AnsjerPush/test_config/test_config.py

@@ -157,4 +157,11 @@ VIVOPUSH_CONFIG = {
         'Key':'531bf5befece8840d31b654a166db91c',
         'Secret':'9d6f19ef-5cdb-47ee-9433-d74c7d11fa50'
     }
+}
+
+OPPOPUSH_CONFIG = {
+    'com.ansjer.zccloud_ab': {
+        'Key': '882266a2000e4407990932be0b7043f5',
+        'Secret': '1037f29469c8416e87ab9cb8537c68ce'
+    }
 }

+ 7 - 0
AnsjerPush/us_config/formal_config.py

@@ -180,4 +180,11 @@ VIVOPUSH_CONFIG = {
         'Key':'531bf5befece8840d31b654a166db91c',
         'Secret':'9d6f19ef-5cdb-47ee-9433-d74c7d11fa50'
     }
+}
+
+OPPOPUSH_CONFIG = {
+    'com.ansjer.zccloud_ab': {
+        'Key': '882266a2000e4407990932be0b7043f5',
+        'Secret': '1037f29469c8416e87ab9cb8537c68ce'
+    }
 }

+ 57 - 2
Service/DevicePushService.py

@@ -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))

+ 76 - 6
Service/PushService.py

@@ -5,16 +5,19 @@
 @File :PushService.py
 @IDE :PyCharm
 """
+import hashlib
+import json
 import logging
 import os
+import time
 
 import apns2
 import jpush
 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
+from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
+    , VIVOPUSH_CONFIG, OPPOPUSH_CONFIG
 from Object.RedisObject import RedisObject
 from Service.CommonService import CommonService
 from Service.VivoPushService.push_admin.APIMessage import PushMessage
@@ -238,9 +241,9 @@ class PushObject:
                 'restricted_package_name': app_bundle_id,
                 'registration_id': token_val,
             }
-            if image:
-                data['extra.notification_style_type'] = 2
-                data['extra.notification_bigPic_uri'] = image
+            # if image:
+            #     data['extra.notification_style_type'] = 2
+            #     data['extra.notification_bigPic_uri'] = image
             headers = {
                 'Authorization': 'key={}'.format(app_secret)
             }
@@ -313,4 +316,71 @@ class PushObject:
             rec2 = sender_send.send(message)
             logger.info('vivo推送结果:{}'.format(rec2))
         except Exception as e:
-            logger.info('vivo推送异常:{}'.format(e))
+            logger.info('vivo推送异常:{}'.format(e))
+
+    @staticmethod
+    def android_oppopush(nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
+                         uid='', channel='1', image=''):
+        """
+        android oppo 推送
+        @param nickname: 设备昵称
+        @param app_bundle_id: 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: None
+        """
+        logger = logging.getLogger('info')
+        try:
+            """
+            android 国内oppo APP消息提醒推送
+            """
+            app_key = OPPOPUSH_CONFIG[app_bundle_id]['Key']
+            master_secret = OPPOPUSH_CONFIG[app_bundle_id]['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, 'nickname': nickname,
+                         '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)
+            logger.info("oppo推送返回值:{}".format(response.json()))
+            assert response.status_code == 200
+        except Exception as e:
+            return repr(e)