|
@@ -12,51 +12,38 @@
|
|
@Contact: chanjunkai@163.com
|
|
@Contact: chanjunkai@163.com
|
|
"""
|
|
"""
|
|
import botocore
|
|
import botocore
|
|
-from django.db import transaction
|
|
|
|
-from django.views.generic.base import View
|
|
|
|
-import os
|
|
|
|
-
|
|
|
|
|
|
+from botocore import client
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
from Controller.DeviceConfirmRegion import Device_Region
|
|
|
|
+from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
|
|
|
'''
|
|
'''
|
|
http://192.168.136.40:8077/Test
|
|
http://192.168.136.40:8077/Test
|
|
'''
|
|
'''
|
|
import json
|
|
import json
|
|
-import math
|
|
|
|
import time
|
|
import time
|
|
import urllib
|
|
import urllib
|
|
-import datetime
|
|
|
|
from Object.AliPayObject import AliPayObject
|
|
from Object.AliPayObject import AliPayObject
|
|
-import logging
|
|
|
|
import boto3
|
|
import boto3
|
|
from boto3.session import Session
|
|
from boto3.session import Session
|
|
-from botocore.exceptions import ClientError
|
|
|
|
import oss2
|
|
import oss2
|
|
import paypalrestsdk
|
|
import paypalrestsdk
|
|
import logging
|
|
import logging
|
|
-import requests
|
|
|
|
-import hashlib
|
|
|
|
-import hmac
|
|
|
|
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, 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
|
|
-from Object.RedisObject import RedisObject
|
|
|
|
-from django.contrib.auth.hashers import make_password, check_password # 对密码加密模块
|
|
|
|
-from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, SERVER_DOMAIN, PAYPAL_CRD, \
|
|
|
|
- SERVER_DOMAIN_SSL, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, SERVER_TYPE
|
|
|
|
-from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, CompanySerialModel, \
|
|
|
|
- SerialNumberModel, CompanyModel, VPGModel, Unused_Uid_Meal, StsCrdModel, ExperienceContextModel, DeviceLogModel
|
|
|
|
|
|
+from django.contrib.auth.hashers import make_password # 对密码加密模块
|
|
|
|
+from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_ARN, AWS_ACCESS_KEY_ID, \
|
|
|
|
+ AWS_SECRET_ACCESS_KEY, SERVER_TYPE, AWS_SES_ACCESS_REGION
|
|
|
|
+from Model.models import Order_Model, Store_Meal, VodHlsModel, OssCrdModel, StsCrdModel, DeviceLogModel
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
-from Object.UidTokenObject import UidTokenObject
|
|
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
-from Service.ModelService import ModelService
|
|
|
|
from Object.m3u8generate import PlaylistGenerator
|
|
from Object.m3u8generate import PlaylistGenerator
|
|
-from Model.models import Device_User, Device_Info, UID_Bucket, UID_Preview, UidSetModel, UidPushModel
|
|
|
|
-from Ansjer.config import PAYPAL_CRD, SERVER_DOMAIN, SERVER_DOMAIN_SSL, PAYPAL_WEB_HOOK_ID
|
|
|
|
|
|
+from Model.models import Device_Info, UID_Bucket, UID_Preview, UidSetModel
|
|
|
|
+from Ansjer.config import SERVER_DOMAIN_SSL
|
|
|
|
|
|
SERVER_DOMAIN = 'http://test.dvema.com/'
|
|
SERVER_DOMAIN = 'http://test.dvema.com/'
|
|
ACCESS_KEY = "AKIA2E67UIMD3CYTIWPA"
|
|
ACCESS_KEY = "AKIA2E67UIMD3CYTIWPA"
|
|
@@ -142,9 +129,124 @@ class testView(View):
|
|
return self.do_comb(request_dict, response)
|
|
return self.do_comb(request_dict, response)
|
|
elif operation == 'count_ts':
|
|
elif operation == 'count_ts':
|
|
return self.count_ts(request_dict, response)
|
|
return self.count_ts(request_dict, response)
|
|
|
|
+ elif operation == 'upload-s3':
|
|
|
|
+ return self.file_upload_s3(request, request_dict, response)
|
|
|
|
+ elif operation == 'v2/upload-s3':
|
|
|
|
+ return self.file_upload_s3_v2(request, request_dict, response)
|
|
|
|
+ elif operation == 'download-s3':
|
|
|
|
+ return self.file_download_s3(request_dict, response)
|
|
|
|
+ elif operation == 'acl-put':
|
|
|
|
+ return self.s3_acl_put(request_dict, response)
|
|
|
|
+ elif operation == 's3-object-delete':
|
|
|
|
+ return self.object_delete(request_dict, response)
|
|
|
|
+ elif operation == 'head-bucket':
|
|
|
|
+ return self.head_bucket(request_dict, response)
|
|
else:
|
|
else:
|
|
return 123
|
|
return 123
|
|
|
|
|
|
|
|
+ @classmethod
|
|
|
|
+ def head_bucket(cls, request_dict, response):
|
|
|
|
+ bucket_name = request_dict.get('bucket', None)
|
|
|
|
+ s3 = AmazonS3Util('AKIA2E67UIMD45Y3HL53', 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw', 'us-east-1')
|
|
|
|
+ s3.bucket_exists(bucket_name)
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def file_upload_s3(cls, request, request_dict, response):
|
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
|
+ file_name = file.name
|
|
|
|
+ file_name = 'app/images/{}'.format(file_name)
|
|
|
|
+ cls.upload_s3(file, file_name)
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def file_upload_s3_v2(cls, request, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 'private' | 'public-read' | 'public-read-write' | 'authenticated-read'
|
|
|
|
+ """
|
|
|
|
+ file = request.FILES.get('file', None)
|
|
|
|
+ file_name = file.name
|
|
|
|
+ # S3下文件夹路径+文件名 组成对象key
|
|
|
|
+ file_key = 'app/images/{}'.format(file_name)
|
|
|
|
+ s3 = AmazonS3Util(AWS_ACCESS_KEY_ID[1], AWS_SECRET_ACCESS_KEY[1], AWS_SES_ACCESS_REGION)
|
|
|
|
+ # 存储桶
|
|
|
|
+ bucket = 'ansjerfilemanager'
|
|
|
|
+ s3.upload_file_obj(bucket, file_key, file, {'ContentType': file.content_type, 'ACL': 'public-read'})
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def object_delete(cls, request_dict, response):
|
|
|
|
+ file_name = request_dict.get('key', None)
|
|
|
|
+ file_key = 'app/images/{}'.format(file_name)
|
|
|
|
+ s3 = AmazonS3Util('AKIA2E67UIMD45Y3HL53', 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw', 'us-east-1')
|
|
|
|
+ bucket = "ansjerfilemanager"
|
|
|
|
+ s3.delete_obj(bucket, file_key)
|
|
|
|
+ return response.json(0)
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def upload_s3(data, upload_path):
|
|
|
|
+ """
|
|
|
|
+ 上传对象到对应存储桶
|
|
|
|
+ @param data:
|
|
|
|
+ @param upload_path:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ aws_key = "AKIA2E67UIMD45Y3HL53" # 【你的 aws_access_key】
|
|
|
|
+ aws_secret = "ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw" # 【你的 aws_secret_key】
|
|
|
|
+ session = Session(aws_access_key_id=aws_key,
|
|
|
|
+ aws_secret_access_key=aws_secret,
|
|
|
|
+ region_name="us-east-1")
|
|
|
|
+ s3 = session.resource("s3")
|
|
|
|
+ # client = session.client("s3")
|
|
|
|
+ bucket = "ansjerfilemanager" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
|
|
|
|
+ # upload_key = "test"
|
|
|
|
+ s3.Bucket(bucket).put_object(Key=upload_path, Body=data)
|
|
|
|
+ return True
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(repr(e))
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def s3_acl_put(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ S3通过存储桶对象设置Acl权限
|
|
|
|
+ @param request_dict:
|
|
|
|
+ @param response:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ key = request_dict.get('key', None)
|
|
|
|
+ aws_key = "AKIA2E67UIMD45Y3HL53" # 【你的 aws_access_key】
|
|
|
|
+ aws_secret = "ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw" # 【你的 aws_secret_key】
|
|
|
|
+ session = Session(aws_access_key_id=aws_key,
|
|
|
|
+ aws_secret_access_key=aws_secret,
|
|
|
|
+ region_name="us-east-1")
|
|
|
|
+ s3 = session.resource("s3")
|
|
|
|
+ # client = session.client("s3")
|
|
|
|
+ bucket = "ansjerfilemanager" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
|
|
|
|
+ # upload_key = "test"
|
|
|
|
+ obj = s3.Object(bucket, key)
|
|
|
|
+ obj.Acl().put(ACL='public-read')
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(repr(e))
|
|
|
|
+ return False
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def file_download_s3(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ S3通过签名获取对象URL
|
|
|
|
+ @param request_dict:
|
|
|
|
+ @param response:
|
|
|
|
+ @return:
|
|
|
|
+ """
|
|
|
|
+ key = request_dict.get('key', None)
|
|
|
|
+ s3_client = AmazonS3Util('AKIA2E67UIMD45Y3HL53', 'ckYLg4Lo9ZXJIcJEAKkzf2rWvs8Xth1FCjqiAqUw', 'us-east-1')
|
|
|
|
+ bucket = "ansjerfilemanager"
|
|
|
|
+ response_url = s3_client.generate_file_obj_url(bucket, key)
|
|
|
|
+ return response.json(0, response_url)
|
|
|
|
+
|
|
def do_comb(self, request_dict, response):
|
|
def do_comb(self, request_dict, response):
|
|
import itertools
|
|
import itertools
|
|
list1 = [1, 2, 3, 4]
|
|
list1 = [1, 2, 3, 4]
|
|
@@ -164,7 +266,6 @@ class testView(View):
|
|
return HttpResponse(json.dumps(list3))
|
|
return HttpResponse(json.dumps(list3))
|
|
|
|
|
|
def findPaypalOrder(self, request_dict, response):
|
|
def findPaypalOrder(self, request_dict, response):
|
|
- from paypalrestsdk import Order, ResourceNotFound
|
|
|
|
PAYPAL_CRD = {
|
|
PAYPAL_CRD = {
|
|
"mode": "sandbox", # sandbox or live
|
|
"mode": "sandbox", # sandbox or live
|
|
"client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
|
|
"client_id": "AVLoQVq3xHZ6FrF4mxHwlCPgVBAw4Fw5RtMkuxmYd23SkUTIY643n2g3KdK-Al8wV05I28lza5uoQbAA",
|
|
@@ -875,6 +976,8 @@ class testView(View):
|
|
sumSec += (fg >> shift) & 0xf
|
|
sumSec += (fg >> shift) & 0xf
|
|
size = 0
|
|
size = 0
|
|
return HttpResponse(
|
|
return HttpResponse(
|
|
- "{year}年{month}月 </br>上传的TS总数:{sumTs} </br> 总秒数:{sumSec} </br> 总大小:{size}GB (1秒约等150KB计算)".format(year=year, month=month,
|
|
|
|
- sumTs=sumTs, sumSec=sumSec,
|
|
|
|
- size=size))
|
|
|
|
|
|
+ "{year}年{month}月 </br>上传的TS总数:{sumTs} </br> 总秒数:{sumSec} </br> 总大小:{size}GB (1秒约等150KB计算)".format(year=year,
|
|
|
|
+ month=month,
|
|
|
|
+ sumTs=sumTs,
|
|
|
|
+ sumSec=sumSec,
|
|
|
|
+ size=size))
|