|
@@ -1,5 +1,5 @@
|
|
|
-#!/usr/bin/env python3
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
+#!/usr/bin/env python3
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
"""
|
|
|
@Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
|
|
|
@AUTHOR: ASJRD018
|
|
@@ -12,218 +12,49 @@
|
|
|
@Contact: chanjunkai@163.com
|
|
|
"""
|
|
|
from django.views.generic.base import View
|
|
|
-from django.utils.decorators import method_decorator
|
|
|
-from django.views.decorators.csrf import csrf_exempt
|
|
|
-from django.contrib import auth
|
|
|
-from django.http import HttpResponseRedirect
|
|
|
|
|
|
'''
|
|
|
http://192.168.136.40:8077/Test
|
|
|
'''
|
|
|
-import json
|
|
|
-import requests
|
|
|
-from Service.ModelService import ModelService
|
|
|
-from django.middleware.csrf import get_token
|
|
|
-from django.http import JsonResponse
|
|
|
-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
|
|
|
-import paypalrestsdk
|
|
|
-from django.http import HttpResponseRedirect, HttpResponse
|
|
|
-
|
|
|
+from Ansjer.config import BASE_DIR
|
|
|
|
|
|
# 测试接口sdk
|
|
|
class Test(View):
|
|
|
- '''
|
|
|
- limit=10:指定返回记录的数量
|
|
|
- offset=10:指定返回记录的开始位置。
|
|
|
- page=2&per_page=100:指定第几页,以及每页的记录数。
|
|
|
- sortby=name&order=asc:指定返回结果按照哪个属性排序,以及排序顺序。
|
|
|
- animal_type_id=1:指定筛选条件
|
|
|
- '''
|
|
|
-
|
|
|
- # @method_decorator(csrf_exempt)
|
|
|
- # def dispatch(self, *args, **kwargs):
|
|
|
- # return super(Test, self).dispatch(*args, **kwargs)
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
response = ResponseObject()
|
|
|
- return response.json(474)
|
|
|
- return self.updatePrimaryMaster()
|
|
|
- # 增加
|
|
|
+ from alipay import AliPay, ISVAliPay
|
|
|
+ app_private_key_string = open(BASE_DIR + '/Controller/alipay_private_2048.pem').read()
|
|
|
+ alipay_public_key_string = open(BASE_DIR + '/Controller/alipay_public_2048.pem').read()
|
|
|
+ alipay = AliPay(
|
|
|
+ appid="2016092200569234",
|
|
|
+ app_notify_url=None, # the default notify path
|
|
|
+ app_private_key_string=app_private_key_string,
|
|
|
+ # alipay public key, do not use your own public key!
|
|
|
+ alipay_public_key_string=alipay_public_key_string,
|
|
|
+ sign_type="RSA", # RSA or RSA2
|
|
|
+ debug=False # False by default
|
|
|
+ )
|
|
|
+ order_string = alipay.api_alipay_trade_wap_pay(
|
|
|
+ out_trade_no="20161112",
|
|
|
+ total_amount=0.01,
|
|
|
+ subject="实用性充气版玩具",
|
|
|
+ return_url="http://example.com",
|
|
|
+ notify_url="https://example.com/notify" # this is optional
|
|
|
+ )
|
|
|
+ print(order_string)
|
|
|
+ from django.http import HttpResponseRedirect
|
|
|
+ # return response.json(0,"https://openapi.alipay.com/gateway.do? + {order_string}".format(order_string=order_string))
|
|
|
+ print(order_string)
|
|
|
+ return HttpResponseRedirect("https://openapi.alipaydev.com/gateway.do?"+order_string)
|
|
|
+ return response.json(0,)
|
|
|
+ # 增加
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
response = ResponseObject()
|
|
|
return response.json(0)
|
|
|
|
|
|
- def updatePrimaryMaster(self):
|
|
|
- from Model.models import Device_Info, Device_User
|
|
|
- qs = Device_Info.objects.filter(isShare=True, primaryMaster='').values('primaryUserID', 'id')
|
|
|
- for i in qs:
|
|
|
- user_qs = Device_User.objects.filter(userID=i['primaryUserID'])
|
|
|
- if user_qs:
|
|
|
- is_update = Device_Info.objects.filter(id=i['id']).update(primaryMaster=user_qs[0].username)
|
|
|
- print(is_update)
|
|
|
- return HttpResponse(status=200, content='1234')
|
|
|
-
|
|
|
- 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 = 'LTAIyMkGfEdogyL9'
|
|
|
- access_key_secret = '71uIjpsqVOmF7DAITRyRuc259jHOjO'
|
|
|
- bucket_name = 'cloudvod1'
|
|
|
- # role_arn是角色的资源名称。
|
|
|
- role_arn = 'acs:ram::1901342792446414:role/stsoss'
|
|
|
-
|
|
|
- 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",
|
|
|
- "oss:DeleteObject",
|
|
|
- ],
|
|
|
- "Resource": ["acs:oss:*:*:cloudvod1/*"],
|
|
|
- "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'],
|
|
|
- 'Expiration': token['Credentials']['Expiration'],
|
|
|
- 'expire': '3600',
|
|
|
- 'endpoint': endpoint,
|
|
|
- 'bucket_name': bucket_name,
|
|
|
- 'arn': token['AssumedRoleUser']['Arn']
|
|
|
- }
|
|
|
- return JsonResponse(status=200, data=res)
|
|
|
-
|
|
|
- def qiniutokentest(self):
|
|
|
- # flake8: noqa
|
|
|
- from qiniu import Auth
|
|
|
- # 需要填写你的 Access Key 和 Secret Key
|
|
|
- access_key = 'dwdHw1pQ9wFNiHDdflBUiZyWmiLppd5VCC2yF0O_'
|
|
|
- secret_key = 'uTn7hdKD9Mbf2dzMWjLj2e9V1nXN7HAsOGRKwqDF'
|
|
|
- # 构建鉴权对象
|
|
|
- q = Auth(access_key, secret_key)
|
|
|
- # 要上传的空间
|
|
|
- bucket_name = 'test'
|
|
|
- # 上传到七牛后保存的文件名
|
|
|
- key = '/*'
|
|
|
- # 生成上传 Token,可以指定过期时间等
|
|
|
- # 上传策略示例
|
|
|
- # https://developer.qiniu.com/kodo/manual/1206/put-policy
|
|
|
- policy = {
|
|
|
- # 'callbackUrl':'https://requestb.in/1c7q2d31',
|
|
|
- # 'callbackBody':'filename=$(fname)&filesize=$(fsize)'
|
|
|
- # 'persistentOps':'imageView2/1/w/200/h/200'
|
|
|
- }
|
|
|
- # 3600为token过期时间,秒为单位。3600等于一小时
|
|
|
- token = q.upload_token(bucket_name, key, 3600, policy)
|
|
|
- print(token)
|
|
|
- return HttpResponse(content=token, status=200)
|
|
|
-
|
|
|
- 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)
|
|
|
- if paymentId and PayerID:
|
|
|
- paypalrestsdk.configure({
|
|
|
- "mode": "sandbox", # sandbox or live
|
|
|
- "client_id": "AfnfDqezODOoWGS-W2Itu-Zl1ay1R95IsGlMqPghPA3KGhkPndNMnQT0bdEewvSv92XAFIfLiinmyhBL",
|
|
|
- "client_secret": "EErLskwYA1xXY3890mHx5OhzgK83B2rNc57zIozGNyKc8i6RJuhPTF9WyhhdZgyDEih0heo1MH9Jk1lj"
|
|
|
- })
|
|
|
- # ID of the payment. This ID is provided when creating payment.
|
|
|
- payment = paypalrestsdk.Payment.find(paymentId)
|
|
|
- payres = payment.execute({"payer_id": PayerID})
|
|
|
- print(payres)
|
|
|
- if payres:
|
|
|
- print("Payment execute successfully")
|
|
|
- else:
|
|
|
- print(payment.error) # Error Hash
|
|
|
- return response.json(0)
|
|
|
- else:
|
|
|
- pass
|
|
|
- paypalrestsdk.configure({
|
|
|
- "mode": "sandbox", # sandbox or live
|
|
|
- "client_id": "AfnfDqezODOoWGS-W2Itu-Zl1ay1R95IsGlMqPghPA3KGhkPndNMnQT0bdEewvSv92XAFIfLiinmyhBL",
|
|
|
- "client_secret": "EErLskwYA1xXY3890mHx5OhzgK83B2rNc57zIozGNyKc8i6RJuhPTF9WyhhdZgyDEih0heo1MH9Jk1lj"})
|
|
|
-
|
|
|
- payment = paypalrestsdk.Payment({
|
|
|
- "intent": "sale",
|
|
|
- "payer": {
|
|
|
- "payment_method": "paypal"},
|
|
|
- "redirect_urls": {
|
|
|
- # "return_url": "http://192.168.136.45:3000/payment/execute",
|
|
|
- "return_url": "http://192.168.136.40:8077/Test",
|
|
|
- "cancel_url": "http://localhost:3000/"},
|
|
|
- "transactions": [{
|
|
|
- "item_list": {
|
|
|
- "items": [{
|
|
|
- "name": "item",
|
|
|
- "sku": "item",
|
|
|
- "price": "5.00",
|
|
|
- "currency": "USD",
|
|
|
- "quantity": 1}]},
|
|
|
- "amount": {
|
|
|
- "total": "5.00",
|
|
|
- "currency": "USD"},
|
|
|
- "description": "This is the payment transaction description."}]})
|
|
|
-
|
|
|
- if payment.create():
|
|
|
- print("Payment created successfully")
|
|
|
- else:
|
|
|
- print(payment.error)
|
|
|
- print(payment)
|
|
|
- for link in payment.links:
|
|
|
- if link.rel == "approval_url":
|
|
|
- # Convert to str to avoid Google App Engine Unicode issue
|
|
|
- # https://github.com/paypal/rest-api-sdk-python/pull/58
|
|
|
- approval_url = str(link.href)
|
|
|
- print("Redirect for approval: %s" % (approval_url))
|
|
|
- return HttpResponseRedirect(approval_url)
|
|
|
-
|
|
|
# 修改 资源改变
|
|
|
def put(self, request):
|
|
|
response = ResponseObject()
|