Эх сурвалжийг харах

fcm 推送删除失效token数据

locky 1 долоо хоног өмнө
parent
commit
65d7a00f36

+ 7 - 2
Service/PushService.py

@@ -16,6 +16,7 @@ import firebase_admin
 import jpush
 import requests
 from firebase_admin import messaging
+from firebase_admin.messaging import UnregisteredError
 from pyfcm import FCMNotification
 
 from AnsjerPush.config import APP_BUNDLE_DICT, APNS_MODE, BASE_DIR, APNS_CONFIG, FCM_CONFIG, JPUSH_CONFIG, XMPUSH_CONFIG \
@@ -242,10 +243,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