八年男孩
八年男孩
  • 发布:2014-11-26 09:56
  • 更新:2016-11-19 20:20
  • 阅读:7647

支付宝集成

分类:HTML5+
App
<!DOCTYPE html>  
<html>  

    <head>  
        <meta charset="utf-8">  
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />  
        <title></title>  
        <script src="../js/mui.min.js"></script>  
        <link href="../css/mui.min.css" rel="stylesheet" />  
        <link href="../css/myapp.css" rel="stylesheet" />  
        <script type="text/javascript" charset="utf-8">  
            mui.init();  
        </script>  
        <style>  
            h5 {  
                font-size: 14px;  
                font-weight: bold;  
                color: #000000;  
            }  
            label {  
                font-size: 12px;  
            }  
        </style>  
    </head>  

    <body>  
        <header class="mui-bar mui-bar-nav">  
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
            <h1 class="mui-title">会员充值</h1>  
        </header>  
    </body>  
    <div class="mui-content">  
        <h5>默认搜索框:</h5>  
        <form id="pay_form" class="mui-input-group" action="http://192.168.1.103:80/love/alipay.php?total=10" method="post">  
            <div class="mui-input-row">  
                <label>充值金额:</label>  
                <input id="total" name="total" type="number" class="mui-input-clear" placeholder="请输入数字,比如:10">  
            </div>  

        </form>  
        <h5>备注:</h5>  
        <div class="mui-input-row" style="margin: 10px 5px;">  
            <textarea rows="5" placeholder="请输入您的充值备注"></textarea>  
        </div>  
        <button id="sub_pay" class="mui-btn mui-btn-primary mui-btn-block">确认充值</button>  

    </div>  
    <script type="text/javascript">  
        mui.plusReady(function() {  
            document.getElementById('sub_pay').addEventListener('tap', function() {  
                var channel = null;  
                plus.payment.getChannels(function(channels) {                     
                    channel = channels[0];  
                    var txt = "支付通道信息:";  
                    for (var i in channels) {  
                        var channel = channels[i];  
                        txt += "id:" + channel.id + ", ";  
                        txt += "description:" + channel.description + ", ";  
                        txt += "serviceReady:" + channel.serviceReady + "; ";  
                        alert(txt);  
                        checkServices(channel);  
                    }  

                }, function(e) {  
                    alert("获取支付通道失败:" + e.message);  

                });  
                var PAYSERVER = 'http://192.168.1.103:80/love/pay.php?total=10';  
                var xhr = new XMLHttpRequest();  
                xhr.onreadystatechange = function() {  
                    switch (xhr.readyState) {  
                        case 4:  
                            if (xhr.status == 200) {  
                                plus.payment.request(channel, xhr.responseText, function(result) {  
                                    alert(result);  
                                    plus.nativeUI.alert("支付成功!", function() {  
                                        back();  
                                    });  

                                }, function(error) {  
                                    plus.nativeUI.alert("支付失败:" + error.code);  

                                });  

                            } else {  

                                alert("获取订单信息失败!");  

                            }  
                            break;  
                    }  

                }  

                xhr.open('GET', PAYSERVER);  

                xhr.send();  

            }, false);  
            /*mui.back=function(){  
                plus.nativeUI.confirm('你真的要放弃充值吗?',function(e){  
                    var i=e.index;  
                    switch(i)  
                    {  
                    case 0:  

                      break;  
                    case 1:  

                      break;  

                    }  

                },'提示',["是","否"])  
            }*/  
            function checkServices(pc) {  
                if (!pc.serviceReady) {  
                    var txt = null;  
                    switch (pc.id) {  
                        case "alipay":  
                            txt = "检测到系统未安装“支付宝快捷支付服务”,无法完成支付操作,是否立即安装?";  
                            break;  
                        default:  
                            txt = "系统未安装“" + pc.description + "”服务,无法完成支付,是否立即安装?";  
                            break;  
                    }  
                    plus.nativeUI.confirm(txt, function(e) {  
                        if (e.index == 0) {  
                            pc.installService();  
                        }  
                    }, pc.description);  
                }  
            }  
        });  
    </script>  

</html>

2014-11-26 09:56 负责人:无 分享
已邀请:
DCloud_App_Array

DCloud_App_Array

请确保输入的私钥数据内容正确,必须是pem文件中的所有数据(包括开头和结束字符及换行符)


请不要使用Windows平台的记事本打开,pem文件使用的是linux的换行符,在记事本中无法正确识别

  • ysf

    我的也出现问题,估计就是生成签名时出问题了,应该就是密钥格式的问题,请问一下用什么打开才能保证正确呢?

    2015-09-23 14:08

  • hopeband

    您好,支付成功后跳转回app怎么实现的呢?

    2016-11-19 20:20

八年男孩

八年男孩 (作者)

服务端代码和http://ask.dcloud.net.cn/article/71这个上面的一样。只是我的partenerid和私钥不一样。

beyond88

beyond88

请问一下,是否只支持微信和支付宝,能否支持paypal,如果要支持paypal怎么一个思路?

  • DCloud_App_Array

    暂时还不支持,可以考虑使用wap方式支付。

    2015-09-08 20:41

  • beyond88

    OK,谢谢

    2015-09-22 17:14

hopeband

hopeband

支付成功后回调怎么做的?

该问题目前已经被锁定, 无法添加新回复