支付配置参考http://ask.dcloud.net.cn/article/71
注:微信支付需打包后安装到手机测试
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div class="pay-btn" id="weixinPay">立即支付</div> </body> </html> <script> var weixinPay=document.getElementById('weixinPay') channel = null; channels = null; //支付 weixinPay.addEventListener('tap',function(){ // 获取支付通道 plus.payment.getChannels(function(cs) { channels = cs; payOrder('wxpay') }, function(e) { plus.nativeUI.alert("获取支付通道失败:" + e.message); }); }); function payOrder(id) { if(id != 'wxpay'){ plus.nativeUI.alert("不支持此支付通道!"); return; } for (var i in channels) { if (channels[i].id == id) { channel = channels[i]; } } // 请求支付订单 //reqURL后台请求订单信息的接口 var reqURL='http://xxx' mui.ajax(reqURL, { data:{}, dataType: 'json', type: 'post', timeout: globalTimeout, success: function(info) { console.log(JSON.stringify(info)+'支付状态') var param1 = { appid: info.appid, noncestr: info.nonce_str, package: info.package, partnerid: info.mch_id, prepayid: info.prepay_id, timestamp: info.timestamp, sign: data.sign }; plus.payment.request(channel, param1, function(result) { //成功的回调 plus.nativeUI.alert('支付成功'); }, function(e) { //支付失败的回调 plus.nativeUI.alert("支付失败:" + e.code + "支付失败:" + e.message); }); }, error: function(xhr) { plus.nativeUI.toast('请求失败,请检查网络'); } }); } </script>