浏览代码

回放列表UID 加密6

chenshibin 4 年之前
父节点
当前提交
44a750992b
共有 2 个文件被更改,包括 22 次插入2 次删除
  1. 2 2
      Controller/CloudStorage.py
  2. 20 0
      Object/TokenObject.py

+ 2 - 2
Controller/CloudStorage.py

@@ -32,7 +32,7 @@ from aliyunsdksts.request.v20150401 import AssumeRoleRequest
 from boto3.session import Session
 from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
 from django.views.generic.base import View
-from jwt import jwt
+import jwt
 from pyfcm import FCMNotification
 
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \
@@ -469,7 +469,7 @@ class CloudStorageView(View):
             )
             vod_url = '{server_domain}/cloudstorage/signplaym3u8?' \
                       'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
-                format(server_domain=SERVER_DOMAIN, uid=TokenObject.generate(uid), channel=channel, time=vod['time'])
+                format(server_domain=SERVER_DOMAIN, uid=TokenObject.encryption(data={'uid': uid}), channel=channel, time=vod['time'])
             ts_num = int(vod['fg']) & 0xf
             vod_play_list.append({
                 'name': vod['time'],

+ 20 - 0
Object/TokenObject.py

@@ -97,6 +97,26 @@ class TokenObject:
             self.code = 0
             return res
 
+    def encryption(self, data={}):
+        try:
+            access_expire = int(OAUTH_ACCESS_TOKEN_TIME.total_seconds())
+            refresh_expire = int(OAUTH_REFRESH_TOKEN_TIME.total_seconds())
+            now_stamp = int(time.time())
+            access_data = data
+            refresh_data = data
+            access_data['exp'] = access_expire + now_stamp
+            refresh_data['exp'] = refresh_expire + now_stamp
+            access_token = jwt.encode(access_data,
+                                      OAUTH_ACCESS_TOKEN_SECRET,
+                                      algorithm='HS256')
+            return access_token.decode('utf-8')
+        except Exception as e:
+            self.code = 309
+            print(repr(e))
+        else:
+            self.code = 0
+            return res
+
     def refresh(self):
         if not self.token:
             self.code = 309