admin管理员组文章数量:1616033
问题:在开发网页支付宝支付业务时,调用支付宝的返回的是一个完整的html页面,浏览器误认为是广告类窗口进行拦截屏蔽。
解决办法:主动触发打开新的标签页
// 生成订单号,跳转项目空页面渲染支付宝返回的完整页面
generateOrderNo() {
// 开启一个新的标签页
const newWin = window.open('about:blank');
this.$http.post(userSelfUrl + '/order', this.itemsInfo).then((res) => {
if (res.data.ecode == ResEcode) {
const resData = res.data.data
const data = { orderNo: resData.orderNo, rechargeType: 1 }
const {href} = this.$router.resolve({ name: 'Alipay', query: data })
const url = 'http://' + window.location.host + '/' + href
// 重定向url到项目中的空页面
newWin.location.href = url
} else {
this.responseText = res.data.msg
}
})
}
// 支付组件
<template>
<div>
<div v-html="alipayInfo"></div>
</div>
</template>
<script>
import {userSelfUrl} from '../../../assets/js/api'
export default {
name:'Alipay',
data(){
return {
alipayInfo:''
}
},
methods:{
toPay (data) {
// 根据订单数据请求支付宝的支付页面
this.$http.post(userSelfUrl + '/pay', data).then((res) => {
if (res.data.ecode == ResEcode) {
//得到的支付宝的完整支付页面字符串
this.alipayInfo = res.data.data
} else {
this.responseText = res.data.msg
}
})
},
},
created (){
this.toPay(this.$route.query)
},
updated () {
// 支付宝支付页面提交付款
document.forms[0].submit()
}
}
</script>
当然还有其他更好的办法,仅供参考
版权声明:本文标题:调用支付宝网页支付被浏览器拦截 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1728736089a1170909.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论