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);
}

};

转载于:https://www.cnblogs.com/sunhuinaxixi/p/10566976.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值