|
@@ -17,6 +17,7 @@ from django.views.decorators.csrf import csrf_exempt
|
|
|
# from Ansjer.settings import *
|
|
|
from django.contrib import auth
|
|
|
from django.http import HttpResponseRedirect
|
|
|
+
|
|
|
'''
|
|
|
http://192.168.136.40:8077/Test
|
|
|
'''
|
|
@@ -29,9 +30,9 @@ from ratelimit.decorators import ratelimit
|
|
|
from Object.ResponseObject import ResponseObject
|
|
|
from Object.TokenObject import TokenObject
|
|
|
from Object.RedisObject import RedisObject
|
|
|
-from django.shortcuts import render_to_response,render,redirect
|
|
|
+from django.shortcuts import render_to_response, render, redirect
|
|
|
import paypalrestsdk
|
|
|
-from django.http import HttpResponseRedirect,HttpResponse
|
|
|
+from django.http import HttpResponseRedirect, HttpResponse
|
|
|
|
|
|
|
|
|
class Test(View):
|
|
@@ -51,8 +52,82 @@ class Test(View):
|
|
|
'''
|
|
|
/Test?paymentId=PAY-4VL25365CA733482BLPMAHBI&token=EC-1SU951197H0006730&PayerID=A29TCMY2J8G9C
|
|
|
'''
|
|
|
+
|
|
|
@ratelimit(key='ip', rate='1/m')
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
+ # 阿里云oss测试
|
|
|
+ return self.ossCrd()
|
|
|
+ # 七牛测试
|
|
|
+ return self.qiniutokentest()
|
|
|
+ # paypal测试
|
|
|
+ return self.paypaytest(request)
|
|
|
+
|
|
|
+ # 增加
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
+ response = ResponseObject()
|
|
|
+ return response.json(0)
|
|
|
+
|
|
|
+ def ossCrd(self):
|
|
|
+ '''
|
|
|
+ 生成sts上传授权
|
|
|
+ '''
|
|
|
+ from aliyunsdkcore import client
|
|
|
+ from aliyunsdksts.request.v20150401 import AssumeRoleRequest
|
|
|
+ import json
|
|
|
+ import oss2
|
|
|
+ # Endpoint以杭州为例,其它egion请按实际情况填写。
|
|
|
+ endpoint = 'oss-cn-shenzhen.aliyuncs.com'
|
|
|
+ # 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
|
|
|
+ # access_key_id = 'LTAIXSozepSx81xe'
|
|
|
+ # access_key_secret = '19BlxRiAHDPLx4mhz6vQZRuhK0eKed'
|
|
|
+ access_key_id = 'LTAIKF7ohvwF5ugH'
|
|
|
+ access_key_secret = 'AfBIeMdrvMN3m0EsQYuRkmNyA7uWoz'
|
|
|
+ bucket_name = 'testrtmp'
|
|
|
+ # role_arn是角色的资源名称。
|
|
|
+ role_arn = 'acs:ram::1024237323330331:role/maxadmin'
|
|
|
+
|
|
|
+ clt = client.AcsClient(access_key_id, access_key_secret, 'cn-shenzhen')
|
|
|
+ req = AssumeRoleRequest.AssumeRoleRequest()
|
|
|
+
|
|
|
+ # 设置返回值格式为JSON。
|
|
|
+ req.set_accept_format('json')
|
|
|
+ req.set_RoleArn(role_arn)
|
|
|
+ req.set_RoleSessionName('chanjunkai')
|
|
|
+ req.set_DurationSeconds(3600)
|
|
|
+ policys = {
|
|
|
+ "Version": "1",
|
|
|
+ "Statement": [
|
|
|
+ {
|
|
|
+ "Action": [
|
|
|
+ "oss:PutObject",
|
|
|
+ ],
|
|
|
+ "Resource": ["acs:oss:*:*:testrtmp/*"],
|
|
|
+ "Effect": "Allow",
|
|
|
+ "Condition": {
|
|
|
+ "IpAddress": {
|
|
|
+ "acs:SourceIp": "120.237.157.184"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ req.set_Policy(Policy=json.dumps(policys))
|
|
|
+ body = clt.do_action(req)
|
|
|
+ # body = clt.do_action_with_exception(req)
|
|
|
+ # 使用RAM账号的AccessKeyId和AccessKeySecret向STS申请临时token。
|
|
|
+ token = json.loads(body)
|
|
|
+ print(token)
|
|
|
+ res={
|
|
|
+ 'AccessKeyId':token['Credentials']['AccessKeyId'],
|
|
|
+ 'AccessKeySecret':token['Credentials']['AccessKeySecret'],
|
|
|
+ 'SecurityToken':token['Credentials']['SecurityToken'],
|
|
|
+ 'expire':3600,
|
|
|
+ 'endpoint':endpoint,
|
|
|
+ 'bucket_name':bucket_name
|
|
|
+ }
|
|
|
+ return JsonResponse(status=200,data=res)
|
|
|
+
|
|
|
+ def qiniutokentest(self):
|
|
|
# flake8: noqa
|
|
|
from qiniu import Auth
|
|
|
# 需要填写你的 Access Key 和 Secret Key
|
|
@@ -75,24 +150,20 @@ class Test(View):
|
|
|
# 3600为token过期时间,秒为单位。3600等于一小时
|
|
|
token = q.upload_token(bucket_name, key, 3600, policy)
|
|
|
print(token)
|
|
|
- return HttpResponse(content=token,status=200)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ return HttpResponse(content=token, status=200)
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- '''
|
|
|
-
|
|
|
- :param request:
|
|
|
- :param args:
|
|
|
- :param kwargs:
|
|
|
- :return:
|
|
|
+ def paypaytest(self, request):
|
|
|
'''
|
|
|
+
|
|
|
+ :param request:
|
|
|
+ :param args:
|
|
|
+ :param kwargs:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
response = ResponseObject()
|
|
|
# return response.json(0)
|
|
|
- paymentId = request.GET.get('paymentId',None)
|
|
|
- PayerID = request.GET.get('PayerID',None)
|
|
|
+ paymentId = request.GET.get('paymentId', None)
|
|
|
+ PayerID = request.GET.get('PayerID', None)
|
|
|
if paymentId and PayerID:
|
|
|
paypalrestsdk.configure({
|
|
|
"mode": "sandbox", # sandbox or live
|
|
@@ -149,11 +220,6 @@ class Test(View):
|
|
|
print("Redirect for approval: %s" % (approval_url))
|
|
|
return HttpResponseRedirect(approval_url)
|
|
|
|
|
|
- # 增加
|
|
|
- def post(self, request, *args, **kwargs):
|
|
|
- response = ResponseObject()
|
|
|
- return response.json(0)
|
|
|
-
|
|
|
# 修改 资源改变
|
|
|
def put(self, request):
|
|
|
response = ResponseObject()
|