ソースを参照

修复P8推送无图问题

zhangdongming 1 ヶ月 前
コミット
c8f6091543
1 ファイル変更12 行追加9 行削除
  1. 12 9
      Service/PushService.py

+ 12 - 9
Service/PushService.py

@@ -130,15 +130,9 @@ 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 —— 把 image_url 等字段放顶层,便于 Notification Service Extension 直接读取
             body = {
                 "aps": {
                     "alert": {
@@ -149,7 +143,16 @@ class PushObject:
                     "category": "myCategory",
                     "mutable-content": 1
                 },
-                "custom": push_data
+                # ---- 把原来的 push_data 展平到顶层(尤其是 image_url) ----
+                "image_url": launch_image,
+                "uid": uid,
+                "channel": channel,
+                "received_at": n_time,
+                "event_time": n_time,
+                "event_type": event_type,
+                "nickname": nickname,
+                "zpush": "1",
+                "jump_type": CommonService.get_jump_type(event_type)
             }
 
             headers = {
@@ -157,7 +160,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: