浏览代码

修复P8推送问题

zhangdongming 4 周之前
父节点
当前提交
045999d3b4
共有 1 个文件被更改,包括 27 次插入18 次删除
  1. 27 18
      Service/PushService.py

+ 27 - 18
Service/PushService.py

@@ -131,25 +131,31 @@ class PushObject:
             url = f"{apns_url}/3/device/{token_val}"
 
             jump_type = CommonService.get_jump_type(event_type)
-            push_data = {
-                'alert': msg_text, 'msg': '', 'sound': '',
-                'zpush': '1', 'uid': uid, 'channel': channel,
-                'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
-                'nickname': nickname, 'image_url': launch_image, 'jump_type': jump_type
-            }
+
             sound = 'call_phone.mp3' if event_type in DATA_PUSH_EVENT_TYPE_LIST else 'default'
 
+            # 构造 body —— 把 image_url 等字段放顶层,便于 Notification Service Extension 直接读取
             body = {
+                "alert": msg_text,
                 "aps": {
                     "alert": {
-                        "title": msg_title,
+                        "title": uid,
                         "body": msg_text
                     },
                     "sound": sound,
                     "category": "myCategory",
                     "mutable-content": 1
                 },
-                "custom": push_data
+                'jump_type': jump_type,
+                'image_url': launch_image,
+                "channel": channel,
+                "event_time": n_time,
+                "event_type": event_type,
+                "msg": "",
+                "received_at": n_time,
+                "sound": "",
+                "uid": uid,
+                "zpush": "1"
             }
 
             headers = {
@@ -157,7 +163,7 @@ class PushObject:
                 "apns-push-type": "alert"
             }
 
-            with httpx.Client(http2=True,timeout=10,cert=pem_path,) as client:
+            with httpx.Client(http2=True,timeout=10, cert=str(pem_path),) as client:
                 res = client.post(url, headers=headers, json=body)
 
             if res.status_code == 200:
@@ -226,14 +232,6 @@ class PushObject:
                 apns_url = "https://api.sandbox.push.apple.com" if CONFIG_INFO == CONFIG_TEST else "https://api.push.apple.com"
                 url = f"{apns_url}/3/device/{token_val}"
 
-
-                jump_type = CommonService.get_jump_type(event_type)
-                push_data = {
-                    'alert': msg_text, 'msg': '', 'sound': '',
-                    'zpush': '1', 'uid': uid, 'channel': channel,
-                    'received_at': n_time, 'event_time': n_time, 'event_type': event_type,
-                    'nickname': nickname, 'image_url': launch_image, 'jump_type': jump_type
-                }
                 sound = 'call_phone.mp3' if event_type in DATA_PUSH_EVENT_TYPE_LIST else 'default'
 
                 body = {
@@ -246,7 +244,18 @@ class PushObject:
                         "category": "myCategory",
                         "mutable-content": 1
                     },
-                    "custom": push_data
+                    # ---- 把原来的 push_data 展平到顶层(尤其是 image_url) ----
+                    "jump_type": CommonService.get_jump_type(event_type),
+                    "image_url": launch_image,
+                    "channel": channel,
+                    "event_time": n_time,
+                    "event_type": event_type,
+                    "msg":"",
+                    "received_at": n_time,
+                    "sound":"",
+                    "uid": uid,
+                    "zpush": "1",
+                    "nickname": nickname,
                 }
 
                 headers = {