天津出行司机端 v6.9.3版本的 MD5 值为:b7a18e0f0e865860fd80aa9ed7cf4ae1
以下内容为反编译后的 BridgeUtil.java 源代码,内容仅作参考
package com.github.lzyzsd.jsbridge;
import android.content.Context;
import android.webkit.WebView;
import com.didichuxing.doraemonkit.aop.WebViewHook;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class BridgeUtil {
static final String CALLBACK_ID_FORMAT = "JAVA_CB_%s";
static final String EMPTY_STR = "";
public static final String JAVASCRIPT_STR = "javascript:";
static final String JS_FETCH_QUEUE_FROM_JAVA = "javascript:WebViewJavascriptBridge._fetchQueue();";
static final String JS_HANDLE_MESSAGE_FROM_JAVA = "javascript:WebViewJavascriptBridge._handleMessageFromNative('%s');";
static final String SPLIT_MARK = "/";
static final String UNDERLINE_STR = "_";
static final String YY_FETCH_QUEUE = "yy://return/_fetchQueue/";
static final String YY_OVERRIDE_SCHEMA = "yy://";
static final String YY_RETURN_DATA = "yy://return/";
public static String parseFunctionName(String jsUrl) {
return jsUrl.replace("javascript:WebViewJavascriptBridge.", "").replaceAll("\\(.*\\);", "");
}
public static String getDataFromReturnUrl(String url) {
if (url.startsWith(YY_FETCH_QUEUE)) {
return url.replace(YY_FETCH_QUEUE, "");
}
String temp = url.replace(YY_RETURN_DATA, "");
String[] functionAndData = temp.split("/");
if (functionAndData.length >= 2) {
StringBuilder sb = new StringBuilder();
for (int i = 1; i < functionAndData.length; i++) {
sb.append(functionAndData[i]);
}
return sb.toString();
}
return null;
}
public static String getFunctionFromReturnUrl(String url) {
String temp = url.replace(YY_RETURN_DATA, "");
String[] functionAndData = temp.split("/");
if (functionAndData.length >= 1) {
return functionAndData[0];
}
return null;
}
public static void webViewLoadJs(WebView view, String url) {
String js = "var newscript = document.createElement(\"script\");newscript.src=\"" + url + "\";";
WebViewHook.inject(view);
view.loadUrl(WebViewHook.getSafeUrl(JAVASCRIPT_STR + (js + "document.scripts[0].parentNode.insertBefore(newscript,document.scripts[0]);")));
}
public static void webViewLoadLocalJs(WebView view, String path) {
String jsContent = assetFile2Str(view.getContext(), path);
WebViewHook.inject(view);
view.loadUrl(WebViewHook.getSafeUrl(JAVASCRIPT_STR + jsContent));
}
public static String assetFile2Str(Context c, String urlStr) {
String line;
InputStream in = null;
try {
try {
in = c.getAssets().open(urlStr);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
do {
line = bufferedReader.readLine();
if (line != null && !line.matches("^\\s*\\/\\/.*")) {
sb.append(line);
continue;
}
} while (line != null);
bufferedReader.close();
in.close();
return sb.toString();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
if (in != null) {
try {
in.close();
return null;
} catch (IOException e3) {
return null;
}
}
return null;
}
}
}