瀏覽代碼

token obj

chenjunkai 5 年之前
父節點
當前提交
65ad895534
共有 1 個文件被更改,包括 14 次插入8 次删除
  1. 14 8
      Object/UidTokenObject.py

+ 14 - 8
Object/UidTokenObject.py

@@ -28,14 +28,20 @@ class UidTokenObject:
         token = self.token
         if self.token is None:
             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={}):
         token = jwt.encode(data, UID_TOKEN_KEY, algorithm='HS256').decode('utf-8')