瀏覽代碼

基础架构完成

chenjunkai 6 年之前
父節點
當前提交
179cade65e
共有 6 個文件被更改,包括 37 次插入17 次删除
  1. 3 7
      Ansjer/test/osssigput.py
  2. 26 6
      Controller/CloudVod.py
  3. 0 3
      Controller/MealManage.py
  4. 5 0
      Object/UidTokenObject.py
  5. 2 0
      Service/CommonService.py
  6. 1 1
      templates/hlsvod.html

+ 3 - 7
Ansjer/test/osssigput.py

@@ -22,11 +22,7 @@ import oss2
 import base64
 
 
-tokenss = {"AccessKeyId": "STS.NHxxqYRJFeeZJcNsD3u6i9t61",
-           "AccessKeySecret": "iAnPvLNruXs2ZQxURiuhGwWC2kwv94QhmepZcQuwsWc",
-           "SecurityToken": "CAIS0wJ1q6Ft5B2yfSjIr4vNM8vtv5Vn0qexSEX/l0RmeblF1rGd0zz2IHFIf3NhAe0bv/kzm2lX7/YYlqN4S5ZDR1HCbsJxtk7Uf9wwJ9ivgde8yJBZoljMewHKedGSvqL7Z+H+U6mMGJOEYEzFkSle2KbzcS7YMXWuLZyOj+wuDLEQRRLqVSdaI91UKwB+yrcdLmCDGfupPwLnpWDSAUF0wFce71ly8qOi2MaRxwPDhVnhsI8vqp/2P4KvYrsdXuh2WMzn2/dtJOiTknxb7x9X+LlxgPUDu02D3LC8G3Bd7w+LKPGultRkN11CYbUgEKNltIqF95oh4LSVzd+ojU8QYqcMA3j9PNnxmJKfRLn2Z4xlKeinYij3v4rRZsWvgWQNemkGMQ5GQd0lJ0JrBAYkIjOgcf77owqbOlr+GvXZj/hpiMov1Tvz4cGNPEOf5T4EVOPY4vQagAE6AcP5nsFSY2fDHKLn25q8PiTjO5LuHOJV6NwJ6jG8RjXu0/5qS1gmzQeThhUHkfErNnuTWbu53bS0HZ9bPEus7AoS9a0+4PsfEVJcVPAzqXQt2o7IgEPQXPB0/YD8pkNip+geoNPTqYRpbmD8Xc6PG65sTLPoevyDlWhp8z3noQ==",
-           "Expiration": "2018-12-10T07:16:46Z", "expire": "3600", "endpoint": "oss-cn-shenzhen.aliyuncs.com",
-           "bucket_name": "cloudvod1", "arn": "acs:ram::1901342792446414:role/stsoss/chanjunkai"}
+tokenss = {"AccessKeyId": "STS.NK9QEdKycTqd6JDyprKzbrcLL", "AccessKeySecret": "HXB8Aug13472E8YrvVPC7jSfgAz42dwqHbBZQEQWEWNx", "SecurityToken": "CAIS0wJ1q6Ft5B2yfSjIr4iMGv/QpqZC47OPNGz1nXAnR/VOnabnrjz2IHFIf3NhAe0bv/kzm2lX7/YYlqN4S5ZDR1HCbsJxtmOEMNYwJ9ivgde8yJBZoljMewHKedGSvqL7Z+H+U6mMGJOEYEzFkSle2KbzcS7YMXWuLZyOj+wuDLEQRRLqVSdaI91UKwB+yrcdLmCDGfupPwLnpWDSAUF0wFce71ly8qOi2MaRxwPDhVnhsI8vqp/2P4KvYrsdXuh2WMzn2/dtJOiTknxb7x9X+LlxgPUDu02D3LC8G3Bd7w+LKPGultRkN11CYbUgEKNltIqF95oh4LSVzd+ojU8QYqcMA3j9PNnxmJKfRLn2Z4xlKeinYij3v4rRZsWvgWQNemkGMQ5GQd0lJ0JrBAYkIjOgcf77owqbOlr+GvXZj/hpiMov1Tvz4cGNPEOf5T4EVOPY4vQagAG0T92WVVVpbT+yvK+aV0f1E46g6p/f7/JlQn0v3coLRbl4XfjTWH9NlUNTnYTljAsBRKPaYMZWJQGGSlACgE8pN+AtyZDsyKX8nCvs/utaMxVwcI1fq9GZLlw1MLhOJK7mkpGqDduoPy/tC1w6EGUZtLng/PwUNu68CXvu8rz/BA==", "Expiration": "2018-12-10T10:29:43Z", "expire": "3600", "endpoint": "oss-cn-shenzhen.aliyuncs.com", "bucket_name": "cloudvod1", "arn": "acs:ram::1901342792446414:role/stsoss/chanjunkai"}
 # 使用RAM账号的AccessKeyId和AccessKeySecret向STS申请临时token。
 
 # 使用临时token中的认证信息初始化StsAuth实例。
