App呼起京东和淘宝指定的页面

需求: 需要在自己的App直接打开京东和淘宝指定的页面。

对于ios,首先想到的是根据页面的js找到对应的universal link。ios9以下和安卓就用schema跳转。

对于京东的链接 https://pro.m.jd.com/mall/active/3pR34myNmV7cXiR4DjzUSRuu5hqA/index.html?ad_od=1&utm_source=kong&utm_medium=zssc&utm_campaign=t_1000210271_100854&utm_term=ea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854&jd_pop=ea62df13-dc13-44c8-ae00-59b5683ec8f2&abt=0 分析源码https://st.360buyimg.com/common/commonH_B/js/m_common_merge2.1.js 网上还找到这个版本的js

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
aE(e.openAppBtnId, "click", function() {
aw("0");
var aU = this.getAttribute("id");
var aR = aI[aU];
// 添加断点,跟踪代码
if (!i) {
var aT = document.createElement("iframe");
aT.id = aj;
document.body.appendChild(aT);
document.getElementById(aj).style.display = "none";
document.getElementById(aj).style.width = "0px";
document.getElementById(aj).style.height = "0px";
i = true
}
if (aR.openAppCallback) {
var aS = aR.openAppCallbackSource ? aR.openAppCallbackSource : null;
aR.openAppCallback.call(this, aS)
}
f(aR, "appDownOpenIntervalTime");
aH(aR);
if (l.isUseUniversalLinks && !aR.noJdApp) {
az(aR)
} else {
af(aR)
}
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function az(aS) {
var aV = aQ(aS, true);
var aT = aS.universalLinksUrl + "/ul/ul.action?" + aV;
// 可以判定aT应该就是universal links
if (navigator.userAgent.indexOf("baidubrowser") >= 0) {
window.location.href = aT
} else {
var aR = document.createElement("a");
aR.setAttribute("href", aT);
aR.style.display = "none";
document.body.appendChild(aR);
var aU = document.createEvent("HTMLEvents");
aU.initEvent("click", !1, !1);
aR.dispatchEvent(aU)
}
}

测试发现根据代码获得universal link只能打开京东的首页https://linkst.m.jd.com/ul/ul.action?openApp.jdMobile://virtual?params={"category":"jump","des":"m","sourceValue":"babel-act","sourceType":"babel","url":"https%3A%2F%2Fpro.m.jd.com%2Fmall%2Factive%2F3pR34myNmV7cXiR4DjzUSRuu5hqA%2Findex.html%3Fad_od%3D1%26utm_source%3Dkong%26utm_medium%3Dzssc%26utm_campaign%3Dt_1000210271_100854%26utm_term%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854%26jd_pop%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2%26abt%3D0","M_sourceFrom":"H5_UL","msf_type":"click","NoJumpDownLoadPage":false,"downAppIos":"https%3A%2F%2Fst.360buyimg.com%2Fcommon%2FdownLoadCommon%2FdownLoadAppIOSMPage.html","locationHref":"https%3A%2F%2Fpro.m.jd.com%2Fmall%2Factive%2F3pR34myNmV7cXiR4DjzUSRuu5hqA%2Findex.html%3Fad_od%3D1%26utm_source%3Dkong%26utm_medium%3Dzssc%26utm_campaign%3Dt_1000210271_100854%26utm_term%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854%26jd_pop%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2%26abt%3D0","m_param":{"m_source":"0","event_series":{},"jda":"122270672.2074471510.1521534916.1522766295.1522991099.5","usc":"kong","ucp":"t_1000210271_100854","umd":"zssc","utr":"ea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854","jdv":"122270672%7Ckong%7Ct_1000210271_100854%7Czssc%7Cea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854%7C1522991529755","ref":"https%3A%2F%2Fpro.m.jd.com%2Fmall%2Factive%2F3pR34myNmV7cXiR4DjzUSRuu5hqA%2Findex.html%3Fad_od%3D1%26utm_source%3Dkong%26utm_medium%3Dzssc%26utm_campaign%3Dt_1000210271_100854%26utm_term%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854%26jd_pop%3Dea62df13-dc13-44c8-ae00-59b5683ec8f2%26abt%3D0","psn":"2074471510|5","psq":14,"unpl":"V2_ZzNsbRBVFkAiXE9dZx5dVTUfFwlEUV9FdwFHSClNDgFkURpaF1MXQWlJKFRzEVQZJkB8XUNRRAklTShUehhVAWIzEVxCXl8UdxREVWoaXw5mBRldRGdDJXUJR1V4GV0GYQMibXJXQSV0OEVVfRxZA2cHElxyURNHdV1PBC8FCVJvAw5YRABBCSYIE1JnGQhWbwQRW0FQQ0ImOEBS","pc_source":"","mba_muid":"2074471510","mba_sid":"15229910996761532999810513868","mt_xid":"","mt_subsite":""},"SE":{"mt_subsite":"","__jdv":"122270672%7Ckong%7Ct_1000210271_100854%7Czssc%7Cea62df13-dc13-44c8-ae00-59b5683ec8f2-p_1999-pr_1076-at_100854%7C1522991529755","unpl":"V2_ZzNsbRBVFkAiXE9dZx5dVTUfFwlEUV9FdwFHSClNDgFkURpaF1MXQWlJKFRzEVQZJkB8XUNRRAklTShUehhVAWIzEVxCXl8UdxREVWoaXw5mBRldRGdDJXUJR1V4GV0GYQMibXJXQSV0OEVVfRxZA2cHElxyURNHdV1PBC8FCVJvAw5YRABBCSYIE1JnGQhWbwQRW0FQQ0ImOEBS","__jda":"122270672.2074471510.1521534916.1522766295.1522991099.5"}}

初步怀疑:

  • 是不是参数没有encode
  • schema的大小写是不是有问题

猜测的结论

  • 京东和微信的关系,京东的schema是白名单,打开App没有限制,而对universal link 的测试不充分,导致相应的链接有问题

通过测试其他的app打开京东的页面,首次有弹框是否打开京东的提示,确认后下次就没有,然而美妆心得的App就是无反应。

近期苹果公司iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。 来自 https://www.jianshu.com/p/a8cce94d508e

对于淘宝的链接https://h5.m.taobao.com/awp/core/detail.htm?id=528294025825&scm=1007.12144.81309.242610_242610&pvid=2f68b234-58a1-47de-aa7b-266c7abe0b48&spm=a217e.7680114.75b100109.d5n0

定位代码

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
e.exports = function(e) {
var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
if ("TB" != n.aliapp.appname && "TB-PD" != n.aliapp.appname) {
t.point = t.point || {},
t.point.callType = t.callType;
var a = (0,
r.default)(e, t)
, s = {
package: "com.taobao.taobao"
};
switch (t.callType) {
case "universalLink":
if (n.os.isIPhone && n.os.version.gte("9.0")) {
var l = (0,
o.appendParams)(t.universalLink || "//b.mashort.cn/ulk/taobao", {
smburl: encodeURIComponent(a)
});
t.redirectUrl && (l = (0,
o.appendParams)(l, {
redirectUrl: encodeURIComponent(t.redirectUrl)
})),
(0,
i.default)(l, "universalLink")
} else
(0,
i.default)(a, "scheme", s);
break;

获得的universal link。测试发现其实分享的淘宝口令http://m.tb.cn/h.WE82pie本身就是universal link

扩展阅读

参考