123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
- @AUTHOR: ASJRD018
- @NAME: AnsjerFormal
- @software: PyCharm
- @DATE: 2018/12/5 11:52
- @Version: python3.6
- @MODIFY DECORD:ansjer dev
- @file: UidTokenObject.py
- @Contact: chanjunkai@163.com
- """
- from AnsjerPush.config import UID_TOKEN_KEY
- import jwt
- # UID_TOKEN_KEY = 'c+565*j@%^'
- class UidTokenObject:
- def __init__(self, token=None):
- self.token = token
- self.UID = ''
- self.channel = ''
- self.flag = self.valid()
- def valid(self):
- 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
- def generate(self, data={}):
- token = jwt.encode(data, UID_TOKEN_KEY, algorithm='HS256').decode('utf-8')
- self.token=token
- return token
- #
- # uto = UidTokenObject()
- # res = uto.generate(data={'uid':'VVDHCVBYDKFMJRWA111A','channel':'1'})
- # print('---')
- # print(res)
|