mui 微信支付 排坑

var that = this;
					var wxChannel = null; // 微信支付  
					var aliChannel = null; // 支付宝支付  
					var channel = null; //支付通道
					mui.init()
					mui.plusReady(function() {
						plus.navigator.setStatusBarStyle('light');
					});
					//点击支付
					mui('.hotel_footer').on('tap', '.footer_right_true', function() {
						if(that.name != null && that.idcard != null) {
							//调用隐藏/显示弹出层
							mui("#popover").popover('toggle', document.getElementById("div"));
						} else {
							alert('请补全您的信息')
						}

					})
					//点击钱包支付
					mui('.mui-table-view').on('tap', '#kzf_money', function() {
						//余额支付
						const client = '/BalancePay' //余额支付
						var that = this
						api.AjaxReponse(client, {
							'access_token': localStorage.getItem('access_token'),
							'order_number': localStorage.getItem('order_number')
						}, function(data) {
							if(data.code == 0) {
								localStorage.setItem('order_uuid', data.data)
								alert('支付成功!')
								mui.openWindow({
									url: './payment_details.html',
								})
							} else {
								alert(data.msg)
							}
						})
					})
					mui.plusReady(function() {
						// 获取支付通道  
						plus.payment.getChannels(function(channels) {
							for(var i in channels) {
								if(channels[i].id == "wxpay") {
									wxChannel = channels[i];
									//									console.log(JSON.stringify(wxChannel))
								} else {
									aliChannel = channels[i];
								}
							}
						}, function(e) {
							alert("获取支付通道失败:" + e.message);
						});

					})
					//点击微信支付
					mui('.mui-table-view').on('tap', '.my_recommend', function() {
						pay('wxpay');
					})
					//点击支付宝支付
					mui('.mui-table-view').on('tap', '.integral', function() {
						pay('alipay');
					})
					var pame = 'access_token=' + localStorage.getItem('access_token') + '&order_number=' + localStorage.getItem('order_number')
					var ALIPAYSERVER = 'http://demo.dcloud.net.cn/helloh5/payment/alipay.php?total=';
//					 var WXPAYSERVER = 'http://demo.dcloud.net.cn/payment/?payid=wxpay&appid=HBuilder&total=1';
					// 2. 发起支付请求  
					function pay(id) {
						// 从服务器请求支付订单  
						var PAYSERVER = '';
						if(id == 'alipay') {
							PAYSERVER = ALIPAYSERVER;
							channel = aliChannel;
						} else if(id == 'wxpay') {
							PAYSERVER = WXPAYSERVER;
							channel = wxChannel;
						} else {
							plus.nativeUI.alert("不支持此支付通道!", null, "酒店支付");
							return;
						}
						var xhr = new XMLHttpRequest();

						xhr.onreadystatechange = function() {
							switch(xhr.readyState) {
								case 4:
									if(xhr.status == 200) {
//										alert(JSON.stringify(JSON.parse(xhr.responseText).data))
//										alert(JSON.stringify(xhr.responseText.data))
										//										console.log(JSON.stringify(xhr.responseText))
										var xhrdata = JSON.parse(xhr.responseText).data
//										var paydata = {}
//
//										paydata.appid = xhrdata.appid;
//										paydata.nonce_str = xhrdata.nonce_str;
//										paydata["package"] = "Sign=WXPay";
//										paydata.partnerid = xhrdata.mch_id;
//										paydata.prepayid = xhrdata.prepay_id;
//										paydata.sign = xhrdata.sign;
//										paydata.timestamp = Date.parse(new Date());

										let paydata = { //后台返回的支付参数最好全部都是小写(论坛看到的提醒)
											"appid": xhrdata.appid,
											"noncestr": xhrdata.nonce_str,
											"package": "Sign=WXPay",//固定
											"partnerid": xhrdata.mch_id,
											"prepayid": xhrdata.prepay_id,
											"timestamp": xhrdata.timestamp,
											"sign": xhrdata.sign
										};
//										alert(JSON.stringify(xhr.responseText))

										plus.payment.request(channel, paydata, function(result) {
											plus.nativeUI.alert("支付成功!", function() {
												back();
											});
										}, function(error) {
											console.log(JSON.stringify(error))
											plus.nativeUI.alert("支付失败:" + error.code);
										});
									} else {
										alert("获取订单信息失败!");
									}
									break;
								default:
									break;
							}
						}
						xhr.open('POST', PAYSERVER);
						xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						xhr.send(pame);

					}

注:mui 微信支付其实是走的app支付,并非web支付…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值