安卓微信中下载apk无反应 微信浏览器无法跳转到apk下载链接方案

此方法可以实现微信内置浏览器跳转到手机其它浏览器,现在网上其它的方法都只是一个页面,让访问者自己手动点右上角浏览器打开,而这个不同,是可以直接自动跳转的。

安卓访问时可以直接自动跳转浏览器;

 

<?php
error_reporting(0);
if($_GET['open']==1 && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger')!==false){
	header("Content-Disposition: attachment; filename=\"load.doc\"");
	header("Content-Type: application/vnd.ms-word;charset=utf-8");
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>Welcome</title>
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport"/>
	<meta content="yes" name="apple-mobile-web-app-capable"/>
	<meta content="black" name="apple-mobile-web-app-status-bar-style"/>
	<meta name="format-detection" content="telephone=no"/>
	<meta content="false" name="twcClient" id="twcClient"/>
	<style>
	body,html{width:100%;height:100%}
	*{margin:0;padding:0}
	body{background-color:#fff}
	.top-bar-guidance{font-size:15px;color:#fff;height:40%;line-height:1.8;padding-left:20px;padding-top:20px;background:url(//gw.alicdn.com/tfs/TB1eSZaNFXXXXb.XXXXXXXXXXXX-750-234.png) center top/contain no-repeat}
	.top-bar-guidance .icon-safari{width:25px;height:25px;vertical-align:middle;margin:0 .2em}
	.app-download-btn{display:block;width:214px;height:40px;line-height:40px;margin:18px auto 0 auto;text-align:center;font-size:18px;color:#2466f4;border-radius:20px;border:.5px #2466f4 solid;text-decoration:none}
</style>
</head>
<body>
	<div class="top-bar-guidance">
		<p>
			点击右上角<img src="//gw.alicdn.com/tfs/TB1xwiUNpXXXXaIXXXXXXXXXXXX-55-55.png" class="icon-safari"/> Safari打开
		</p>
		<p>
			可以继续访问本站哦~
		</p>
	</div>
	<a class="app-download-btn" id="BtnClick" href="javascript:;"> 点此继续访问 </a>
	<script>
		var url = 'http://www.youngxj.cn';//更改需要跳转的地址
		document.querySelector('body').addEventListener('touchmove', function (event) {
			event.preventDefault();
		});
		window.mobileUtil = (function(win, doc) {
			var UA = navigator.userAgent,
			isAndroid = /android|adr/gi.test(UA),
			isIOS = /iphone|ipod|ipad/gi.test(UA) && !isAndroid,
			isBlackBerry = /BlackBerry/i.test(UA),
			isWindowPhone = /IEMobile/i.test(UA),
			isMobile = isAndroid || isIOS || isBlackBerry || isWindowPhone;
			return {
				isAndroid: isAndroid,
				isIOS: isIOS,
				isMobile: isMobile,
				isWeixin: /MicroMessenger/gi.test(UA),
				isQQ: /QQ/gi.test(UA)
			};
		})(window, document);
		if(mobileUtil.isWeixin){
			if(mobileUtil.isIOS){
				url = "https://t.asczwa.com/taobao?backurl=" + encodeURIComponent(url);
				document.getElementById('BtnClick').href=url;
			}else if(mobileUtil.isAndroid){
				url = '?open=1';
				document.getElementById('BtnClick').href=url;
				var iframe = document.createElement("iframe");
				iframe.style.display = "none";
				iframe.src = url;
				document.body.appendChild(iframe);
			}
		}else{
			document.getElementById('BtnClick').href=url;
			window.location.replace(url);
		}
	//setTimeout('WeixinJSBridge.invoke("closeWindow", {}, function(e) {})', 2000); </script>
</body>
</html>

lle4wo6f.png

好了,废话不多说了,直接上方案。

这个方案需要我们借助一个外部的接口来实现此功能 

我们在他们那边租用了此接口,测试地址:http://wzf.zjychina.cn/wt0187.html

通过租用的接口可以实现安卓端微信直接唤醒手机默认浏览器打开指定的链接,从而实现下载APP的功能,

案例展示:

 

具体实现原理:

利用HTTP请求中Header中的user-agent字段,来识别用户的客户端,如果判断用户是在微信中打开的链接,则自动打开系统手机浏览器来打开链接。如果是在手机浏览器打开,则正常访问。

判断用户客户端的Javasript代码如下:

function is_wechat_client(){

      var ua = navigator.userAgent.toLowerCase();

      if(ua.match(/MicroMessenger/i)=="micromessenger"){

          return true;

      }else{

          return false;

      }

}

好了,亲们,上面两种办法笔者都尝试过了,均可行。如果你有更好的办法可以在此处留言,方便广大码友

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值