web頁面調用支付寶支付

 

web頁面調用支付寶支付

此文章是前端單獨模擬完成支付,若在線上環境則須要後臺配合產生簽名等參數php

  1. 在螞蟻金服開放平臺申請沙箱環境html

    將沙箱環境中的密鑰、應用網關、回調地址補全,生成密鑰的方法在此前端

    這裏寫圖片描述

    配置好的沙箱環境如圖示jquery

    這裏寫圖片描述

  2. 利用RSA簽名驗證工具生成簽名,方法在此web

  3. 前端調用,附上代碼express

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
    <div style="width:200px;height:200px;background:red;" onclick="to()"></div>
    </body>
    <script src="../js/jquery-1.12.1.js"></script>
    <script>
        var prodConfig = {
            "body": "body",
            "subject": "daledou",
            "out_trade_no": "70501111111S001111110",
            "timeout_express": "90m",
            "total_amount": 9.00,
            "product_code": "QUICK_WAP_WAY"
        }
        var alipayConfig = {
            biz_content: JSON.stringify(prodConfig),
            app_id: '本身的appid',
            version: '1.0',
            format: 'json',
            sign_type: 'RSA2',
            method: 'alipay.trade.wap.pay',
            notify_url: 'http://***/alipy/notify_url.php',
            return_url: 'http://***/alipy/return_url.php',
            charset: 'UTF-8',
            sign: 'L3quItR9hqIfsgjZVqDO/L8k5dmdSSn7KCQcHMRsZl0yzFa9im5Ge/ZXZh1sIo+fqr5zJkUUYmZknERw+iPiiNt/w0VLKPzjgzL4afoQ4oS5vnD8SzdccA9C1E5GxjvJCXGseeciQpyNkMmvXwTcL7egS4ukn2dAV0lpcM8KNPJdi+1HlWgAlnFT0Xq6Kqs24GD+Fd4ogpXoWOa3HfSjY1+DY+7FwKyunTvR9isN/kRIckW887GE2Dy2jRSghhANrf47f54SDMu+UcuRsNfxsgwfSTiafTW1q8Eym/2G7PBOWnI0I5llD7bs9Qu3zB/b+IpLlkEa0jUNj1rXgvkjww==',
            timestamp: '2017-11-15 14:55:46'
        }
        function to() {
            httpPost('https://openapi.alipaydev.com/gateway.do', alipayConfig)
        }
        function httpPost(URL, PARAMS) {
            var temp = document.createElement("form");
            temp.action = URL;
            temp.method = "post";
            temp.style.display = "none";
     
            for (var x in PARAMS) {
                var opt = document.createElement("textarea");
                opt.name = x;
                opt.value = PARAMS[x];
                temp.appendChild(opt);
            }
     
            document.body.appendChild(temp);
            temp.submit();
     
            return temp;
        }
    </script>
    </html>
相關文章
相關標籤/搜索