ソースを参照

fcm 推送删除失效token数据

locky 1 週間 前
コミット
97c4b5be82
1 ファイル変更7 行追加2 行削除
  1. 7 2
      Service/PushService.py

+ 7 - 2
Service/PushService.py

@@ -16,6 +16,7 @@ import jwt
 import httpx
 
 from firebase_admin import messaging
+from firebase_admin.messaging import UnregisteredError
 from pyfcm import FCMNotification
 
 from AnsjerPush.config import APP_BUNDLE_DICT, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG, \
@@ -355,10 +356,14 @@ class PushObject:
             # Send a message to the device corresponding to the provided
             # registration token.
             result = messaging.send(message)
-            LOGGER.info('uid:{}fcm推送结果:{}'.format(uid, result))
+            LOGGER.info('uid:{} fcm推送结果:{}'.format(uid, result))
             return True
+        except UnregisteredError as e:
+            LOGGER.info('uid:{},token:{},fcm推送异常UnregisteredError:{}'.format(uid, token_val, repr(e)))
+            # 删除失效token数据
+            UidPushModel.objects.filter(uid_set__uid=uid, token_val=token_val).delete()
         except Exception as e:
-            LOGGER.info('uid:{}fcm推送异常:{}'.format(uid, repr(e)))
+            LOGGER.info('uid:{} fcm推送异常:{}'.format(uid, repr(e)))
             return False
 
     @staticmethod