需求:vue页面嵌套在安卓或者苹果app里面 在vue页面完成支付宝 或者 微信的支付
说明:一开始在作这个需求的时候 觉得只是请求后端的接口而已 后来才知道并非 请求完接口以后仍是要前端进行一些操做
代码:
微信支付php
saveWechat(){//微信支付 let _this = this; _this.common.ajax({ method: 'post', url: '/members/payPreFee', responseType: 'text', data: { id :_this.$route.query.id, payway :'wechat', }, success(response) { window.location.href = response.data.data.code_url;//微信支付 请求接口成功以后 跳转页面 地址为后端返回的地址 } }); },
支付宝支付前端
saveAlipay(){//支付宝支付 let _this = this; _this.axios({ method: 'post', url: '/members/payPreFee', responseType: 'text', data:{ id :_this.$route.query.id, payway : 'alipay', }, }) .then(function(response) {//后端接口请求成功以后 后端会返回表单 前端提交表单 const div = document.createElement('div'); div.innerHTML = response.data; document.body.appendChild(div); div.style.display="none"; document.forms.alipaysubmit.submit(); }) .catch(function(error) { layer.tipsX(error); }); }
app 须要作一些兼容:
能够参照 微信h5支付 或者 支付宝h5支付 官方提供的方法,亲测能够。
支付宝网站支付文档
微信h5支付官方文档vue