Browse Source

推送图片测试

locky 3 years ago
parent
commit
5fb1cbd14e
1 changed files with 40 additions and 0 deletions
  1. 40 0
      Controller/DetectControllerV2.py

+ 40 - 0
Controller/DetectControllerV2.py

@@ -16,6 +16,7 @@ import datetime
 import json
 import logging
 import os
+import threading
 import time
 
 import apns2
@@ -39,6 +40,7 @@ from Object.UidTokenObject import UidTokenObject
 from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService
+from Service.GatewayService import GatewayPushService
 
 '''
 http://push.dvema.com/notify/push?etk=Y2lTRXhMTjBWS01sWlpURTVJU0ZWTlJ6RXhNVUU9T3o=&n_time=1526845794&channel=1&event_type=704&is_st=0
@@ -242,6 +244,9 @@ class NotificationView(View):
                 try:
                     # 推送消息
                     if not have_dkey:
+                        if (is_st == 1 or is_st == 3) and (push_type == 0 or push_type == 1):
+                            push_thread = threading.Thread(target=self.push_thread_test, args=(push_type, aws_s3_client, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text))
+                            push_thread.start()
                         if push_type == 0:  # ios apns
                             do_apns_code = self.do_apns(**kwag_args)
                             logger.info('进入do_apns,uid={}'.format(uid))
@@ -305,6 +310,16 @@ class NotificationView(View):
                     del up['uid_set__nickname']
                     del up['uid_set__detect_interval']
                     del up['uid_set__detect_group']
+
+                # try:
+                #     # 推送消息
+                #     if not have_dkey:
+                #         push_thread = threading.Thread(target=self.push_thread, args=(push_type, aws_s3_client, region, thumbspng, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text))
+                #         push_thread.start()
+                # except Exception as e:
+                #     logger.info('---推送图片异常---{}'.format(e))
+                #     pass
+
                 res_data = {'code': 0, 'img_push': response_url, 'msg': 'success'}
                 return JsonResponse(status=200, data=res_data)
 
@@ -346,6 +361,31 @@ class NotificationView(View):
             }
             return JsonResponse(status=200, data=json.dumps(data), safe=False)
 
+    def push_thread(self, push_type, aws_s3_client, region, thumbspng, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
+        time.sleep(3)
+        bucket = 'foreignpush' if region == 1 else 'push'
+        image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': thumbspng}, ExpiresIn=300)
+        if push_type == 0:
+            GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
+        elif push_type == 1:
+            GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
+
+    def push_thread_test(self, push_type, aws_s3_client, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text):
+        logger = logging.getLogger('info')
+        logger.info('推送图片测试:{} {} {} {} {} {} {} {}'.format(push_type, uid, appBundleId, token_val, event_type, n_time, msg_title, msg_text))
+        time.sleep(3)
+        bucket = 'foreignpush'
+        thumbspng = '11PGLS16VTM7PZGP111A/1/1659484801.jpeg'
+        try:
+            image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': thumbspng}, ExpiresIn=300)
+            logger.info('推送图片url:{}'.format(image_url))
+            if push_type == 0:
+                GatewayPushService.ios_apns_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
+            elif push_type == 1:
+                GatewayPushService.android_fcm_push(uid, appBundleId, token_val, n_time, event_type, msg_title, msg_text, image_url)
+        except Exception as e:
+            logger.info('推送图片测试异常:{}'.format(e))
+
     def test_apns(self, request_dict):
         kwag_args = {
             'uid': request_dict.get('uid', None),