#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved. @AUTHOR: ASJRD018 @NAME: Ansjer @software: PyCharm @DATE: 2018/5/22 13:58 @Version: python3.6 @MODIFY DECORD:ansjer dev @file: Test.py @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 Ansjer.settings import * 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 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) # 查询 ''' /Test?paymentId=PAY-4VL25365CA733482BLPMAHBI&token=EC-1SU951197H0006730&PayerID=A29TCMY2J8G9C ''' @ratelimit(key='ip', rate='1/m') def get(self, request, *args, **kwargs): # 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) ''' :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 post(self, request, *args, **kwargs): response = ResponseObject() return response.json(0) # 修改 资源改变 def put(self, request): response = ResponseObject() return response.json(0) # 修改 属性改变 def PATCH(self, request): response = ResponseObject() return response.json(0) # 删除 def delete(self, request): response = ResponseObject() return response.json(0) def validation(self, request_dict, *args, **kwargs): response = ResponseObject() return response.json(0)