微信或支付宝支付

function plusReady() {
                plus.payment.getChannels(function(channels) {
                    var content = document.getElementById('dcontent');
                    var txt = "支付通道信息:";
                    for(var i in channels) {
                        var channel = channels[i];
                        if(channel.id == 'qhpay' || channel.id == 'qihoo') { // 过滤掉不支持的支付通道:暂不支持360相关支付
                            continue;
                        }
                        pays[channel.id] = channel;
                        txt += "id:" + channel.id + ", ";
                        txt += "description:" + channel.description + ", ";
                        txt += "serviceReady:" + channel.serviceReady + "";
                        //                        var de = document.createElement('div');
                        //                        de.setAttribute('class', 'button');
                        //                        de.setAttribute('onclick', 'pay(this.id)');
                        //                        de.id = channel.id;
                        //                        de.innerText = channel.description + "支付";
                        //                        content.appendChild(de);
                        //                        checkServices(channel);
                    }
                }, function(e) {});
            }
            document.addEventListener('plusready', plusReady, false);

            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);
                }
            }

            var w = null;
            var PAYSERVER = IP + '/mobile/payment/aliPrepay.html';
            var PAYSERVER2 = IP + '/mobile/payment/wechatPrepay.html';
            var url = "";

            function pay(id) {
                if(w) {
                    return;
                }
                if(id == 'alipay') {
                    url = PAYSERVER;
                } else if(id == 'wxpay') {
                    url = PAYSERVER2;
                } else {
                    plus.nativeUI.alert("当前环境不支持此支付通道!", null, "充值");
                    return;
                }

                w = plus.nativeUI.showWaiting();
                var amount = document.getElementById('total').value;

                $.ajax({
                    type: 'post',
                    url: url,
                    data: {
                        amount: amount, //金额
                        token:plus.storage.getItem("token"), //用户标识
                        type:"balance", //类型
                    },
                    dataType: 'json',
                    success: function(data) {
                        w.close();
                        w = null;
                        console.log("1111"+JSON.stringify(data))
                        plus.payment.request(pays[id], data.data.prepayInfo, function(result) {
                            var username = plus.storage.getItem("username");
                            var type = id == "alipay" ? "支付宝支付" : "微信支付";
                            plus.nativeUI.alert("支付成功", function() {
                                var walletSub = plus.webview.getWebviewById("walletSub.html");
                                mui.fire(walletSub, 'pulldownRefresh');
                                var walletHistorySub = plus.webview.getWebviewById("walletHistorySub.html");
                                mui.fire(walletHistorySub, 'pulldownRefresh');
                                var menu = plus.webview.getWebviewById("menuSub.html");
                                mui.fire(menu, 'reflashClient');
                                back();
                            }, "通知");
                        }, function(e) {
                            plus.nativeUI.toast("支付出错");
                        });
                    },
                    error: function(retData) {
                        w.close();
                        w = null;
                        plus.nativeUI.alert(retData);
                    }
                });
 }


function payWechat(){
  var money = $(".highlight").find("span").eq(0).text();
  if(money == '') {
    plus.nativeUI.alert("请输入充值金额");
  } else {
    var total = parseInt(money);
    var id = 'wxpay'
    pay(id);
   }
}

function payAlipay(){
  var money = $(".highlight").find("span").eq(0).text();
  if(money == '') {
    plus.nativeUI.alert("请输入充值金额");
  } else {
    var total = parseInt(money);
    var id = 'alipay'
    pay(id);
  }
}

 

猜你喜欢

转载自www.cnblogs.com/ccllj/p/9643662.html