主要思路是后端返回Url地址前端跳转
前端利用window.location.href = res2.data.data.mweb_url;进行跳转
// 点击按钮购买会员 H5支付
mobileZifuvip(i) {
console.log(i);
let that = this;
this.axios(
config +
"/order/purchaseMember?userId=" +
localStorage.getItem("userId") +
"&commodityNumber=" +
i,
{
sessionId: this.sessionId,
userId: localStorage.getItem("userId"),
spbillCreateIp: this.clientIp,
method: "post",
headers: {
Authorization: localStorage.getItem("token")
}
}
)
.then(res => {
// console.log(res, '支付信息')
that.closeFullScreen(that.openFullScreen()); // 取消加载
// 获取请求参数
this.axios({
url:
config + "/pay?type=WX_MWEB&&orderNumber=" + res.data.orderNumber,
headers: {
Authorization: localStorage.getItem("token")
},
// data: {
// userId : localStorage.getItem("userId"),
// },
method: "post"
})
.then(res2 => {
console.log(res2.data, "打印的请求参数");
window.location.href = res2.data.data.mweb_url;
if (res.status === 200) {
// 2. 发起支付请求
// 获取参数后跳转微信支付
window.location.href = res2.data.data.mweb_url;
}
})
.catch(err => {
that.closeFullScreen(that.openFullScreen()); // 取消加载
console.log(err);
});
})
.catch(err => {
that.closeFullScreen(that.openFullScreen()); // 取消加载
console.log(err);
});
},