python支付宝支付

支付宝支付

  • 支付宝文档

  • RSA下载工具

  • 支付宝沙箱

  • 安装模块

    pip install Crypto 
    pip install pycryptodome
    pip install python-alipay-sdk
    
  • 下载RSA工具

  • 将生成的公钥上传到支付宝沙箱的RSA2(SHA256)密钥(推荐)处

  • 设置公钥后会生成一个支付宝公钥,将其复制

  • 然后将其写入一个文件 alipay_pulic_key.pem

    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB
    -----END PUBLIC KEY-----
    
  • 把之前生成的私钥也写入另外一个文件 app_private_key.pem

    -----BEGIN RSA PRIVATE KEY-----
    MIIEowIBAAKCAQEAgxk5N/XQkRatTn56TxGo8nVGk4YKb7VheSDtcLezj7sDdibVamrWz/77VG1GY17Q2jOnCoHpngWDsJybZ/5icblvk3I76H5GT+zjYMBbHXfAlnRB7BG6+Vo7YWe442S0E+A8z8N+R3MArSb3+Coht+8JgvGNdsVE9u2upmxq4GHMKDu/TY3Q7lPIXW3iL6Kxn/4L2u+EdTstlwDi141unF2r7evpBO21XNBFPdjzoSjHgV00UqpLxmoO5v9IHb2XOgOL/V0Jgl/OQ3VBTADg9yL5NcC4CvpX4QEFJlnXBMusdlvCd7VvqIK7PO1Befxjnam5Gbdl4+ONqSaXzBUuXQIDAQABAoIBAG7zZPqYXqi8QXZiEk9iydJRMKbf1WtPXawvEuTHg/9LrhVLrmj+KpiaJKJ6Fxl8CgYAF/bfeVqe2lxSGGNe9Sp9ipTBiidLxvU8QM/zlVbKr30Y35kEJ3eclw9XO+jbrOaP7Y8XmhcYIH0ts/2RCBHKFI4NODCBW/8YNysFVQT15M7goM18dIpgQVWGGzK3L+1Gg0PZ1YP2So8rKXvktLuSyk2ZACtkDCVI0dK9VxKe6pwKBgApw9URT8CXGS2ObLntoX8nQ73ItP3EYoAUdy3uAGHNNX/8mSNFDt0zt3ZidqM5+JxUNOke1GrFdx1MNt4sk6yk596fbMDjiLULp1lLr8KCmvlUZKay2Rfes4OcK9NnF4S3jwS4HDIQXQrnAyqnjvOc08wBhkXsfnU+KEpVglFx1AoGBAJBqcnm+hwM1OOZ4HubD/3Ct4/BWvHDwDe8fCVqkspTXyVs94rjzPUTekwg3Q7p6GrC/ZdekmrqL6K/OpZcXqqlQTkvSe+3Wic4aqEa73+2qemAE+3rDZ2nf1cQrIPSBIPLSTHdkuoxLiSL4f8XZQeSUsTTTFRoaoaNtbo/ayuQw
    -----END RSA PRIVATE KEY-----
    
  • 这样沙箱配置结束了。

  • python与支付宝交互

    class PayView(APIView):
        def get(self,request):
            ali = AliPay(
                appid='201628',
                app_notify_url = None,
                alipay_public_key_path=os.path.join(settings.BASE_DIR,'keys/alipay_public_key.pem'),
                app_private_key_path=os.path.join(settings.BASE_DIR,'keys/app_private_key.pem'),
                debug=False
            )
            data = {
                "subject":"服装",
                "out_trade_no":'20191919191',
                "total_amount":str(234)
            }
            order_str = ali.api_alipay_trade_page_pay(**data)
    
            request_url = 'https://openapi.alipaydev.com/gateway.do?'+order_str
            return Response({
                "status":100,
                "msg":"",
                "data":request_url
            })
    
    
posted @ 2019-11-07 13:45  巫小诗  阅读(509)  评论(0编辑  收藏  举报