微信支付:
wxpay () {
let params = {
actCode: this.actCode,// 活动编号
channelType: 'WxPay', // 支付方式
clientType: this.clientType, // 渠道(未传,浏览器后端默认设置的web, iOS/ Android/, 详情请查看底部获取渠道代码)
mobile: localStorage.mobile,// 当前手机号
amount: amount // 金额
tradeType: 'MWEB' // 类型(未传, 后端兼容)
returnUrl: window.location.origin + window.location.pathname + '?params=' + this.$route.query.params
// 这里添加returnURl参数, 微信支付成功后Safari可以自动返回并刷新, 安卓手机的自带浏览器返回后不刷新,所以还需加上该参数
}
console.log(params)
this.$axios2.post(`${MKTWEB}/workwx/getPayInfo`, params).then(res => {
console.log(res)
if (res.code === 1) {
// 获取返回数据并转为json字符串
let resData = JSON.parse(res.data)
console.log(resData)
// mwebUrl为后端接口返回, 直接赋值即可
window.location.href = resData.mwebUrl
} else {
this.$toast(res.msg)
}
})
}
支付宝支付:
alipay () {
let params = {
actCode: this.actCode,
channelType: 'AliPay',
clientType: this.clientType,
mobile: localStorage.mobile,
q: this.$route.query.q,
payAmount: this.couponPrice,
// 增加returnUrl, [因为支付宝支付成功后是不会返回到Safari浏览器的](https://opendocs.alipay.com/open/203/105288)
returnUrl: window.location.origin + window.location.pathname + '?params=' + this.$route.query.params
}
this.$axios2.post(`${MKTWEB}/workwx/getPayInfo`, params).then(res => {
if (res.code === 1) {
// 后端返回的form表单
let divForm = document.getElementsByTagName('divform')
if (divForm.length) {
document.body.removeChild(divForm[0])
}
const div=document.createElement('divform');
div.innerHTML=res.data;
document.body.appendChild(div);
document.forms[0].submit();
} else {
this.$toast(res.msg)
}
})
}