问题描述:
微信中对支付宝和淘宝的网址是直接屏蔽的,不能直接打開(除非复制链接用其他的浏览器打开),这样就会势必影响第三方在微信中的支付功能,很大程度上影响了用户对第三方应用的体验度。我们改如何突破呢这道防线呢?
原理分析:
微信是对跳转到支付宝的顶级域名(alipay.com)、淘宝的顶级域名(taobao.com)下的网址等进行屏蔽,遇到这两个顶级域名下的网址,微信就提示你复制网址在其他浏览器中打开。
解决思路:
iframe方式:
iframe(iframe详细讲解)调用的页面就是支付宝的支付页面,这样,顶层的页面的地址不是微信限制的地址,就能在此第三方平台页面中访问支付宝的支付页面。
document.getElementById("paymentiframe").src='http://wappaygw.alipay.com/service/rest.htm'+params;
实例:
——————————————————————————————————————————————————————————————————----假设当前页面名称为alipayWX.htm 内容如下(在此页面中的iframe中加载支付宝的支付页面)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>微信支付宝支付</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,height=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
<style type="text/css">
*{border:0;padding:0;margin:0;}
body{width:100%;height:100%;}
iframe{width:100%;height:100%;
margin:0 0 1em;
border:0;}
</style>
<script type="text/javascript">
<!--
//页面重新加载了
function setIframeHeight(iframe) {
if(num==1){//首次进入页面
num++;
}else{
//这里什么代码都不需要的说明:
//比如说:支付宝页面上返回的超链接地址指向的是http://xxxx.com/a.htm
//则要在a.htm的页面内容中加上 不让内嵌为iframe的js代码即可,如下
//if(window.top !== window.self){ window.top.location = window.location;}
//原理解释:在iframe内部打开的是支付宝的页面,点击页面内部的超链接返回到其它非支付宝的地址时,微信的内嵌浏览器是不新开页面的,还是在原来的iframe页面中打开新的非支付宝地址
//这样返回的商城的页面就会内嵌在iframe里了,加上此js代码后,页面自动返回顶层窗口,就不受限于iframe页面了
}
//-->
</script>
</head>
<body >
<iframe id="payment" name="payment" height="800" src="blank.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" οnlοad="setIframeHeight(this)" ></iframe>
<script type="text/javascript">
<!--
var num=1;
(function(){
var iframe = document.getElementById('payment');
var params=location.search;
if(params){
iframe.src='http://wappaygw.alipay.com/service/rest.htm'+params;//OK
}
})()
//-->
</script>
</body>
</html>