django中支付宝(沙箱)简单使用
python=3.6.8
django=2.1.8
python-alipay-sdk=2.0.1
非官方支付宝 Python SDK: https://github.com/fzlee/alipay/blob/master/README.zh-hans.md#alipay.trade.page.pay
沙箱环境配置
1、在支付宝开放平台---->开发者中心—>开发服务---->沙箱
2、RSA2密钥生成并上传
参考官方地址:https://opendocs.alipay.com/open/291/105971
新版的生成密钥工具为.exe文件,下载完成以后,请自行安装,安装好以后,桌面自动生成图标
运行支付宝开放平台开发助手
获取支付宝公钥
django中使用alipay
alipay公钥和app私钥在django中存放行式
alipay公钥
app私钥
models.py
from django.db import models
# Create your models here.
class Goods(models.Model):
goods_name = models.CharField(max_length=32)
goods_price = models.FloatField()
class Order(models.Model):
order_number = models.CharField(max_length=64)
status_choices = ((0, '未支付'), (1, '已支付'))
order_status = models.IntegerField(choices=status_choices, default=0)
goods = models.ForeignKey(to='Goods', on_delete=models.CASCADE)
views.py
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.views import View
from django.conf import settings
from .models import *
import uuid
from alipay import AliPay
# Create your views here.
class GoodsView(View):
def get(self, request):
goods_list = Goods.objects