Browse Source

Merge branch 'test' of 13.56.215.252:/web/rpo/AnsjerFormal into test

chenshibin 4 years ago
parent
commit
b79057e6da
2 changed files with 52 additions and 40 deletions
  1. 47 35
      Controller/CloudStorage.py
  2. 5 5
      Controller/TestApi.py

+ 47 - 35
Controller/CloudStorage.py

@@ -204,14 +204,16 @@ class CloudStorageView(View):
         channel = request_dict.get('channel', None)
         channel = request_dict.get('channel', None)
         storeTime = request_dict.get('time', None)
         storeTime = request_dict.get('time', None)
         now_time = int(time.time())
         now_time = int(time.time())
-        vh_qs = VodHlsModel.objects.filter(uid=uid, channel=channel, time=int(storeTime), endTime__gte=now_time). \
+        vh_qs = VodHlsModel.objects.filter(uid=uid, channel=channel, time=storeTime, endTime__gte=now_time). \
             values("sec", "fg", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
             values("sec", "fg", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
         if not vh_qs.exists():
         if not vh_qs.exists():
-            return response.json()
+            return response.json(11,'不存在')
         sec = vh_qs[0]['sec']
         sec = vh_qs[0]['sec']
         fg = vh_qs[0]['fg']
         fg = vh_qs[0]['fg']
         bucket__region = vh_qs[0]['bucket__region']
         bucket__region = vh_qs[0]['bucket__region']
         bucket_name = vh_qs[0]['bucket__bucket']
         bucket_name = vh_qs[0]['bucket__bucket']
+        print(bucket__region)
+        print(bucket_name)
         aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
         aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
         aws_secret_access_key = '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'
         aws_secret_access_key = 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw'
         session = Session(
         session = Session(
@@ -225,7 +227,7 @@ class CloudStorageView(View):
         conn = session.client('s3')
         conn = session.client('s3')
         playlist_entries = []
         playlist_entries = []
         for i in range(fg):
         for i in range(fg):
-            thumbspng = '{uid}/vod{channel}/{time}/{i}.ts'. \
+            thumbspng = '{uid}/vod{channel}/{time}/ts{i}.ts'. \
                 format(uid=uid, channel=channel, time=storeTime, i=i)
                 format(uid=uid, channel=channel, time=storeTime, i=i)
             response_url = conn.generate_presigned_url(
             response_url = conn.generate_presigned_url(
                 'get_object',
                 'get_object',
@@ -242,10 +244,14 @@ class CloudStorageView(View):
                 'duration': 10,
                 'duration': 10,
             })
             })
         playlist = PlaylistGenerator(playlist_entries).generate()
         playlist = PlaylistGenerator(playlist_entries).generate()
-        response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl")
-        # response = HttpResponse(playlist, content_type="application/octet-stream")
+        response = HttpResponse(playlist)
+        response['Content-Type'] = 'application/octet-stream'
+        response['Content-Disposition'] = 'attachment;filename="play.m3u8"'
         return response
         return response
-        return HttpResponse(status=200, content=playlist)
+
+        # response = HttpResponse(playlist, content_type="application/vnd.apple.mpegurl")
+        # response = HttpResponse(playlist, content_type="application/octet-stream")
+        # return response
 
 
     def do_get_sign_sts(self, request_dict, ip, response):
     def do_get_sign_sts(self, request_dict, ip, response):
         uidToken = request_dict.get('uidToken', None)
         uidToken = request_dict.get('uidToken', None)
@@ -342,7 +348,7 @@ class CloudStorageView(View):
                         res = json.loads(sts_qs[0]["data"])
                         res = json.loads(sts_qs[0]["data"])
                         return JsonResponse(status=200, data=res)
                         return JsonResponse(status=200, data=res)
                     # 套餐id
                     # 套餐id
-                # storage = '{uid}/vod{channel}/'.format(uid=uid, channel=channel)
+                storage = '{uid}/vod{channel}/'.format(uid=uid, channel=channel)
                 bucket_name = ubqs[0]['bucket__bucket']
                 bucket_name = ubqs[0]['bucket__bucket']
                 endpoint = ubqs[0]['bucket__endpoint']
                 endpoint = ubqs[0]['bucket__endpoint']
                 region_id = ubqs[0]['bucket__region']
                 region_id = ubqs[0]['bucket__region']
@@ -355,7 +361,7 @@ class CloudStorageView(View):
                     aws_secret_access_key='ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw',
                     aws_secret_access_key='ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw',
                     region_name=REGION_NAME
                     region_name=REGION_NAME
                 )
                 )
