Prechádzať zdrojové kódy

vivo/oppo推送,极光透传

peng 2 rokov pred
rodič
commit
1aff3fb62d
3 zmenil súbory, kde vykonal 40 pridanie a 5 odobranie
  1. 1 0
      Model/models.py
  2. 30 2
      Service/DevicePushService.py
  3. 9 3
      Service/PushService.py

+ 1 - 0
Model/models.py

@@ -1196,6 +1196,7 @@ class UidPushModel(models.Model):
     app_type = models.IntegerField(default=0, verbose_name=u'app类型 1:ios,2:安卓')
     push_type = models.IntegerField(default=0, verbose_name=u'推送类型')  # 0: apns, 1: 安卓gcm, 2: 极光, 3:华为, 4:小米, 5:vivo, 6:oppo, 7:魅族
     token_val = models.CharField(default='', max_length=160, verbose_name=u'设备验证令牌')
+    jg_token_val = models.CharField(default='', max_length=500, verbose_name=u'极光推送令牌')
     m_code = models.CharField(default='', max_length=64, verbose_name='手机唯一标识')
     addTime = models.IntegerField(verbose_name='添加时间', default=0)
     updTime = models.IntegerField(verbose_name='更新时间', default=0)

+ 30 - 2
Service/DevicePushService.py

@@ -112,7 +112,7 @@ class DevicePushService:
                 values('token_val', 'app_type', 'appBundleId', 'm_code', 'push_type', 'userID_id', 'userID__NickName',
                        'lang', 'm_code', 'tz', 'uid_set__nickname', 'uid_set__detect_interval', 'uid_set__detect_group',
                        'uid_set__channel', 'uid_set__ai_type', 'uid_set__device_type', 'uid_set__new_detect_interval',
-                       'uid_set__msg_notify')
+                       'uid_set__msg_notify', 'jg_token_val')
         return uid_push_qs
 
     @staticmethod
@@ -180,6 +180,8 @@ class DevicePushService:
                 kwag_args['token_val'] = token_val
                 kwag_args['msg_title'] = msg_title
                 kwag_args['msg_text'] = msg_text
+                if params['event_type'] == 606 and up['push_type'] in [5, 6]:
+                    kwag_args['jg_token_val'] = up['jg_token_val']
                 local_date_time = CommonService.get_now_time_str(n_time=params['n_time'], tz=tz, lang='cn')
                 local_date_time = local_date_time[0:10]
                 # 以下是存库
@@ -627,7 +629,7 @@ class DevicePushService:
 
     @staticmethod
     def do_oppopush(channel_id, uid, channel, appBundleId, token_val, event_type, n_time,
-                    msg_title, msg_text):
+                    msg_title, msg_text, jg_token_val=''):
         """
         android 国内oppo APP消息提醒推送
         """
@@ -676,6 +678,8 @@ class DevicePushService:
         response = requests.post(push_url, data=push_data, headers=headers)
         if response.status_code == 200:
             LOGGING.info("oppo推送返回值:{},uid:{},time:{},event:{}".format(response.json(), uid, now_time, event_type))
+            if event_type == 606 or event_type == '606':
+                DevicePushService.jpush_transparent_transmission(msg_title, msg_text, appBundleId, jg_token_val)
             return response.json()
 
     @classmethod
@@ -919,3 +923,27 @@ class DevicePushService:
         now_data = CommonService.get_now_time_str(now_time, tz, 'cn')
         week = LocalDateTimeUtil.date_to_week(now_data)
         return now_data, week
+
+    @staticmethod
+    def jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, token_val):
+        """
+        android 极光透传
+        @param msg_title: 推送标题
+        @param msg_text: 推送内容
+        @param token_val: 推送token
+        @param app_bundle_id: app包id
+        @return: None
+        """
+        try:
+            app_key = JPUSH_CONFIG[app_bundle_id]['Key']
+            master_secret = JPUSH_CONFIG[app_bundle_id]['Secret']
+            # 换成各自的app_key和master_secret
+            _jpush = jpush.JPush(app_key, master_secret)
+            push = _jpush.create_push()
+            push.audience = jpush.registration_id(token_val)
+            push.message = jpush.message(msg_content=msg_text, title=msg_title)
+            push.platform = jpush.all_
+            res = push.send()
+            assert res.status_code == 200
+        except Exception as e:
+            return repr(e)

+ 9 - 3
Service/PushService.py

@@ -21,6 +21,7 @@ from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG,
 from Model.models import UidPushModel
 from Object.S3Email import S3Email
 from Service.CommonService import CommonService
+from Service.DevicePushService import DevicePushService
 from Service.VivoPushService.push_admin.APIMessage import PushMessage
 from Service.VivoPushService.push_admin.APISender import APISender
 
@@ -268,12 +269,13 @@ class PushObject:
 
     @staticmethod
     def android_vivopush(token_val, n_time, event_type, msg_title, msg_text, app_bundle_id='', uid='', channel='1',
-                         image='', nickname='', appBundleId=''):
+                         image='', nickname='', appBundleId='', jg_token_val=''):
         """
         vivo 推送(不支持图片)
         @param app_bundle_id: app包名
         @param appBundleId: app包名
         @param token_val: 推送token
+        @param jg_token_val: 极光推送token
         @param event_type: 事件类型
         @param msg_title: 推送标题
         @param msg_text: 推送内容
@@ -323,19 +325,22 @@ class PushObject:
                 .message_dict()
             rec = sender_send.send(message)
             logger.info('vivo推送结果:{}, 设备uid:{}'.format(rec, uid))
+            if rec['result'] == 0 and (event_type == 606 or event_type == '606'):
+                DevicePushService.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val)
             return rec
         except Exception as e:
             logger.info('vivo推送异常:{}'.format(e))
 
     @staticmethod
     def android_oppopush(channel_id, nickname, app_bundle_id, token_val, n_time, event_type, msg_title, msg_text,
-                         uid='', channel='1', image=''):
+                         uid='', channel='1', image='', jg_token_val=''):
         """
         android oppo 推送
         @param channel_id: 通知通道id
         @param nickname: 设备昵称
         @param app_bundle_id: app包id
         @param token_val: 推送token
+        @param jg_token_val: 推送token
         @param n_time: 当前时间
         @param event_type: 事件类型
         @param msg_title: 推送标题
@@ -395,7 +400,8 @@ class PushObject:
 
             response = requests.post(push_url, data=push_data, headers=headers)
             logger.info("oppo推送返回值:{}".format(response.json()))
-            assert response.status_code == 200
+            if response.status_code == 200 and (event_type == 606 or event_type == '606'):
+                DevicePushService.jpush_transparent_transmission(msg_title, msg_text, app_bundle_id, jg_token_val)
         except Exception as e:
             return repr(e)