wap站打开app

var down = {
sign: '',
phoneType: 0,
shopType: 0,
goUrl: "",
openAppCommand: "",//打开app模块的参数
openAppModelParam: {},
init: function (sign, obj) {
var that = this;
that.openAppModelParam = obj;
that.getRealSign(sign);
},
getRealSign: function (signparam) { //获得真正的sign值
var that = this;
$.ajax({
url: 'http://appconfig.wangxiao.cn/Service/GetAdviertisement?sign=' + signparam + '&DeviceType=' + 0,
type: 'GET',
dataType: 'jsonp',
success: function (result) {
if (result.ResultCode == 0) {
that.sign = result.Data.Sign;
that.judgePhoneType();
if (that.shopType == 10) {
that.getUrlonAndroid();
window.location.href = that.goUrl;
} else {
//android       
if (that.phoneType == 0) {
that.getUrlonAndroid();
that.createCommandAndstorage();
//打开app
window.location.href = that.openAppCommand;
//跳转至应用宝
setTimeout(function () {
window.location.href = that.goUrl;
}, 1000);
}
//苹果商店链接
if (that.phoneType == 1) {
that.getUrlonIOS();
}
}
}
},
error: function (msg) {
console.log(msg);
}
});
},
judgePhoneType: function () { //判断机型和微信浏览器
var that = this;
var u = navigator.userAgent;
//判断手机类型
if (u.indexOf('MicroMessenger') > -1) {
that.shopType = 10;
//alert("微信浏览器");
} else {
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) { //安卓手机
that.shopType = 0;
//alert("安卓")
} else if (u.indexOf('iPhone') > -1) { //苹果手机
that.phoneType = 1;
//alert("苹果")
}
}
},
getUrlonAndroid: function () {
var that = this;
if (that.sign == 'ztk') {
that.goUrl = 'http://a.app.qq.com/o/simple.jsp?pkgname=cn.wangxiao.zhuntiku';
} else {
that.goUrl = 'http://a.app.qq.com/o/simple.jsp?pkgname=cn.wangxiao.' + that.sign + 'zhuntiku';
}
},
getUrlonIOS: function () {
var that = this;
$.ajax({
url: 'http://appconfig.wangxiao.cn/Service/GetAdviertisement?sign=' + that.sign + '&DeviceType=' + 1,
type: 'GET',
dataType: 'jsonp',
success: function (result) {
if (result.ResultCode == 0) {
that.goUrl = result.Data.AppUrl;
//打开app
that.createCommandAndstorage();
window.location.href = "../../download/index.html";
}
}
});
},
createCommandAndstorage: function () {
var that = this;
//如果是大的准题库就清空
if (that.sign == "ztk") {
that.sign = "";
}
//默认0是安卓手机
if (that.phoneType == 0) {
//安卓唤起的本地app的地址'+sign+'
that.openAppCommand = 'cn.wangxiao.' + that.sign + 'zhuntiku://zdwx';
} else if (that.phoneType == 1) {
//如果是苹果手机
that.openAppCommand = that.sign + "zhuntiku://";
}
that.openAppCommand = that.openAppCommand + "?type=" + that.openAppModelParam.Type + "&typeAction=" + that.openAppModelParam.TypeAction + "&param=" + JSON.stringify(that.openAppModelParam).replace(/&/g, "&");
//url scheme地址保存
localStorage.setItem("schemeurl", that.openAppCommand);
//手机类型
localStorage.setItem("phonetype", that.phoneType);
//只用苹果的此链接
localStorage.setItem("iosshophref", that.goUrl);
}

};
posted @ 2019-03-20 19:12  warmDoll  阅读(604)  评论(0编辑  收藏  举报