当前位置:网站首页>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
边栏推荐
- 软件测试周刊(第68期):解决棘手问题的最上乘方法是:静观其变,顺水推舟。
- 31. 下一个排列
- [untitled] PID control TT encoder motor
- Record Alibaba cloud server mining program processing
- 拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇
- Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
- Get the punch in record of nailing attendance machine
- SSM framework series - JUnit unit test optimization day2-3
- Go language: passing slices between functions
- AUTOSAR from introduction to mastery 100 lectures (83) - bootloader self refresh
猜你喜欢

Important knowledge of transport layer (interview, retest, final)

Record some NPM related problems (messy records)

Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)

nodejs + mysql 实现简单注册功能(小demo)

Summary of JVM knowledge points - continuously updated

Use compressorjs to compress pictures, optimize functions, and compress pictures in all formats

Free and open source charging pile Internet of things cloud platform

SSM framework series - annotation development day2-2

Learning materials

melt reshape decast 长数据短数据 长短转化 数据清洗 行列转化
随机推荐
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
5 free audio material websites, recommended collection
Design of body fat detection system based on 51 single chip microcomputer (51 + OLED + hx711 + US100)
office2021安装包下载与激活教程
【微信小程序】flex布局使用记录
将opencv 图片转换为字节的方式
4.22学习记录(你一天只做了水题是吗)
MySQL -- 16. Data structure of index
V-model binding value in El select, data echo only displays value, not label
(1) Openjuterpyrab comparison scheme
mysql 基本语句查询
Use Proteus to simulate STM32 ultrasonic srf04 ranging! Code+Proteus
拥抱机器视觉新蓝海,冀为好望开启数字经济发展新“冀”遇
Wonderful review | the sixth issue of "source" - open source economy and industrial investment
Subscribe to Alibaba demo send business messages
Melt reshape decast long data short data length conversion data cleaning row column conversion
Unable to create servlet under SRC subfile of idea
jmeter操作redis
decast id.var measure. Var data splitting and merging
Teach you to quickly develop a werewolf killing wechat applet (with source code)