Django实现支付宝沙箱操作,太强了呀

Django实现支付宝沙箱操作环境即所需模块

  1. Django == 3.1.0
  2. python == 3.7.4
  3. python-alipay-sdk=2.0.1
所需
  1. 下载模块 python-alipay-sdk=2.0.1
  2. 文档 非官方支付宝 Python SDK: #alipay.trade.page.pay
沙箱环境配置
  1. 在支付宝开放平台---->开发者中心—>开发服务---->沙箱
  2. RSA2密钥生成并上传 参考官方地址:
  3. 下载支付宝开放平台开发助手下载地址下载后生成秘钥[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iAJ4s57z-1602600230093)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013215751437.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-RLkaGka3-1602600315452)(C:%5CUsers%5CASUS%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20201013215646909.png#pic_center)])
4.将应用公钥复制到支付宝中 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pm1umRDQ-1602600230099)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013220238000.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-xIM2Wwqr-1602600230101)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013220309533.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CZRSx4tY-1602600230104)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013220359867.png)]
5.配置app中支付宝公钥 开发助手秘钥
  1. [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-hzEeNDd6-1602600230107)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013220610210.png)]
  2. 在Django的app中创建文件夹置放支付宝公钥[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Bg9hMEFa-1602600230111)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013221108217.png)]
  3. 在Django的app中创建文件夹置放开放平台私钥[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0aGqpG4B-1602600230112)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013221548593.png)]
Django Models# 支付状态表class Status(BaseModel):name = models.CharField(max_length=32)class Meta:db_table = 'status'# 支付表class Order(BaseModel):out_trade_no = models.CharField(max_length=60)trada_no = models.CharField(max_length=60, null=True, blank=True)goods = models.ForeignKey(Goods, on_delete=models.CASCADE)user = models.ForeignKey(User, on_delete=models.CASCADE)goods_num = models.IntegerField()status = models.ForeignKey(Status, on_delete=models.CASCADE)class Meta:db_table = 'order'Django Views配置
  1. ? 所需的包import uuid import redis from app01.views import login_serializer from alipay import AliPay, AliPayConfig123
# 绝对路径打开文件{}代表从这里往前app_private_key_string = open('{}\\app02\\alipay_key\\app_private_key'.format(settings.BASE_DIR)).read()alipay_public_key_string = open('{}\\app02\\alipay_key\\alipay_public'.format(settings.BASE_DIR)).read()12[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-TU8ck5hJ-1602600230116)(C:\Users\ASUS\AppData\Roaming\Typora\typora-user-images\image-20201013222520219.png)]