需求: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