根据网友们提供的思路,本文整理了三种方案。
1、申请腾讯开放平台开发者
具体流程可以去访问http://open.qq.com/,大概的意思是需要将apk提交到腾讯开放平台的里面,每个apk应该会自动生成一个二维码,每年支付一定的费用,然后在微信里面扫一下这个二维码,这个时候也需要先安装一个手机应用宝,才能进行 apk的安装。
对于这种方案,只能用一种很流行的话说:”很任性”。
2、重定向
这种方法对于一些已经发布出去的二维码比较有用,也是目前比较普遍的做法。不可能因为微信不能直接下载了,就得把所有的已经流出去的二维码重新生成吧?
2.1判断浏览器类型
/*首先判断是否是pc,若是pc访问则跳转到http://app.ctrip.com/*/
var u = navigator.userAgent || '';
var isPC = !/(iphone|ios|android|mini|mobile|mobi|Nokia|Symbian|iPod|iPad|Windows\s+Phone|MQQBrowser|wp7|wp8|UCBrowser7|UCWEB|360\s+Aphone\s+Browser)/i.test(u);
if (isPC) { location.href = "http://www.hipermart.com.cn"; }
如果是pc端的话,那么直接重定向到一个网站
如果是非pc端的话,那么要区分是android还是apple?
2.2判断是android还是iOS?
因为我们假设iOS的下载必须从苹果的appstore里面下载,那么其下载地址有一定的规律,比如说sourceid等。
可以通过一个正则表达式来确定。
var urls = document.location.search, re2 = new RegExp("(\\\?|&)sourceid=([^&]+)(&|$)", "i"), from = urls.match(re2);
if (from) { sid = from[2]; }
document.location.search
比如一个URL是XXXX?g=1,那么document.location.search的值就是?g=1
2.3重定向到下载地址
window.onload = function () { //修复图片偶尔不能加载
var salesLocal = localStorage.getItem("SALESOBJ") ? JSON.parse(localStorage.getItem("SALESOBJ")) : null;
var appUrl = salesLocal && salesLocal.data && salesLocal.data.appurl ? salesLocal.data.appurl : "";
if (!isPC && !iswx) {
if(appUrl){
location.href = appUrl;
}else if(sid){
location.href = "/m/" + sid;
}
}
}
2.4 html页面源文件
body {height: 100%;}
.container {padding:0 20px;background-image: url(images/bg.jpg);background-position: center center;background-size: 100% 100%;height: 100%;}
.dl-step {padding-top: 58px;}
.dl-step .step {clear: both;}
.dl-step .index {float: left;height: 36px;width: 36px;border: 2px solid #fff;background-color: #ffba26;border-radius: 50%;text-align: center;line-height: 36px;position: relative;background-clip: padding-box;color: #fff;}
.dl-step .content {margin-left: 70px;border-radius: 4px;padding:8px 13px 13px;position: relative;}
.dl-step-1 {margin-bottom: 60px;position: relative;}
.dl-step-1 .content {background-color: #ffba26;box-shadow: 0 1px 2px rgba(0,0,0,0.5);font-size: 15px;color: #fff;padding: 0 13px;height: 38px;line-height: 38px;}
.dl-step-1:before {
content: "";
display: block;
width: 89px;
height: 75px;
position: absolute;
right: 0;
top: -56px;
background-image: url(images/icons.png);
background-size: auto 213px;
background-repeat: no-repeat;
background-position: 0 0;
z-index: 10;
}
.dl-step-1 .index:before {
content: "";
display: block;
height: 45px;
width: 2px;
background-color: #fff;
position: absolute;
top: 45px;
left: 17px;
border-radius: 2px;
}
.dl-step-2 {margin-bottom: 58px;}
.dl-step-2 .index, .dl-step-3 .index {background-color: rgba(39,41,57,0.2);}
.dl-step-2 .content, .dl-step-3 .content {background-color: rgba(255,255,255,0.9);box-shadow: 0 1px 2px rgba(0,0,0,0.3);}
.dl-step-2 .content .tip, .dl-step-3 .content .tip {margin-bottom: 2px;font-size: 15px;color: #333;font-family: Microsoft Yahei;}
.dl-step-2 .index:before {
content: "";
display: block;
height: 128px;
width: 2px;
background-color: #fff;
position: absolute;
top: 45px;
left: 17px;
border-radius: 2px;
}
.dl-devices {overflow: hidden;}
.dl-devices .item {background-color: #ceecfb;width: 49%;float: left;padding: 5px 0;}
.dl-devices .android {margin-left: 1px;}
.dl-devices .name {float: left;background-color: #fff;padding: 0 4px;color: #666;line-height: 14px;font-size: 12px;font-family: Microsoft Yahei;}
.dl-devices .icon {height: 40px;clear: left;background-image: url(images/icons1.png);background-size: auto 213px;background-repeat: no-repeat;}
.dl-devices .desc {color:#666;font-size: 10px;text-align: center;font-family: Microsoft Yahei;}
.dl-devices .ios .icon {background-position: center -85px;}
.dl-devices .android .icon {background-position: center -131px;}
.dl-step-3 .app {background-color: #ceecfb;padding: 8px 25px;}
.dl-step-3 .app .icon {padding-left: 38px;height:31px;line-height:31px;background-image: url(images/icons2.png);background-repeat: no-repeat;background-position: -29px -182px;background-size: auto 213px;font-size: 10px;color: #666;font-family: Microsoft Yahei;}
.dl-step .content:before {
content: "";
display: block;
height: 0;
width: 0;
border: 5px solid transparent;
border-right-color: rgba(0,0,0,0.1);
position: absolute;
top: 14px;
left: -11px;
}
.dl-step .content:after {
content: "";
display: block;
height: 0;
width: 0;
border: 5px solid transparent;
position: absolute;
top: 13px;
left: -10px;
}
.dl-step-1 .content:after {border-right-color: #ffba26;}
.dl-step-2 .content:after, .dl-step-3 .content:after {border-right-color: rgba(255,255,255,0.9);}
/*首先判断是否是pc,若是pc访问则跳转到http://app.ctrip.com/*/
var u = navigator.userAgent || '';
var isPC = !/(iphone|ios|android|mini|mobile|mobi|Nokia|Symbian|iPod|iPad|Windows\s+Phone|MQQBrowser|wp7|wp8|UCBrowser7|UCWEB|360\s+Aphone\s+Browser)/i.test(u);
if (isPC) { location.href = "http://www.hipermart.com.cn"; }
var isPC = false;
var e = navigator.userAgent ? navigator.userAgent.toLowerCase() : '';
var iswx = /micromessenger/.test(e) ? !0 : !1;
var wxurl = '';
if (iswx) {
wxurl = "http://mp.weixin.qq.com/mp/redirect?url=";
}
// window.onload = function () { //修复图片偶尔不能加载
function hello() { //修复图片偶尔不能加载
var appUrl = "http://app.hipermart.com.cn:8888/apk/hipermart.apk";
if (!isPC && !iswx) {
if(appUrl){
location.href = appUrl;
}else if(sid){
location.href = "/m/" + sid;
}
}
}
点击右上方
选择在浏览器中打开
安卓
在浏览器中打开
即可自动下载APP
海玛特客户端