当前位置:网站首页>mui 微信支付 排坑
mui 微信支付 排坑
2022-04-23 13:04:00 【孤身不觉晚】
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支付…
版权声明
本文为[孤身不觉晚]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40043424/article/details/103075855
边栏推荐
- melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
- Servlet监听器&过滤器介绍
- 7_ The cell type scores obtained by addmodule and gene addition method are compared in space
- How to click an object to play an animation
- MySQL supports IP access
- 98. Error s.e.errormvcautoconfiguration $staticview reported by freemaker framework: cannot render error page for request
- Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘
- Huawei cloud MVP email
- Idea的src子文件下无法创建servlet
- CGC: contractual graph clustering for community detection and tracking
猜你喜欢
The use of dcast and melt in R language is simple and easy to understand
mysql8安装
100 GIS practical application cases (52) - how to keep the number of rows and columns consistent and aligned when cutting grids with grids in ArcGIS?
MySQL —— 16、索引的数据结构
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
1130 - host XXX is not allowed to connect to this MySQL server error in Navicat remote connection database
4. DRF permission & access frequency & filtering & sorting
Packet capturing and sorting -- TCP protocol [8]
31. 下一个排列
Recovering data with MySQL binlog
随机推荐
Homomorphic encryption technology learning
About the 'enum' enumeration type and structure.
SQL exercise question 1
Calculate the past date and days online, and calculate the number of live days
Huawei cloud MVP email
拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇
AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
[untitled] PID control TT encoder motor
【蓝桥杯】4月17日省赛刷题训练(前3道题)
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
数据库中的日期时间类型
SSM framework series - data source configuration day2-1
HQL statement tuning
Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
Subscribe to Alibaba demo send business messages
Async void provoque l'écrasement du programme
100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
Translation of multi modal visual tracking: review and empirical comparison
SSM框架系列——数据源配置day2-1