-                print('----------test')
+                print('--------2--test')
                 print(REGION_NAME)
                 print(REGION_NAME)
                 Policy = {
                 Policy = {
                     "Version": "2012-10-17",
                     "Version": "2012-10-17",
@@ -363,8 +369,8 @@ class CloudStorageView(View):
                         {
                         {
                             "Effect": "Allow",
                             "Effect": "Allow",
                             "Action": "s3:*",
                             "Action": "s3:*",
-                            "Resource": ["arn:aws:s3:::{bucket_name}/{uid}/*".
-                                             format(bucket_name=bucket_name,uid=uid)]
+                            "Resource": ["arn:aws:s3:::{bucket_name}/{uid_channel}*".
+                                             format(bucket_name=bucket_name,uid_channel=storage)]
                         }
                         }
                     ]
                     ]
                 }
                 }
@@ -385,7 +391,7 @@ class CloudStorageView(View):
                     'bucket_name': bucket_name,
                     'bucket_name': bucket_name,
                     'arn': response['FederatedUser']['Arn'],
                     'arn': response['FederatedUser']['Arn'],
                     'code': 0,
                     'code': 0,
-                    'storage': uid,
+                    'storage': storage,
                     'endTime': ubqs[0]['endTime'],
                     'endTime': ubqs[0]['endTime'],
                     'ip': ip,
                     'ip': ip,
                 }
                 }
@@ -413,9 +419,11 @@ class CloudStorageView(View):
             (uid=uid, channel=channel, time__range=(startTime, endTime), endTime__gte=now_time). \
             (uid=uid, channel=channel, time__range=(startTime, endTime), endTime__gte=now_time). \
             values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
             values("time", "sec", "bucket__bucket", "bucket__endpoint", "bucket__region", "bucket__mold")
         vod_play_list = []
         vod_play_list = []
-        print("---")
+        print("-------------vh_qs")
         print(vh_qs)
         print(vh_qs)
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
         auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
+        print('--------------bigin')
+        print(int(time.time()))
         for vod in vh_qs:
         for vod in vh_qs:
             bucket__mold = vod["bucket__mold"]
             bucket__mold = vod["bucket__mold"]
             bucket_name = vod["bucket__bucket"]
             bucket_name = vod["bucket__bucket"]
@@ -437,35 +445,37 @@ class CloudStorageView(View):
                                         params={'x-oss-process': 'video/snapshot,t_10000,m_fast,w_300'})
                                         params={'x-oss-process': 'video/snapshot,t_10000,m_fast,w_300'})
                 vod_play_list.append({'name': vod['time'], 'sign_url': vod_play_url, 'thumb': thumb, 'sec': vod['sec']})
                 vod_play_list.append({'name': vod['time'], 'sign_url': vod_play_url, 'thumb': thumb, 'sec': vod['sec']})
             elif bucket__mold == 1:
             elif bucket__mold == 1:
-                aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
-                aws_secret_access_key = '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'
-                session = Session(
-                    aws_access_key_id=aws_access_key_id,
-                    aws_secret_access_key=aws_secret_access_key,
-                    region_name=bucket__region
-                )
-                conn = session.client('s3')
-                thumbspng = '{uid}/vod{channel}/{time}/thumbs.png'. \
-                    format(uid=uid, channel=channel, time=vod['time'])
-                response_url = conn.generate_presigned_url(
-                    'get_object',
-                    Params={
-                        'Bucket': bucket_name,
-                        'Key': thumbspng
-                    },
-                    ExpiresIn=3600
-                )
+                # aws_access_key_id = 'AKIA2E67UIMD45Y3HL53'
+                # aws_secret_access_key = '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'
+                # session = Session(
+                #     aws_access_key_id=aws_access_key_id,
+                #     aws_secret_access_key=aws_secret_access_key,
+                #     region_name=bucket__region
+                # )
+                # conn = session.client('s3')
+                # thumbspng = '{uid}/vod{channel}/{time}/thumbs.jpg'. \
+                #     format(uid=uid, channel=channel, time=vod['time'])
+                # response_url = conn.generate_presigned_url(
+                #     'get_object',
+                #     Params={
+                #         'Bucket': bucket_name,
+                #         'Key': thumbspng
+                #     },
+                #     ExpiresIn=3600
+                # )
+                # thumb_url = response_url
                 # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
                 # m3u8 = '{uid}/vod{channel}/{time}/{time}.m3u8'. \
                 #     format(uid=uid, channel=channel, time=vod['time'])
                 #     format(uid=uid, channel=channel, time=vod['time'])
-                thumb_url = response_url
-                vod_url = 'http://cloudstroage.dvema.com/cloudstorage/signplaym3u8?' \
+                vod_url = 'http://test.dvema.com/cloudstorage/signplaym3u8?' \
                           'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
                           'uid={uid}&channel={channel}&time={time}&sign=tktktktk'. \
                     format(uid=uid, channel=channel, time=vod['time'])
                     format(uid=uid, channel=channel, time=vod['time'])
                 vod_play_list.append({
                 vod_play_list.append({
                     'name': vod['time'],
                     'name': vod['time'],
                     'sign_url': vod_url,
                     'sign_url': vod_url,
-                    'thumb': thumb_url,
+                    # 'thumb': thumb_url,
                     'sec': vod['sec']})
                     'sec': vod['sec']})
+        print('--------------end')
+        print(int(time.time()))
         return response.json(0, vod_play_list)
         return response.json(0, vod_play_list)
 
 
     def do_store_playlist(self, request_dict, response):
     def do_store_playlist(self, request_dict, response):
@@ -667,7 +677,7 @@ class CloudStorageView(View):
     function payOKButton() {
     function payOKButton() {
         // 复杂数据
         // 复杂数据
         console.log('success')
         console.log('success')
-        window.webkit.messageHandlers.jsCallOC.postMessage({"status": 0});
+        window.location.href="https://www.baidu.com?page=closePage";
     }
     }
 	</script>
 	</script>
 </body> 
 </body> 
@@ -747,7 +757,7 @@ class CloudStorageView(View):
     function payOKButton() {
     function payOKButton() {
         // 复杂数据
         // 复杂数据
         console.log('success')
         console.log('success')
-        window.webkit.messageHandlers.jsCallOC.postMessage({"status": 1});
+        window.location.href="https://www.baidu.com?page=closePage"  
     }
     }
 	</script>
 	</script>
 </body> 
 </body> 
@@ -865,6 +875,8 @@ class CloudStorageView(View):
         pay_type = int(request_dict.get('pay_type', None))
         pay_type = int(request_dict.get('pay_type', None))
         rank = request_dict.get('rank', None)
         rank = request_dict.get('rank', None)
 
 
+        if uid == None or channel == None or commodity_code == None or pay_type == None or rank == None:
+            return response.json(13, '参数有误.')
         dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1)
         dv_qs = Device_Info.objects.filter(userID_id=userID, UID=uid, isShare=False, isExist=1)
         if not dv_qs.exists():
         if not dv_qs.exists():
             return response.json(12)
             return response.json(12)

+ 5 - 5
Controller/TestApi.py

@@ -684,7 +684,7 @@ class testView(View):
         #UserIdToken
         #UserIdToken
         tko = TokenObject()
         tko = TokenObject()
         res = tko.generate(
         res = tko.generate(
-            data={'userID': 158943604783713800138000, 'lang': 'cn', 'user': '13527261476', 'm_code': '123413243214'})
+            data={'userID': 158943594633713800138000, 'lang': 'cn', 'user': '597471180@qq.com', 'm_code': '123413243214'})
 
 
         #uidToken
         #uidToken
         # utko = UidTokenObject()
         # utko = UidTokenObject()