@@ -36,7 +32,7 @@ auth = oss2.StsAuth(tokenss['AccessKeyId'],
 print(auth)
 ''''''
 callback_dict = {}
-callback_dict['callbackUrl'] = 'http://www.dvema.com:3000/?id=1234&xxx=3423'
+callback_dict['callbackUrl'] = 'http://www.dvema.com:3000/?token=token&filename=shijianchuo&size=1234&len=1234'
 # 设置回调请求消息头中Host的值, 如oss-cn-hangzhou.aliyuncs.com。
 callback_dict['callbackHost'] = 'oss-cn-shenzhen.aliyuncs.com'
 # 设置发起回调时请求body的值。
@@ -56,7 +52,7 @@ bucket = oss2.Bucket(auth, tokenss['endpoint'], tokenss['bucket_name'])
 # bucket.delete_object('a-3.txt')
 # exit()
 
-bucket.put_object('sdf.txt', b'dsafdasfas',headers)
+bucket.put_object('123456.txt', b'241234124',headers)
 exit()
 res = bucket.get_object('1234.txt')
 print(res.read())

+ 26 - 6
Controller/CloudVod.py

@@ -38,6 +38,8 @@ from Service.CommonService import CommonService
 # 获取设备推送hls流 证书
 http://192.168.136.40:8077/cloudVod/getSts?uidToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJGVFNMTDhITTQzN1ozOFdVMTExQSJ9.GIBt8SgY-3yRt9mlihtvRwLM-MT8uVPDKCUQ2yvV3Vo
 # 获取存储的播放文件列表
+#修改状态
+http://192.168.136.40:8077/cloudVod/status?token=local&did=138001380001543918745881545&channel=4&status=1
 '''
 
 
@@ -65,6 +67,7 @@ class CloudVodView(View):
             # 移动侦测获取设备sts证书
             ip = CommonService.get_ip_address(request)
             return self.do_getSts(request_dict, ip, response)
+        # 付款完成
         elif operation == 'payExecute':
             return self.do_paypal_execute(request_dict, response)
         else:
@@ -82,9 +85,20 @@ class CloudVodView(View):
                 return self.do_create_order(request_dict, userID, response)
             elif operation == 'status':
                 return self.do_change_status(request_dict, userID, response)
+            elif operation == 'details':
+                return self.do_meal_details(request_dict, userID, response)
             else:
                 return response.json(414)
 
+    def do_meal_details(self, request_dict, userID, response):
+        did = request_dict.get('did', None)
+        qs = Device_Info.objects.filter(userID_id=userID, id=did).values("UID")
+        UID = qs[0]["UID"]
+        dmqs = Device_Meal.objects.filter(uid=UID).values('rank', 'status', 'channel', 'add_time', 'update_time',
+                                                          'end_time', 'rank__title')
+        res = CommonService.qs_to_list(dmqs)
+        return response.json(0, res)
+
     def do_create_order(self, request_dict, userID, response):
         did = request_dict.get('did', None)
         rank = request_dict.get('rank', None)
@@ -97,7 +111,7 @@ class CloudVodView(View):
         uid = qs[0]['UID']
         nowTime = int(time.time())
         orderID = CommonService.createID()
-        smqs = Store_Meal.objects.filter(id=rank).values("currency","price")
+        smqs = Store_Meal.objects.filter(id=rank).values("currency", "price")
         currency = smqs[0]['currency']
         price = smqs[0]['price']
         # call_sub_url = "{SERVER_DOMAIN}cloudVod/payExecute?orderID={orderID}".format(SERVER_DOMAIN=SERVER_DOMAIN,orderID=orderID)
@@ -157,12 +171,14 @@ class CloudVodView(View):
         if utko.flag is False:
             return response.json(444, 'uidToken')
         UID = utko.UID
-        qs = Device_Meal.objects.filter(uid=UID, status=1).values("rank", "channel")
+        channel = utko.channel
+        print(channel)
+        print(UID)
+        qs = Device_Meal.objects.filter(uid=UID, channel=channel, status=1).values("rank", "channel")
         if not qs.exists():
             return response.json(10, '设备未购买')
         # 套餐id
         rank = qs[0]['rank']
-        channel = qs[0]['channel']
         storage = '{uid}/vod{channel}/'.format(uid=UID, channel=channel)
 
         # bucket_vod_list = {1: 'cloudvod1', 2: 'cloudvod2', 3: 'cloudvod3'}
@@ -256,7 +272,8 @@ class CloudVodView(View):
             if obj.is_prefix():  # 文件夹
                 print('directory: ' + obj.key)
                 ptime = obj.key.split('/')[3]
-                url = bucket.sign_url('GET', '{prefix}{name}.m3u8'.format(prefix=obj.key, name=ptime), 60 * 60,params={'x-oss-process': 'hls/sign'})
+                url = bucket.sign_url('GET', '{prefix}{name}.m3u8'.format(prefix=obj.key, name=ptime), 60 * 60,
+                                      params={'x-oss-process': 'hls/sign'})
                 # url = bucket.sign_url('GET', obj.key, 60 * 60,params={'x-oss-process': 'hls/sign'})
                 urllst = url.split('?')
                 url_start = urllib.parse.unquote(urllst[0])
@@ -324,11 +341,14 @@ class CloudVodView(View):
         if not did or not status or not channel:
             return response.json(444, 'did,status,channel')
         dvqs = Device_Info.objects.filter(id=did, userID_id=userID).values("UID")
+        UID = dvqs[0]["UID"]
         if not dvqs.exists():
             return response.json(10, '没有设备')
-        dmqs = Device_Meal.objects.filter(channel=channel, uid=dvqs[0]["UID"])
+        dmqs = Device_Meal.objects.filter(channel=channel, uid=UID)
         if not dmqs.exists():
             return response.json(10, '未购买')
         now_time = timezone.localtime(timezone.now())
         dmqs.update(update_time=now_time, status=status)
-        return response.json(0)
+        utko = UidTokenObject()
+        utko.generate(data={'uid': UID, 'channel': channel})
+        return response.json(0,utko.token)

+ 0 - 3
Controller/MealManage.py

@@ -227,10 +227,7 @@ class MealView(View):
             return response.json(tko.code)
         userID = tko.userID
         if operation == 'list':
-
             return self.do_query_list(response)
-        elif operation == 'createOrder':
-            return
         else:
             return response.json(414)
 

+ 5 - 0
Object/UidTokenObject.py

@@ -20,6 +20,7 @@ class UidTokenObject:
     def __init__(self, token=None):
         self.token = token
         self.UID = ''
+        self.channel = ''
         self.flag = self.valid()
 
     def valid(self):
@@ -27,11 +28,15 @@ class UidTokenObject:
         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

+ 2 - 0
Service/CommonService.py

@@ -177,5 +177,7 @@ class CommonService:
                 ps['add_time'] = ps['add_time'].strftime("%Y-%m-%d %H:%M:%S")
             if 'update_time' in ps:
                 ps['update_time'] = ps['update_time'].strftime("%Y-%m-%d %H:%M:%S")
+            if 'end_time' in ps:
+                ps['end_time'] = ps['end_time'].strftime("%Y-%m-%d %H:%M:%S")
             res.append(ps)
         return res

+ 1 - 1
templates/hlsvod.html

@@ -10,7 +10,7 @@
 <!-- <script src="https://cdn.jsdelivr.net/npm/hls.js@canary"></script> -->
 <video id="video"></video>
 <script>
-    var url = 'http://cloudvod1.oss-cn-shenzhen.aliyuncs.com/FTSLL8HM437Z38WU111A/vod4/2018121001/1543902118/1543902118.m3u8?x-oss-process=hls%2Fsign&OSSAccessKeyId=LTAIyMkGfEdogyL9&Expires=1544428388&Signature=9pn0fhEl%2FBnpSgVYSmjiQAwwtc4%3D'
+    var url = 'http://cloudvod1.oss-cn-shenzhen.aliyuncs.com/FTSLL8HM437Z38WU111A/vod4/2018121001/1543902118/1543902118.m3u8?x-oss-process=hls%2Fsign&OSSAccessKeyId=LTAIyMkGfEdogyL9&Expires=1544434635&Signature=6ljV3ySn6ufRhwaLnvaSp9t5oXg%3D'
     var video = document.getElementById('video');
     if (Hls.isSupported()) {
         var hls = new Hls();