vue 微信支付 支付宝支付

需求:vue页面嵌套在安卓或者苹果app里面 在vue页面完成支付宝 或者 微信的支付
说明:一开始在做这个需求的时候 以为只是请求后端的接口而已 后来才知道并不是 请求完接口之后还是要前端进行一些操作
代码:
微信支付

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支付官方文档

发布了7 篇原创文章 · 获赞 2 · 访问量 176

猜你喜欢

转载自blog.csdn.net/qq_40630064/article/details/104018082