@@ -692,9 +692,9 @@ class testView(View):
         return JsonResponse(status=200, data=res,safe=False)
         return JsonResponse(status=200, data=res,safe=False)
 
 
     def test_upload_s3(self,request_dict):
     def test_upload_s3(self,request_dict):
-        aws_key = "ASIA2E67UIMDVVZU3A7S" #【你的 aws_access_key】
-        aws_secret = "Ug1IYux/NOeXsXBgkBfl4nHvsrFS31XU/OX9j9t8" # 【你的 aws_secret_key】
-        aws_session_token = "FwoGZXIvYXdzEFsaDMwiG7k0GXKFsXlU9iLjAa2rLSzefbz9B64d2UQJK3Nq1mK+YOoFK52Nr4CdLu/oHTt+dNTM+/tv372YLTi2MxCvhAhACEle2BiccEHSj9KFdh+gceYILEqHVpcXHldqrttknHpClu8gRLK6pGYojZ5gUcKZ5OA/rOQZPHaCIkY6cjnp5/qyBb87m6bhta6PljCba3pwaNQehy0gMNabZrukKMXt37kEjzfbI19lYozCVvb118AW1B6/abBTTST6ARZBsPfbzrvis5QOp4skdYrZwrYsBk1mbZVXSKo39+KV1KoMhncGQ2CRiG4+wnnMrWcmKMGk//wFMikzL7YaV8ZLkWKAurtKoo/D3EFnqNF/JmzAVMMX80rq9J8CuXKEtdDYkw=="
+        aws_key = "ASIA2E67UIMD454ZXCKZ" #【你的 aws_access_key】
+        aws_secret = "4zqyp4xEc7kf+RVPxHN4pw2G6o1zPEeZjCFvsQg5" # 【你的 aws_secret_key】
+        aws_session_token = "FwoGZXIvYXdzEHUaDNFT8HDNEJnDk7sHyiLoAd7WDsGQtulT19i8BDTPPdG3O3ALMiUs1d/Am5U9ooWo+TNVvkgdI7VN2gcIFP+Ib5QH4IA8ikpYDHC0bxckkZwrBp9EmrZpHgDPEl6tOdpkyVRmquf+a4BcC1794uhpXF40dm46B+FV1Rr61tG741JResI826CZ9oIKxhLcnkT6E0KFZ4WodaRzOswjZpUoYJf5Et+mGQdoOhKTdnwe/o3rbgZ7IcI0m3w6QrFL6M5gb1I8K0uzUwIKcxnvrjPLcQU6TwH002+J51GnygMs8rGGTxaKOuyVgovTx2YpLSj79itEnpQhM64ohvmE/QUyKdTiqfyqacYXV8WkoUEMnw+UkW8QeLFJqCwf77UhWN9zP+SBuC0hhW20"
         session = Session(aws_access_key_id=aws_key,
         session = Session(aws_access_key_id=aws_key,
                           aws_secret_access_key=aws_secret,
                           aws_secret_access_key=aws_secret,
                           aws_session_token=aws_session_token,
                           aws_session_token=aws_session_token,
@@ -703,7 +703,7 @@ class testView(View):
         client = session.client("s3")
         client = session.client("s3")
         bucket = "asj-oct-ipc" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
         bucket = "asj-oct-ipc" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
         upload_data = open("./././static/log/error.log", "rb")
         upload_data = open("./././static/log/error.log", "rb")
-        upload_key = "86YC8Z192VB1VMKU111A/test"
+        upload_key = "86YC8Z192VB1VMKU111A/vod1/test"
         file_obj = s3.Bucket(bucket).put_object(Key=upload_key, Body=upload_data)
         file_obj = s3.Bucket(bucket).put_object(Key=upload_key, Body=upload_data)
         print('--------')
         print('--------')
         print(file_obj)
         print(file_obj)