經過weixin://來打開微信客戶端:android
<a href="weixin://">打開微信</a> <a href="weixin://dl/business/?ticket=xxx">微信內打開網頁</a>
經過反編譯,看到weixin://協議的入口定義爲WXCustomSchemeEntryActivity
,那就是瀏覽器訪問以weixin爲scheme的請求時就會打開微信內的WXCustomSchemeEntryActivity
。瀏覽器
<activity android:name="com.tencent.mm.plugin.base.stub.WXCustomSchemeEntryActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:excludeFromRecents="true" android:exported="true" android:launchMode="singleTop" android:taskAffinity=".wxpayentry" android:theme="@style/mm"> <intent-filter> <data android:scheme="weixin" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity>
Uri data = getIntent().getData(); if (data != null) { String scheme = data.getScheme(); String host = data.getHost(); String query = data.getQuery(); Log.i("MicroMsg.WXCustomSchemeEntryActivity", String.format("uri is %s,scheme is %s, host is %s, query is %s", data.toString(), scheme, host, query)); }
// 校驗是否非法 if (data != null) { String uri = data.getScheme() + "://" + data.getHost() + data.getPath(); // qby詳情看問末附錄 if (!qby.containsKey(uri) && !data.toString().startsWith("weixin://dl/business")) { return; } }
根據url對應的地址,調用微信內的路由組件進行跳轉。微信
HashMap qyb = new HashMap(); qyb.put("weixin://", 0L); qyb.put("weixin://dl/stickers", 1L); qyb.put("weixin://dl/games", 2L); qyb.put("weixin://dl/moments", 4L); qyb.put("weixin://dl/add", 8L); qyb.put("weixin://dl/shopping", 16L); qyb.put("weixin://dl/groupchat", 32L); qyb.put("weixin://dl/scan", 64L); qyb.put("weixin://dl/profile", 128L); qyb.put("weixin://dl/settings", 256L); qyb.put("weixin://dl/general", 512L); qyb.put("weixin://dl/help", 1024L); qyb.put("weixin://dl/notifications", 2048L); qyb.put("weixin://dl/terms", 4096L); qyb.put("weixin://dl/chat", 8192L); qyb.put("weixin://dl/features", 16384L); qyb.put("weixin://dl/clear", 32768L); qyb.put("weixin://dl/feedback", 65536L); qyb.put("weixin://dl/faq", 131072L); qyb.put("weixin://dl/recommendation", 262144L); qyb.put("weixin://dl/groups", 524288L); qyb.put("weixin://dl/tags", 1048576L); qyb.put("weixin://dl/officialaccounts", 2097152L); qyb.put("weixin://dl/posts", 4194304L); qyb.put("weixin://dl/favorites", 8388608L); qyb.put("weixin://dl/privacy", 16777216L); qyb.put("weixin://dl/security", 33554432L); qyb.put("weixin://dl/wallet", 67108864L); qyb.put("weixin://dl/businessPay", 134217728L); qyb.put("weixin://dl/businessPay/", 134217728L); qyb.put("weixin://dl/wechatout", 268435456L); qyb.put("weixin://dl/protection", 1073741824L); qyb.put("weixin://dl/card", 2147483648L); qyb.put("weixin://dl/about", 1125899906842624L); qyb.put("weixin://dl/blacklist", 4294967296L); qyb.put("weixin://dl/textsize", 8589934592L); qyb.put("weixin://dl/sight", 17179869184L); qyb.put("weixin://dl/languages", 34359738368L); qyb.put("weixin://dl/chathistory", 68719476736L); qyb.put("weixin://dl/bindqq", 137438953472L); qyb.put("weixin://dl/bindmobile", 274877906944L); qyb.put("weixin://dl/bindemail", 549755813888L); qyb.put("weixin://dl/securityassistant", 1099511627776L); qyb.put("weixin://dl/broadcastmessage", 2199023255552L); qyb.put("weixin://dl/setname", 4398046511104L); qyb.put("weixin://dl/myQRcode", 8796093022208L); qyb.put("weixin://dl/myaddress", 17592186044416L); qyb.put("weixin://dl/hidemoments", 35184372088832L); qyb.put("weixin://dl/blockmoments", 70368744177664L); qyb.put("weixin://dl/stickersetting", 140737488355328L); qyb.put("weixin://dl/log", 281474976710656L); qyb.put("weixin://dl/wechatoutcoupon", 562949953421312L); qyb.put("weixin://dl/wechatoutshare", 18014398509481984L); qyb.put("weixin://dl/personalemoticon", 4503599627370496L); qyb.put("weixin://dl/designeremoji", 9007199254740992L); qyb.put("weixin://dl/sightdraft", 576460752303423488L); qyb.put("weixin://dl/jumpWxa/", 576460752303423489L); qyb.put("weixin://dl/offlinepay/", 576460752303423490L);