• 支付宝支付流程


    1.支付宝支付流程

    • 支付宝支付流程交互关系

    2.新建支付宝应用

    # 访问"支付宝开发平台"登录,可以访问开发者中心
    https://open.alipay.com/platform/home.htm
    # 可以参考"电脑网站支付" 熟悉电脑支付整体流程
    https://docs.open.alipay.com/270/105899/
    

    2.1 第一步:创建应用(这里使用沙箱环境测试)

    • 公钥加密、私钥解密

    2.2 按照官方要求生成秘钥

    生成秘钥参考官网: https://docs.open.alipay.com/291/105971
    
    • 一定要存储两个东西
      • 支付宝公钥:我发送信息给支付宝,使用支付宝公钥进行加密
      • app私钥(我自己生成的):支付宝给我发送的信息是用我刚刚上传的app公钥加密,只有我 自己的私钥可以解密

    2.3 把生成的app公钥粘贴到沙箱环境的app中

    沙箱环境地址: https://openhome.alipay.com/platform/appDaily.htm?tab=info
    

    2.4 查看沙箱环境账号和密码

    # 买家信息
    买家账号foqhub3270@sandbox.com
    登录密码111111
    支付密码111111
    
    # 商家账号uqqgmd6602@sandbox.com
    商户UID2088102180143385
    登录密码111111
    

    3.测试支付宝获取支付宝扫码链接

    3.1 支付宝开发网址

    支付宝开放平台: https://open.alipay.com/platform/home.htm
    支付宝沙箱环境: https://openhome.alipay.com/platform/appDaily.htm?tab=info
    支付宝开发者文档:https://openhome.alipay.com/developmentDocument.htm
    电脑网站支付流程:https://docs.open.alipay.com/270
    生成签名:https://docs.open.alipay.com/291/106103/
    python-alipay-adk : https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
    

    3.2 说明

    • 阿里官方没有提供python对接支付的sdk,但是python库中有非官方的sdk包可以使用
    • python-alipay-adk : https://github.com/fzlee/alipay/blob/master/README.zh-hans.md
    • 使用起来非常简单,只要传入几个必要的参数就可以完成
    • 由于支付对安全要求很高,所以要理解对接支付宝安全的流程: 公钥加密、私钥解密 这八个字

    3.3 app_private_key.pem app私钥

    -----BEGIN RSA PRIVATE KEY-----
    MIIEpAIBAAKCAQEAxXRdL+ALzW4AW6ndW5/ZD44ppPsfm9If/oc3pc1gmq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pmRlT/gMWozY6CnvWpATcyOQtZdv3SndcB34EazlbS04mXsAWC2js0GIddJeG1CQW695K5b0EokWZc47yuTngsy5vbvJ1w/IDAoGAW5jpaCo1DFMJD9Evmy19ThbKEBUedaxPAdPa4DP88Te410EhEt1et0cU92dor7ZWz32AUXPiShizslv9K+3JgV0TGg0Dc4Ej6uFdmsvKI1wKd9FpoCUa9AYB16wcy4v1oOjYvdBnVYF70ItVEzQOb3qVmkkH+F1f5cJKiNJo/EECgYA1OZn4LqvFsK/WG23FFcW6wvGOKjHgAfwENILiHBHNESYBtwnRaV0Vgikz3tfC5qehmuJT+N+bjsqsqaM3ZR50/xqWx6qGenA5KbGyMkWMu4LFAuqGKz1ocH
    2kjM+jc0eNRzABj7A9ATx+1nfiKD0ehc6lrXIp71rItEuKxyO8w==
    -----END RSA PRIVATE KEY-----
    
    

    3.4 alipay_public_key.pem 支付宝公钥

    -----BEGIN PUBLIC KEY-----
    MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIgHnOn7LLILlKETd6BFRJ0GqgS2Y3mn1wMQmyh9zEyWlz5p1zrahRahbXAfCfSqshSNfqOmAQzSHRVjCqjsAw1jyqrXaPdKBmr90DIpIxmIyKXv4GGAkPyJ/6FTFY99uhpiq0qadD/uSzQsefWo0aTvP/65zi3eof7TcZ32oWpwIDAQAB
    -----END PUBLIC KEY-----
    

    3.5 测试生成支付链接

    # -*- coding: utf-8 -*-
    from alipay import AliPay
    # 沙箱环境中 app 私钥
    app_private_key_string = open('app_private_key.pem').read()
    # 支付宝公钥
    alipay_public_key_string = open( 'alipay_public_key.pem').read()
    def get_alipay_url():
        # 实例化一个alipay对象
        alipay = AliPay(
        appid="2016101800716047", # 沙箱appid
        app_notify_url=None, # 默认回调url
        app_private_key_string=app_private_key_string,
        # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥,
        alipay_public_key_string=alipay_public_key_string,
        sign_type="RSA", # RSA 或者 RSA2
        debug=True, # 默认False,我们是沙箱,所以改成True(让访问沙箱环境支付宝地址)
        )
    # 调用支付接口,生成支付链接
    # 电脑网站支付,需要跳转到https://openapi.alipay.com/gateway.do? + order_string
    order_string = alipay.api_alipay_trade_page_pay(
        out_trade_no="201612226", # 订单id,应该从前端获取
        total_amount=str(0.01), # 订单总金额
        subject="测试阿里云付款", # 付款标题信息
        return_url=None, # 付款成功回调地址(可以为空)
        notify_url=None # 付款成功后异步通知地址(可以为空)
        )
    pay_url = "https://openapi.alipaydev.com/gateway.do?" + order_string
    print(pay_url) # 将这个url复制到浏览器,就会打开支付宝支付页面
    def query_pay():
        alipay = AliPay(
        appid="2016101800716047", # 沙箱appid
        app_notify_url=None, # 默认回调url
        app_private_key_string=app_private_key_string,
        # 支付宝的公钥,验证支付宝回传消息使用,不是你自己的公钥
        alipay_public_key_string=alipay_public_key_string,
        sign_type="RSA", # RSA 或者 RSA2
        debug=True, # 默认False,我们是沙箱,所以改成True(让访问沙箱环境支付宝地址)
        )
    trade_query = alipay.api_alipay_trade_query(
    	out_trade_no=20161112, # 上面生成支付码页面时传入的商品订单号
    	trade_no=None
    	)
    	print(trade_query)
    if __name__ == '__main__':
    get_alipay_url()
    query_pay()
    '''
    trade_query 查询用户付款信息
    返回信息详情请看官方:https://docs.open.alipay.com/api_1/alipay.trade.query
    {
    "code": "10000", # code=10000代表支付成功
    "msg": "Success",
    "buyer_logon_id": "foq***@sandbox.com",
    "buyer_pay_amount": "0.00",
    "buyer_user_id": "2088102180228981",
    "buyer_user_type": "PRIVATE",
    "invoice_amount": "0.00",
    "out_trade_no": "20161112",
    "point_amount": "0.00",
    "receipt_amount": "0.00",
    "send_pay_date": "2020-02-20 21:20:48",
    "total_amount": "0.01",
    "trade_no": "2020022022001428981000087565",
    "trade_status": "TRADE_SUCCESS"
    }
    '''	
    
    • 生成链接地址如下

      https://excashier.alipaydev.com/standard/auth.htm?
      payOrderId=79d3a024f4904f58af434843b945132f.00
      
  • 相关阅读:
    从零开始入门 K8s | 应用编排与管理
    209. Minimum Size Subarray Sum
    208. Implement Trie (Prefix Tree)
    207. Course Schedule
    203. Remove Linked List Elements
    183. Customers Who Never Order
    182. Duplicate Emails
    181. Employees Earning More Than Their Managers
    1261. Find Elements in a Contaminated Binary Tree
    1260. Shift 2D Grid
  • 原文地址:https://www.cnblogs.com/ihszg/p/13823473.html
Copyright © 2020-2023  润新知