Browse Source

token obj

chenjunkai 5 years ago
parent
commit
65ad895534
1 changed files with 14 additions and 8 deletions
  1. 14 8
      Object/UidTokenObject.py

+ 14 - 8
Object/UidTokenObject.py

@@ -28,14 +28,20 @@ class UidTokenObject:
         token = self.token
         token = self.token
         if self.token is None:
         if self.token is None:
             return False
             return False
-        res = jwt.decode(token, UID_TOKEN_KEY, algorithms='HS256')
-        print(res)
-        UID = res.get('uid', None)
-        channel = res.get('channel', None)
-        if UID is None:
-            return False
-        self.UID = UID
-        self.channel = channel
+        try:
+            res = jwt.decode(token, UID_TOKEN_KEY, algorithms='HS256')
+            print(res)
+            UID = res.get('uid', None)
+            channel = res.get('channel', None)
+            if UID is None:
+                return False
+            self.UID = UID
+            self.channel = channel
+        except jwt.ExpiredSignatureError as e:
+            print('过期')
+            print(repr(e))
+        except Exception as e:
+            print(repr(e))
 
 
     def generate(self, data={}):
     def generate(self, data={}):
         token = jwt.encode(data, UID_TOKEN_KEY, algorithm='HS256').decode('utf-8')
         token = jwt.encode(data, UID_TOKEN_KEY, algorithm='HS256').decode('utf-8')