当前位置:网站首页>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
边栏推荐
- 100 lectures on practical application cases of Excel (VIII) - report connection function of Excel
- About the 'enum' enumeration type and structure.
- The quill editor image zooms, multiple rich text boxes are used on one page, and the quill editor upload image address is the server address
- Design and manufacture of 51 single chip microcomputer solar charging treasure with low voltage alarm (complete code data)
- 51 single chip microcomputer stepping motor control system based on LabVIEW upper computer (upper computer code + lower computer source code + ad schematic + 51 complete development environment)
- Learning materials
- Go language mapping operation
- leetcode-791. 自定义字符串排序
- Jupiter notebook installation
- 内核错误: No rule to make target ‘debian/canonical-certs.pem‘, needed by ‘certs/x509_certificate_list‘
猜你喜欢
Jupiter notebook installation
100 GIS practical application cases (53) - making three-dimensional image map as the base map of urban spatial pattern analysis
Design of STM32 multi-channel temperature measurement wireless transmission alarm system (industrial timing temperature measurement / engine room temperature timing detection, etc.)
Idea的src子文件下无法创建servlet
Record a website for querying compatibility, string Replaceall() compatibility error
安装nngraph
Introduction to servlet listener & filter
[Blue Bridge Cup] April 17 provincial competition brushing training (the first three questions)
Teach you to quickly develop a werewolf killing wechat applet (with source code)
GIS practical tips (III) - how to add legend in CASS?
随机推荐
SSM framework series - JUnit unit test optimization day2-3
The accuracy and speed are perfectly balanced, and the latest image segmentation SOTA model is released!!!
Melt reshape decast long data short data length conversion data cleaning row column conversion
Remote access to raspberry pie at home (Part 1)
MySQL —— 16、索引的数据结构
SSM framework series - annotation development day2-2
Deploying MySQL in cloud native kubesphere
Temperature and humidity monitoring + timing alarm system based on 51 single chip microcomputer (C51 source code)
AUTOSAR from introduction to mastery 100 lectures (86) - 2F of UDS service foundation
Date time type in database
Recovering data with MySQL binlog
Importerror after tensorflow installation: DLL load failed: the specified module cannot be found, and the domestic installation is slow
Softbank vision fund entered the Web3 security industry and led a new round of investment of US $60 million in certik
JMeter operation redis
【微信小程序】flex布局使用记录
Free and open source intelligent charging pile SaaS cloud platform of Internet of things
CVPR 2022&NTIRE 2022|首个用于高光谱图像重建的 Transformer
Customize classloader and implement hot deployment - use loadclass
mysql8安装
Use of Presto date function