Browse Source

修改gitignore,测试apns推送图片

locky 3 years ago
parent
commit
e2170c650e
4 changed files with 13 additions and 7 deletions
  1. 1 0
      .gitignore
  2. 3 0
      AnsjerPush/test_config.py
  3. 5 5
      Controller/DetectControllerV2.py
  4. 4 2
      Service/GatewayService.py

+ 1 - 0
.gitignore

@@ -1,6 +1,7 @@
 /.idea
 /static
 /Model/migrations
+/AnsjerPush/file/apns_pem/
 /Ansjer/__pycache__
 /Controller/__pycache__
 /Model/__pycache__

+ 3 - 0
AnsjerPush/test_config.py

@@ -141,6 +141,9 @@ APNS_CONFIG = {
     'com.ansjer.customizeda': {
         'pem_path': 'AnsjerPush/file/apns_pem/customizeda-dev.pem',
     },
+    'com.ansjer.customizede': {
+        'pem_path': 'AnsjerPush/file/apns_pem/customizede.pem',
+    },
     'com.ansjer.zccloud': {
         'pem_path': 'AnsjerPush/file/apns_pem/zccloud-dev.pem',
     },

+ 5 - 5
Controller/DetectControllerV2.py

@@ -230,10 +230,10 @@ class NotificationView(View):
                 try:
                     # 推送消息
                     if not have_dkey:
-                        # logger.info('准备推送:{}, {}'.format(uid, request_dict))
-                        # 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, channel))
-                        # push_thread.start()
+                        logger.info('准备推送:{}, {}'.format(uid, request_dict))
+                        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, channel))
+                            push_thread.start()
                         if push_type == 0:  # ios apns
                             do_apns_code = self.do_apns(**kwag_args)
                             logger.info('进入do_apns,uid={}'.format(uid))
@@ -352,7 +352,7 @@ class NotificationView(View):
         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/1660166702.jpeg'
+        thumbspng = '11PGLS16VTM7PZGP111A/1/1661251934.jpeg'
         try:
             image_url = aws_s3_client.generate_presigned_url('get_object', Params={'Bucket': bucket, 'Key': thumbspng}, ExpiresIn=86400)
             logger.info('推送图片url:{}'.format(image_url))

+ 4 - 2
Service/GatewayService.py

@@ -46,9 +46,11 @@ class GatewayPushService:
             cli = apns2.APNSClient(mode=APNS_MODE, client_cert=pem_path)
             alert = apns2.PayloadAlert(title=msg_title, body=msg_text, launch_image=launch_image)
             push_data = {'alert': 'Motion', 'msg': '', 'sound': '', 'zpush': '1', 'uid': uid, 'channel': channel,
-                         'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname
+                         'received_at': n_time, 'event_time': n_time, 'event_type': event_type, 'nickname': nickname,
+                         'image_url': launch_image
                          }
-            payload = apns2.Payload(alert=alert, custom=push_data, sound='default', mutable_content=True)
+            payload = apns2.Payload(alert=alert, custom=push_data, sound='default', category='MyCategory',
+                                    mutable_content=True)
             n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
             res = cli.push(n=n, device_token=token_val, topic=app_bundle_id)
             assert res.status_code == 200