|
@@ -15,6 +15,7 @@ import json
|
|
|
import time
|
|
|
import urllib
|
|
|
import uuid
|
|
|
+import hashlib
|
|
|
|
|
|
import boto3
|
|
|
import oss2
|
|
@@ -38,6 +39,7 @@ from Service.CommonService import CommonService
|
|
|
from Object.m3u8generate import PlaylistGenerator
|
|
|
from Object.WechatPayObject import WechatPayObject
|
|
|
from django.db.models import Q
|
|
|
+from django.http import StreamingHttpResponse
|
|
|
|
|
|
SERVER_DOMAIN = 'http://test.dvema.com/'
|
|
|
|
|
@@ -67,6 +69,8 @@ class CDKView(View):
|
|
|
return self.saveOrEditCDKform(request_dict, response)
|
|
|
elif operation == 'saveOrEditCDK':
|
|
|
return self.saveOrEditCDK(request_dict, response)
|
|
|
+ elif operation == 'downloadCDK':
|
|
|
+ return self.downloadCDK(response)
|
|
|
|
|
|
if operation is None:
|
|
|
return response.json(444, 'error path')
|
|
@@ -86,8 +90,9 @@ class CDKView(View):
|
|
|
cdk_list = []
|
|
|
for i in range(int(cdk_num)):
|
|
|
nowTime = int(time.time())
|
|
|
+ cdk = hashlib.md5((str(uuid.uuid1()) + str(nowTime)).encode('utf-8')).hexdigest()
|
|
|
cdk_model = CDKcontextModel(
|
|
|
- cdk=uuid.uuid1(),
|
|
|
+ cdk=cdk,
|
|
|
create_time=nowTime,
|
|
|
valid_time=0,
|
|
|
is_activate=0,
|
|
@@ -99,7 +104,7 @@ class CDKView(View):
|
|
|
CDKcontextModel.objects.bulk_create(cdk_list)
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
- return response.json(404, repr(e))
|
|
|
+ return response.json(500, repr(e))
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
|
|
@@ -153,7 +158,8 @@ class CDKView(View):
|
|
|
try:
|
|
|
CDKcontextModel.objects.get(id=cdk_id).delete()
|
|
|
except Exception as e:
|
|
|
- return response.json(404, repr(e))
|
|
|
+ print(e)
|
|
|
+ return response.json(500, repr(e))
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
|
|
@@ -178,6 +184,24 @@ class CDKView(View):
|
|
|
update_dict['rank'] = rank
|
|
|
CDKcontextModel.objects.filter(id=cdk_id).update(**update_dict)
|
|
|
except Exception as e:
|
|
|
- return response.json(404, repr(e))
|
|
|
+ return response.json(500, repr(e))
|
|
|
else:
|
|
|
return response.json(0)
|
|
|
+
|
|
|
+ def downloadCDK(self, response):
|
|
|
+ content = ''
|
|
|
+ cdk_inactivate_qs = CDKcontextModel.objects.filter(is_activate=0).values('cdk')
|
|
|
+ content += '激活码\n'
|
|
|
+ for cdk_inactivate in cdk_inactivate_qs:
|
|
|
+ content += cdk_inactivate['cdk'] + '\n'
|
|
|
+ print(content)
|
|
|
+
|
|
|
+ response = StreamingHttpResponse(content)
|
|
|
+ response['Content-Type'] = 'application/octet-stream'
|
|
|
+ response['Content-Disposition'] = 'attachment;filename="CDK.txt"'
|
|
|
+ return response
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|