package com.tencent.midas.jsbridge; import android.app.Activity; import android.text.TextUtils; import android.webkit.JsResult; import android.webkit.WebView; import com.tencent.midas.api.APMidasResponse; import com.tencent.midas.comm.APLog; import com.tencent.midas.control.APMidasPayHelper; import com.tencent.midas.data.APPluginDataInterface; import com.tencent.midas.data.APPluginReportManager; import com.tencent.midas.plugin.APPluginUtils; import java.net.URLEncoder; import java.util.HashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; public class APWebProtocol { public static String URL_KEY_HEAD_CONTROL = "midasheader"; public static String URL_KEY_HEAD_TITLE = "midastitle"; public static String WEBACTION_CLOSE = "closeWeb"; public static String WEBACTION_GETCGIEXTEND = "getCgiExtend"; public static String WEBACTION_HEAD = "setHead"; public static void AnalyzeWebEntry(Activity activity, Object obj, IAPWebPage iAPWebPage, String str) { HashMap<String, String> url2Map = APPluginUtils.url2Map(str); url2Map.get("page"); String str2 = url2Map.get("action"); url2Map.get("saveNumber"); url2Map.get("saveType"); String str3 = url2Map.get("callback"); if (WEBACTION_GETCGIEXTEND.equals(str2)) { String reserv = APPluginDataInterface.singleton().getReserv(); APLog.d("APWebResultPage", "sendCgiExtends() callback=" + str3 + ", extendStr=" + reserv); if (!TextUtils.isEmpty(reserv)) { try { reserv = URLEncoder.encode(reserv, "UTF-8"); } catch (Exception unused) { } } H5CallBack(obj, str3, reserv); } else if (WEBACTION_CLOSE.equals(str2)) { APPluginReportManager.getInstance().insertData(APPluginDataInterface.singleton().getLaunchInterface(), APPluginReportManager.MIDASPLUGIN_WEBPAGE_WEBCLOSE, "", ""); APMidasResponse aPMidasResponse = new APMidasResponse(); aPMidasResponse.resultCode = 100; aPMidasResponse.resultMsg = "关闭"; APMidasPayHelper.midasCallBack(aPMidasResponse); if (activity != null) { activity.finish(); } } else if (WEBACTION_HEAD.equals(str2)) { try { iAPWebPage.initHead(activity, url2Map.get(URL_KEY_HEAD_CONTROL), url2Map.get(URL_KEY_HEAD_TITLE)); } catch (Exception unused2) { } } } /* JADX WARNING: Removed duplicated region for block: B:14:0x001e */ /* JADX WARNING: Removed duplicated region for block: B:17:0x002d A[Catch:{ Exception -> 0x0079 }] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x004b */ /* JADX WARNING: Removed duplicated region for block: B:22:0x0060 */ public static void H5CallBack(Object obj, String str, String str2) { boolean z15; String str3; try { Object nextValue = new JSONTokener(str2).nextValue(); if (nextValue != null) { if ((nextValue instanceof JSONObject) || (nextValue instanceof JSONArray)) { z15 = true; if (!z15) { try { str3 = String.format("typeof window[\"%s\"]==='function' && window[\"%s\"](%s);", str, str, str2); } catch (Exception e15) { APLog.d("H5CallBack", "H5CallBack() ex = " + e15.toString()); return; } } else { str3 = String.format("typeof window[\"%s\"]==='function' && window[\"%s\"](\"%s\");", str, str, str2); } APLog.i("callback", str); APLog.i("cb", str3); if (!(obj instanceof WebView)) { ((WebView) obj).loadUrl("javascript:" + str3); return; } else if (obj instanceof com.tencent.smtt.sdk.WebView) { ((com.tencent.smtt.sdk.WebView) obj).loadUrl("javascript:" + str3); return; } else { return; } } } } catch (Exception | JSONException unused) { } z15 = false; if (!z15) { } APLog.i("callback", str); APLog.i("cb", str3); if (!(obj instanceof WebView)) { } } public static boolean hookH5Method(Activity activity, WebView webView, String str, String str2, JsResult jsResult, IAPWebViewCallback iAPWebViewCallback) { if (TextUtils.isEmpty(str2) || !str2.startsWith("http://unipay.sdk.android/?")) { return false; } iAPWebViewCallback.WebChromeClientJsAlert(webView, str, str2, jsResult); return true; } public static boolean hookH5Method(Activity activity, com.tencent.smtt.sdk.WebView webView, String str, String str2, com.tencent.smtt.export.external.interfaces.JsResult jsResult, IAPX5WebViewCallback iAPX5WebViewCallback) { if (TextUtils.isEmpty(str2) || !str2.startsWith("http://unipay.sdk.android/?")) { return false; } iAPX5WebViewCallback.WebChromeClientJsAlert(webView, str, str2, jsResult); return true; } }