uni-app中小程序微信支付获取code后请求支付接口的方法
pay(id) { console.log(id) if(id != ""){ uni.login({ provider: 'weixin', success: (loginRes) => {
将获取的code传给后台服务器,后台再返回一堆微信认可的数据给前端,前端组装数据再请求微信接口 this.$api.bank.extractPay(id,loginRes.code).then(res => { console.log(res) if(res.status == "200" || res.status == "201" || res.status == "204") { if(res.data.meta) { let payObj = res.data.meta payObj.success = (val) => { console.log(val) uni.showToast({ title: "支付成功!", duration: 1500, success: () => { uni.switchTab({url: "../library/library"}) } }) }; payObj.fail = (val) => { console.log(val) uni.showToast({ title: "用户取消付款!", duration: 1500, success: () => { uni.switchTab({url: "../library/library?topIndex="+1+'&subIndex='+3}) } }) } uni.requestPayment(payObj); } } }) } }) } },