当前位置:网站首页>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
边栏推荐
- 产品开发都应该知道的8个网站,增强工作体验
- 7_Addmodule和基因加和法add 得到的细胞类型打分在空间上空转对比
- HQL statement tuning
- Calculate the past date and days online, and calculate the number of live days
- Three channel ultrasonic ranging system based on 51 single chip microcomputer (timer ranging)
- Learning materials
- 将opencv 图片转换为字节的方式
- Get the punch in record of nailing attendance machine
- SSM框架系列——Junit单元测试优化day2-3
- pyqt5 将opencv图片存入内置SQLlite数据库,并查询
猜你喜欢
产品开发都应该知道的8个网站,增强工作体验
Calculate the past date and days online, and calculate the number of live days
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
three. JS text ambiguity problem
Record Alibaba cloud server mining program processing
R语言中dcast 和 melt的使用 简单易懂
Navicat远程连接数据库 出现 1130- Host xxx is not allowed to connect to this MySQL server错误
JMeter operation redis
STM32 is connected to the motor drive, the DuPont line supplies power, and then the back burning problem
随机推荐
内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
有趣的IDEA插件推荐,给你的开发工作增添色彩
Pytorch: a pit about the implementation of gradreverselayer
Idea的src子文件下无法创建servlet
Async void provoque l'écrasement du programme
pyqt5 将opencv图片存入内置SQLlite数据库,并查询
8 websites that should be known for product development to enhance work experience
Utils of various date conversion
100 lectures on practical application cases of Excel (VIII) - report connection function of Excel
MySQL supports IP access
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
Summary of JVM knowledge points - continuously updated
Record the problems encountered in using v-print
World Book Day: I'd like to recommend these books
JDBC connection pool
100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
在线计算过往日期天数,计算活了多少天
Record some NPM related problems (messy records)
Use of Presto date function
Translation of multi modal visual tracking: review and empirical comparison