通過(guò)掃描二維碼下載APP已成為一個(gè)非常方便的通過(guò)掃描二維碼下載APP已成為一個(gè)大家常用且非常方便的方式,微信也成為掃描二維碼重要的工具,但是很多用戶用微信掃描后會(huì)提示“已停止訪問(wèn)網(wǎng)頁(yè)”,這是因?yàn)槲⑿虐涯愕逆溄訑r截了,微信scheme接口會(huì)對(duì)含APK和IOS文件的鏈接進(jìn)行屏蔽,所以用戶在微信中無(wú)法打開(kāi)。
此時(shí)就需要用戶在微信內(nèi)無(wú)論是直接打開(kāi)鏈接還是識(shí)別二維碼都能直接下載app。這個(gè)功能的實(shí)現(xiàn)需要對(duì)app的php代碼進(jìn)行相關(guān)的處理,下面給大家講解一下這個(gè)功能的實(shí)現(xiàn)的方式和效果。
實(shí)現(xiàn)教程:http://www.zjychina.cn
功能實(shí)現(xiàn)后ios系統(tǒng)可在微信內(nèi)直接下載app,安卓則自動(dòng)跳轉(zhuǎn)瀏覽器下載。
1. App Store應(yīng)用實(shí)現(xiàn)效果

2. 企業(yè)版app實(shí)現(xiàn)效果

3. 安卓用戶則自動(dòng)打開(kāi)手機(jī)瀏覽器下載app。

代碼編程
HTML代碼
var ua?= navigator.userAgent;
var isWeixin =??!!/MicroMessenger/i.test(ua);
CSS代碼
1 #weixin-tip{display:none;position:fixed;left:0;top:0;background:rgba(0,0,0,0.8);filter:alpha(opacity=80);width:100%;height:100%;z-index:100;}
2 #weixin-tip p{text-align:center;margin-top:10%;padding:0 5%;position:relative;}
3 #weixin-tip .close{color:#fff;padding:5px;font:bold 20px/24px simsun;text-shadow:0 1px 0 #ddd;position:absolute;top:0;left:5%;}
JS封裝代碼
1 var is_weixin = (function(){return navigator.userAgent.toLowerCase().indexOf(‘micromessenger’) !== -1})();
2 window.onload = function() {
3 var winHeight = typeof window.innerHeight != ‘undefined’ ? window.innerHeight : document.documentElement.clientHeight; //兼容IOS,不需要的可以去掉
4 var btn = document.getElementById(‘J_weixin’);
5 var tip = document.getElementById(‘weixin-tip’);
6 var close = document.getElementById(‘close’);
7 if (is_weixin) {
8 btn.onclick = function(e) {
9 tip.style.height = winHeight + ‘px’; //兼容IOS彈窗整屏
10 tip.style.display = ‘block’;
11 return false;
12 }
13 close.onclick = function() {
14 tip.style.display = ‘none’;
15 }
16 }
17 }