当前位置:网站首页>Mui wechat payment pit
Mui wechat payment pit
2022-04-23 13:05:00 【It's never too late to be alone】
var that = this;
var wxChannel = null; // Wechat payment
var aliChannel = null; // Alipay pay
var channel = null; // Payment channel
mui.init()
mui.plusReady(function() {
plus.navigator.setStatusBarStyle('light');
});
// Click to pay
mui('.hotel_footer').on('tap', '.footer_right_true', function() {
if(that.name != null && that.idcard != null) {
// Call hide / Show pop-up layers
mui("#popover").popover('toggle', document.getElementById("div"));
} else {
alert(' Please complete your information ')
}
})
// Click wallet to pay
mui('.mui-table-view').on('tap', '#kzf_money', function() {
// Balance payment
const client = '/BalancePay' // Balance payment
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(' Successful payment !')
mui.openWindow({
url: './payment_details.html',
})
} else {
alert(data.msg)
}
})
})
mui.plusReady(function() {
// Access to payment channels
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(" Failed to get payment channel :" + e.message);
});
})
// Click wechat payment
mui('.mui-table-view').on('tap', '.my_recommend', function() {
pay('wxpay');
})
// Click Alipay payment
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. Request for payment
function pay(id) {
// Request payment orders from the server
var PAYSERVER = '';
if(id == 'alipay') {
PAYSERVER = ALIPAYSERVER;
channel = aliChannel;
} else if(id == 'wxpay') {
PAYSERVER = WXPAYSERVER;
channel = wxChannel;
} else {
plus.nativeUI.alert(" This payment channel is not supported !", null, " Hotel payment ");
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 = { // The payment parameters returned in the background should be all lowercase ( Reminders seen in the Forum )
"appid": xhrdata.appid,
"noncestr": xhrdata.nonce_str,
"package": "Sign=WXPay",// Fix
"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(" Successful payment !", function() {
back();
});
}, function(error) {
console.log(JSON.stringify(error))
plus.nativeUI.alert(" Failure to pay :" + error.code);
});
} else {
alert(" Failed to get order information !");
}
break;
default:
break;
}
}
xhr.open('POST', PAYSERVER);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(pame);
}
notes :mui Wechat payment actually goes app payment , Is not web payment …
版权声明
本文为[It's never too late to be alone]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231303466163.html
边栏推荐
- Customize the shortcut options in El date picker, and dynamically set the disabled date
- 将新增和编辑的数据同步更新到列表
- Servlet监听器&过滤器介绍
- 世界读书日:我想推荐这几本书
- There is no need to crack the markdown editing tool typora
- 拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇
- HQL find the maximum value in a range
- Introducing vant components on demand
- three. JS text ambiguity problem
- AUTOSAR from introduction to mastery 100 lectures (52) - diagnosis and communication management function unit
猜你喜欢

AUTOSAR from introduction to mastery 100 lectures (51) - AUTOSAR network management

Synchronously update the newly added and edited data to the list

The El table horizontal scroll bar is fixed at the bottom of the visual window

HQL find the maximum value in a range

Van uploader upload picture implementation process, using native input to upload pictures

hbuilderx + uniapp 打包ipa提交App store踩坑记

Kernel error: no rule to make target 'Debian / canonical certs pem‘, needed by ‘certs/x509_ certificate_ list‘

Melt reshape decast long data short data length conversion data cleaning row column conversion

mui + hbuilder + h5api模拟弹出支付样式
![[untitled] PID control TT encoder motor](/img/ce/942a0b87994699f73da215e7cad2a1.png)
[untitled] PID control TT encoder motor
随机推荐
Free and open source agricultural Internet of things cloud platform (version: 3.0.1)
unity常见的问题(一)
4.22 study record (you only did water problems in one day, didn't you)
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
Process virtual address space partition
Golang realizes regular matching: the password contains at least one digit, letter and special character, and the length is 8-16
Timing role in the project
Community version Alibaba MQ ordinary message sending subscription demo
Free and open source charging pile Internet of things cloud platform
decast id.var measure. Var data splitting and merging
AUTOSAR from introduction to mastery lecture 100 (84) - Summary of UDS time parameters
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
Common problems of unity (1)
mui picker和下拉刷新冲突问题
[Technical Specification]: how to write technical documents?
leetcode-791. Custom string sorting
21 days learning mongodb notes
世界读书日:我想推荐这几本书
基于uniapp异步封装接口请求简介
Three channel ultrasonic ranging system based on 51 single chip microcomputer (timer ranging)