openapp.js
1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* 移动端尝试打开 app
*/
import utils from './utils';
import cookies from './cookies';
const channelMap = {
'baidu.com': 100000000000055,
'so.com': 100000000000049,
'sogou.com': 100000000000053,
'bing.com': 100000000000057,
'm.sm.cn': 100000000000059,
'google.com': 100000000000061
};
const getMktcBySeo = () => {
var mktc,
rf = document.referrer;
for (var domain in channelMap) {
if (rf.indexOf(domain) > -1) {
mktc = channelMap[domain];
break;
}
}
return mktc;
};
const getAppPath = () => {
let qs = utils.queryString();
let ct = qs.mkt_code || qs.union_type || cookies.cookie('unionTypeYas') || getMktcBySeo() || '100000000000349';
delete qs.openapp; // 防止重复打开
let shareParams = qs.share_id ? '"share":"/operations/api/v5/webshare/getShare","shareparam":{"share_id":"' + qs.share_id + '"},' : '',
appPath = 'yohobuy://yohobuy.com/goapp?ct='+ ct +'&openby:yohobuy={"action":"go.h5",' + shareParams +
'"params":{"islogin":"N","url":"http://feature.yoho.cn' + location.pathname + '","param":' + JSON.stringify(qs) + '}}';
return appPath;
};
export default {
init() {
if (utils.queryString().openapp) {
let u = navigator.userAgent.toLowerCase();
let isiOS = u.indexOf('os') > -1 || u.indexOf('iphone') > -1 || u.indexOf('mac') > -1 || u.indexOf('ipad') > -1;
let appPath = getAppPath();
if (isiOS) {
window.location.href = appPath;
} else {
let ifr = document.createElement('iframe');
ifr.src = appPath;
ifr.style.display = 'none';
document.body.appendChild(ifr);
}
}
}
};