一、引入微信 import wx from ‘weixin-js-sdk’ 需要下载对应的依赖
二、调用后端接口获取package_info和orderNo
async Withdrawal() {
uni.showLoading({
mask: true
})
const res = await memberWithdraw({
amount: 0.1,
});
if (res.code == 200) {
console.log('提现返回结果', res.result);
if (res.result && res.result.package_info) {
this.ConfirmPay(res.result.orderNo, res.result.package_info)
} else {
uni.hideLoading()
uni.showToast({
icon: 'none',
title: res.message,
duration: 2000,
});
setTimeout(() => {
uni.navigateBack()
}, 2000)
this.init()
}
}
},
三、拉起微信提现确认弹窗
async ConfirmPay(o, p) {
let that = this
let gtf = await this.gtf()
console.log('gtf', gtf);
wx.config({
debug: false,
appId: '公众号id',
timestamp: gtf.timestamp,
nonceStr: gtf.nonceStr,
signature: gtf.signature,
jsApiList: ['requestMerchantTransfer']
});
wx.ready(function() {
console.log('进入rady');
wx.checkJsApi({
jsApiList: ['requestMerchantTransfer'],
success: function(res) {
if (res.checkResult['requestMerchantTransfer']) {
WeixinJSBridge.invoke('requestMerchantTransfer', {
mchId: '注册的商户号',
appId: '公众号id',
package: p,
},
function(ress) {
console.log('ress', ress);
if (ress.err_msg === 'requestMerchantTransfer:ok') {
uni.hideLoading()
that.sendState(o)
uni.navigateBack({
delta: 1,
})
}
}
);
} else {
uni.hideLoading()
alert('你的微信版本过低,请更新至最新版本。');
}
}
});
});
wx.error(function(res) {
console.log('111', res);
});
},
四、提现成功返回上一页,并刷新余额
参考文章-刷新上一页数据