小程序调用h5支付

it2023-02-03  43

/**

生命周期函数–监听页面加载 */ onLoad: function (options) { let that = this; let payid = options.payid; wx.login({ //获取code 使用wx.login得到的登陆凭证,用于换取openid success: (res) => { let code = res.code; // 请求充值接口获取调起小程序支付相关参数 that.requestPay(payid,code); } }); },

requestPay: function(payid,code) { console.log(payid); console.log(code); let that = this; wx.request({ method: ‘get’, url: pay_test + payid + ‘_3’ + ‘?code=’ + code, //接口地址 data: {}, header: { “Content-Type”: “application/x-www-form-urlencoded”, }, success: function (res) { console.log(res); console.log(res.data); if(res.data.code == 200){ let chargeno = res.data.data.charge.chargeno; that.setData({ chargeno: chargeno }) let payParam = JSON.parse(res.data.data.jsApiParameters); that.requestPayment(payParam); } else { setTimeout(function () { wx.showLoading({ title: “请求失败!”, }); }, 1000); setTimeout(function () { // 隐藏加载框 wx.hideLoading(); }, 3000); } }, fail: function (res) { setTimeout(function () { wx.showLoading({ title: “网络错误!”, }); }, 1000); setTimeout(function () { // 隐藏加载框 wx.hideLoading(); }, 3000); } }) },

/**

小程序支付 */ requestPayment: function(obj) { console.log(obj); let chargeno = this.data.chargeno; //调起微信支付 wx.requestPayment({ //相关支付参数 appId: obj.appId, timeStamp: obj.timeStamp, nonceStr: obj.nonceStr, package: obj.package, signType: obj.signType, paySign: obj.paySign, //小程序微信支付成功的回调通知 success: function(res) { console.log(“付款成功”) //成功之后拉起微信支付 微信支付完成之后跳转到微信自带的支付成功页面 点击页面上的 ‘确定’ 按钮 返回到之前微信充值后的页面 wx.navigateTo({ url: ‘/pages/payover’, });

}, //小程序支付失败的回调通知 fail: function(res) { console.log(“支付失败”); console.log(res); wx.navigateTo({ url: ‘/pages/payover’, }); } }); }

最新回复(0)