|
@@ -20,7 +20,7 @@ import oss2
|
|
import paypalrestsdk
|
|
import paypalrestsdk
|
|
from aliyunsdkcore import client
|
|
from aliyunsdkcore import client
|
|
from aliyunsdksts.request.v20150401 import AssumeRoleRequest
|
|
from aliyunsdksts.request.v20150401 import AssumeRoleRequest
|
|
-from django.http import JsonResponse,HttpResponseRedirect,HttpResponse
|
|
|
|
|
|
+from django.http import JsonResponse, HttpResponseRedirect, HttpResponse
|
|
from django.utils.decorators import method_decorator
|
|
from django.utils.decorators import method_decorator
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.generic.base import View
|
|
from django.views.generic.base import View
|
|
@@ -110,9 +110,103 @@ class CloudVodView(View):
|
|
return self.do_change_status(request_dict, userID, response)
|
|
return self.do_change_status(request_dict, userID, response)
|
|
elif operation == 'playlist':
|
|
elif operation == 'playlist':
|
|
return self.do_get_playlist(request_dict, userID, response)
|
|
return self.do_get_playlist(request_dict, userID, response)
|
|
|
|
+ elif operation == 'appSts':
|
|
|
|
+ return self.do_get_appSts(request_dict, userID, response)
|
|
|
|
+ elif operation == 'details':
|
|
|
|
+ return self.do_get_details(request_dict, userID, response)
|
|
else:
|
|
else:
|
|
return response.json(414)
|
|
return response.json(414)
|
|
|
|
|
|
|
|
+ def do_get_details(self, request_dict, userID, response):
|
|
|
|
+ did = request_dict.get('did', None)
|
|
|
|
+ dvqs = Device_Info.objects.filter(id=did).values('UID')
|
|
|
|
+ if not dvqs.exists():
|
|
|
|
+ return response.json(10, '设备不存在')
|
|
|
|
+ UID = dvqs[0]['UID']
|
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid=UID). \
|
|
|
|
+ values('bucket__content', 'status', 'channel', 'endTime', 'uid')
|
|
|
|
+ res = []
|
|
|
|
+ if ubqs.exists():
|
|
|
|
+ res = list(ubqs)
|
|
|
|
+ return response.json(0, res)
|
|
|
|
+
|
|
|
|
+ def do_get_appSts(self, request_dict, userID, response):
|
|
|
|
+ did = request_dict.get('id')
|
|
|
|
+ channel = request_dict.get('channel')
|
|
|
|
+ dvqs = Device_Info.objects.filter(userID_id=userID, id=did).values('UID')
|
|
|
|
+ if not dvqs.exists():
|
|
|
|
+ return response.json(10, '设备不属于')
|
|
|
|
+ UID = dvqs[0]['UID']
|
|
|
|
+ ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values('channel', 'bucket__bucket',
|
|
|
|
+ 'bucket__endpoint',
|
|
|
|
+ 'bucket__region', 'endTime')
|
|
|
|
+ now_time = CommonService.get_utc()
|
|
|
|
+ if not ubqs.exists():
|
|
|
|
+ return response.json(10, '未购买')
|
|
|
|
+ elif now_time > ubqs[0]['endTime']:
|
|
|
|
+ return response.json(10, '过期')
|
|
|
|
+ oc_qs = OssCrdModel.objects.filter(uid=UID, channel=channel).values("addTime", "data")
|
|
|
|
+ if oc_qs.exists():
|
|
|
|
+ endTime = int(oc_qs[0]["addTime"]) + 3500
|
|
|
|
+ if endTime > now_time:
|
|
|
|
+ res = json.loads(oc_qs[0]["data"])
|
|
|
|
+ return JsonResponse(status=200, data=res)
|
|
|
|
+ # 套餐id
|
|
|
|
+ storage = '{uid}/vod{channel}/'.format(uid=UID, channel=channel)
|
|
|
|
+ bucket_name = ubqs[0]['bucket__bucket']
|
|
|
|
+ endpoint = ubqs[0]['bucket__endpoint']
|
|
|
|
+ access_key_id = OSS_STS_ACCESS_KEY
|
|
|
|
+ access_key_secret = OSS_STS_ACCESS_SECRET
|
|
|
|
+ region_id = ubqs[0]['bucket__region']
|
|
|
|
+ role_arn = OSS_ROLE_ARN
|
|
|
|
+ clt = client.AcsClient(access_key_id, access_key_secret, region_id)
|
|
|
|
+ req = AssumeRoleRequest.AssumeRoleRequest()
|
|
|
|
+ # 设置返回值格式为JSON。
|
|
|
|
+ req.set_accept_format('json')
|
|
|
|
+ req.set_RoleArn(role_arn)
|
|
|
|
+ req.set_RoleSessionName(UID)
|
|
|
|
+ req.set_DurationSeconds(3600)
|
|
|
|
+ Resource_access = "acs:oss:*:*:{bucket_name}/{uid_channel}*".format(bucket_name=bucket_name,
|
|
|
|
+ uid_channel=storage)
|
|
|
|
+ print(Resource_access)
|
|
|
|
+ policys = {
|
|
|
|
+ "Version": "1",
|
|
|
|
+ "Statement": [
|
|
|
|
+ {
|
|
|
|
+ "Action": ["oss:PutObject", "oss:DeleteObject", ],
|
|
|
|
+ "Resource": [Resource_access],
|
|
|
|
+ "Effect": "Allow",
|
|
|
|
+ "Condition": {
|
|
|
|
+ # "IpAddress": {"acs:SourceIp": ip}
|
|
|
|
+ # "IpAddress": {"acs:SourceIp": "120.237.157.184"}
|
|
|
|
+ # "IpAddress": {"acs:SourceIp": "*"}
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ req.set_Policy(Policy=json.dumps(policys))
|
|
|
|
+ body = clt.do_action(req)
|
|
|
|
+ # 使用RAM账号的AccessKeyId和AccessKeySecret向STS申请临时token。
|
|
|
|
+ token = json.loads(body.decode('utf-8'))
|
|
|
|
+ print(token)
|
|
|
|
+ res = {
|
|
|
|
+ 'AccessKeyId': token['Credentials']['AccessKeyId'],
|
|
|
|
+ 'AccessKeySecret': token['Credentials']['AccessKeySecret'],
|
|
|
|
+ 'SecurityToken': token['Credentials']['SecurityToken'],
|
|
|
|
+ 'Expiration': token['Credentials']['Expiration'],
|
|
|
|
+ 'expire': '3600',
|
|
|
|
+ 'endpoint': endpoint,
|
|
|
|
+ 'bucket_name': bucket_name,
|
|
|
|
+ 'arn': token['AssumedRoleUser']['Arn'],
|
|
|
|
+ 'code': 0,
|
|
|
|
+ 'storage': storage}
|
|
|
|
+ # 'ip': ip}
|
|
|
|
+ if oc_qs.exists():
|
|
|
|
+ oc_qs.update(data=json.dumps(res), addTime=now_time)
|
|
|
|
+ else:
|
|
|
|
+ OssCrdModel.objects.create(uid=UID, channel=channel, data=json.dumps(res), addTime=now_time)
|
|
|
|
+ return JsonResponse(status=200, data=res)
|
|
|
|
+
|
|
def do_pay_error(self):
|
|
def do_pay_error(self):
|
|
response = HttpResponse()
|
|
response = HttpResponse()
|
|
response.content = '''
|
|
response.content = '''
|
|
@@ -248,14 +342,12 @@ class CloudVodView(View):
|
|
ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values('channel', 'bucket__bucket',
|
|
ubqs = UID_Bucket.objects.filter(uid=UID, channel=channel, status=1).values('channel', 'bucket__bucket',
|
|
'bucket__endpoint',
|
|
'bucket__endpoint',
|
|
'bucket__region', 'endTime')
|
|
'bucket__region', 'endTime')
|
|
- if not ubqs.exists():
|
|
|
|
- res = {'code': 403}
|
|
|
|
- return JsonResponse(status=200, data=res)
|
|
|
|
- # return response.json(10, '设备未购买')
|
|
|
|
now_time = CommonService.get_utc()
|
|
now_time = CommonService.get_utc()
|
|
- if now_time > ubqs[0]['endTime']:
|
|
|
|
- res = {'code': 403}
|
|
|
|
|
|
+ if not ubqs.exists():
|
|
|
|
+ res = {'code': 403, 'msg': '未购买'}
|
|
return JsonResponse(status=200, data=res)
|
|
return JsonResponse(status=200, data=res)
|
|
|
|
+ elif ubqs[0]['endTime'] < now_time:
|
|
|
|
+ return JsonResponse(status=200, data={'code': 403, 'msg': '过期'})
|
|
now_time_stamp = CommonService.get_utc()
|
|
now_time_stamp = CommonService.get_utc()
|
|
oc_qs = OssCrdModel.objects.filter(uid=UID, channel=channel).values("addTime", "data")
|
|
oc_qs = OssCrdModel.objects.filter(uid=UID, channel=channel).values("addTime", "data")
|
|
if oc_qs.exists():
|
|
if oc_qs.exists():
|
|
@@ -438,7 +530,6 @@ class CloudVodView(View):
|
|
red_url = "{SERVER_DOMAIN}cloudVod/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
red_url = "{SERVER_DOMAIN}cloudVod/payOK".format(SERVER_DOMAIN=SERVER_DOMAIN)
|
|
return HttpResponseRedirect(red_url)
|
|
return HttpResponseRedirect(red_url)
|
|
|
|
|
|
-
|
|
|
|
def do_change_status(self, request_dict, userID, response):
|
|
def do_change_status(self, request_dict, userID, response):
|
|
did = request_dict.get('did', None)
|
|
did = request_dict.get('did', None)
|
|
status = request_dict.get('status', None)
|
|
status = request_dict.get('status', None)
|
|
@@ -456,6 +547,8 @@ class CloudVodView(View):
|
|
if now_time > ubqs[0].endTime:
|
|
if now_time > ubqs[0].endTime:
|
|
return response.json(10, '已过期')
|
|
return response.json(10, '已过期')
|
|
ubqs.update(status=status)
|
|
ubqs.update(status=status)
|
|
|
|
+ if status == 0:
|
|
|
|
+ return response.json(0)
|
|
utko = UidTokenObject()
|
|
utko = UidTokenObject()
|
|
utko.generate(data={'uid': UID, 'channel': channel})
|
|
utko.generate(data={'uid': UID, 'channel': channel})
|
|
uidTkUrl = "{SERVER_DOMAIN}cloudVod/getSts?uidToken={uidToken}". \
|
|
uidTkUrl = "{SERVER_DOMAIN}cloudVod/getSts?uidToken={uidToken}". \
|