调用支付宝网页支付被浏览器拦截

问题:在开发网页支付宝支付业务时,调用支付宝的返回的是一个完整的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>

当然还有其他更好的办法,仅供参考
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值