---- AI试用 ---域名问题某些图片和js资源无法访问,导致一些代码实例无法运行!(代码里gzui.net换成momen.vip即可)

h5调用支付宝支付

前端开发 蚂蚁 1211℃ 0评论

https://opensupport.alipay.com/support/home.htm

handleAliPay(){
	if (/MicroMessenger/.test(window.navigator.userAgent)) {
		console.log('handleAliPay 微信客户端');
	} else if (/AlipayClient/.test(window.navigator.userAgent)) {
		console.log('handleAliPay 支付宝客户端');
	} else {
		console.log('handleAliPay 其他浏览器');
	};
        //请求后台的支付接口
	this.$u.api.alipage({outTradeNo:new Date().getTime()})
	.then(res=>{
		let divForm = document.getElementsByTagName('divform')
		if (divForm.length) {
			 document.body.removeChild(divForm[0])
		}
	   const div = document.createElement('divform')
	   div.innerHTML = res.data // res.data就是sb支付宝返回给你的form
	   document.body.appendChild(div);
	   // document.forms[0].setAttribute('target', '_blank') // 加了_blank可能出问题所以我注释了
	   document.punchout_form.submit();
	   // document.getElementById('alipay_submit').submit();
	console.log('alipage',res);
	}).catch(err=>{
		console.log('alipage err',err);
	})
},

转载请注明:有爱前端 » h5调用支付宝支付

喜欢 (2)or分享 (0)