Browse Source

回放列表UID 加密6

chenshibin 4 years ago
parent
commit
44a750992b
2 changed files with 22 additions and 2 deletions
  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 boto3.session import Session
 from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
 from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
 from django.views.generic.base import View
 from django.views.generic.base import View
-from jwt import jwt
+import jwt
 from pyfcm import FCMNotification
 from pyfcm import FCMNotification
 
 
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \
 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?' \
             vod_url = '{server_domain}/cloudstorage/signplaym3u8?' \
                       'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
                       '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
             ts_num = int(vod['fg']) & 0xf
             vod_play_list.append({
             vod_play_list.append({
                 'name': vod['time'],
                 'name': vod['time'],

+ 20 - 0
Object/TokenObject.py

@@ -97,6 +97,26 @@ class TokenObject:
             self.code = 0
             self.code = 0
             return res
             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):
     def refresh(self):
         if not self.token:
         if not self.token:
             self.code = 309
             self.code = 309