支付宝收费后跳转html代码,PC端支付宝开发最终的页面跳转问题

支付宝支付一般是请求接口后收到一组form表单代码,在h5中,可以直接像下面这样直接使用

doPayAlipay(alipayNeedParams).then(resAlipay=>{

if(resAlipay.code==0){

const div = document.createElement('div');

div.innerHTML = resAlipay.data.form;

document.body.appendChild(div);

document.getElementById('alipayForm').submit();

}

})

但是在pc中就不能酱紫了,我们得给他新开一个标签页或者弹窗,那么可以使用window.open亦或者下面的方法

doPayAlipay(alipayNeedParams).then(resAlipay=>{

if(resAlipay.code==0){

const div = document.createElement('div');

div.innerHTML = `Alipay`;

document.body.appendChild(div);

document.getElementById('triggerAlipay').click()

}

})

但是最终酱紫是会被浏览器拦截掉的,因为该操作不是用户主动触发的,浏览器认为酱紫不安全所以拦截了( _self 不会限制)

最终找到一个相对完美的方法,先打开一个空白页,待异步成功之后再赋予链接地址:

let newOpenWindow = window.open('about:blank');

doPayAlipay(alipayNeedParams).then(resAlipay=>{

if(resAlipay.code==0){

this.$tools.storage.set('alipayForm', resAlipay.data.form)

newOpenWindow.location = this.payAliUrl

// ...

}

})

中转页面类似这样:

即将跳转到支付宝...

export default {

head(){

return {

title: '跳转中...'

}

},

created(){

if(process.client){

let alipayForm = this.$tools.storage.get('alipayForm')

if(alipayForm && this.$store.getters.isLogin){

const div = document.createElement('div');

div.innerHTML = alipayForm;

document.body.appendChild(div);

this.$tools.storage.remove('alipayForm')

document.getElementsByName('punchout_form')[0].submit();

}else{

this.$alert('非法进入!','警告',{showClose:false}).then(()=>{

this.$router.replace(this.$tools.urlMerge('/', this.$route))

})

}

}

}

}

相关资料

支付宝小程序扫码跳转指定页面的实现方式是在小程序的app.js文件中的onLaunch方法中获取到二维码的参数,并将其存储在全局变量中。具体的代码如下所示:\[1\]\[2\] ```javascript onLaunch(options) { // 获取关联普通链接二维码的码值(即二维码地址),放到全局变量qrCode中 if (options.query && options.query.qrCode) { this.qrCode = options.query.qrCode; } } ``` 在二维码链接的地址中,包含了需要跳转的页面信息。例如,如果二维码链接的地址为https://www.test.com/abc,则在小程序中扫描该二维码后,可以通过截取字符串的方式获取到具体需要使用的参数。\[3\]通过这些参数,可以实现在支付宝小程序中跳转到指定页面。 #### 引用[.reference_title] - *1* [记录支付宝微信小程序扫码进入指定页面](https://blog.csdn.net/weixin_53224223/article/details/127451226)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [实现支付宝APP扫码跳转小程序并传参](https://blog.csdn.net/2301_77281342/article/details/129797966)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值