Maxcredito v1.2.1版本的 MD5 值为:2605738f37f8ddb81288799ddcbfcbe8
以下内容为反编译后的 SensorsABTestH5Helper.java 源代码,内容仅作参考
package com.sensorsdata.abtest.core;
import android.text.TextUtils;
import android.util.Base64;
import android.view.View;
import com.facebook.internal.AnalyticsEvents;
import com.google.firebase.messaging.Constants;
import com.sensorsdata.abtest.entity.AppConstants;
import com.sensorsdata.abtest.entity.H5Request;
import com.sensorsdata.analytics.android.sdk.SALog;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import java.lang.ref.WeakReference;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class SensorsABTestH5Helper implements WebViewJavascriptBridge {
private static final String TAG = "SAB.SensorsABTestH5Helper";
private String mMessage;
private WeakReference<View> mWebView;
public SensorsABTestH5Helper(WeakReference<View> weakReference, String str) {
this.mWebView = weakReference;
this.mMessage = str;
}
public static void invokeWebViewLoad(View view, String str, Object[] objArr, Class[] clsArr) {
try {
view.getClass().getMethod(str, clsArr).invoke(view, objArr);
} catch (Exception e2) {
SALog.printStackTrace(e2);
}
}
public static String string2Base64(String str) {
return Base64.encodeToString(str.getBytes(), 0);
}
@Override
public void callJs(final String str) {
final View view;
WeakReference<View> weakReference = this.mWebView;
if (weakReference == null || (view = weakReference.get()) == null) {
return;
}
view.post(new Runnable() {
@Override
public void run() {
String str2 = "'abtest','" + str + "'";
SensorsABTestH5Helper.invokeWebViewLoad(view, "loadUrl", new Object[]{"javascript:window.sensorsdata_app_call_js(" + str2 + ")"}, new Class[]{String.class});
}
});
}
@Override
public void handlerJSMessage() {
try {
SALog.i(TAG, "handlerJSMessage enter.");
WeakReference<View> weakReference = this.mWebView;
if (weakReference != null && weakReference.get() != null) {
if (TextUtils.isEmpty(this.mMessage)) {
SALog.i(TAG, "content is null");
return;
}
SALog.i(TAG, "handlerJSMessage content: " + this.mMessage);
JSONObject jSONObject = new JSONObject(this.mMessage);
if (TextUtils.equals("abtest", jSONObject.optString("callType"))) {
final H5Request h5Request = new H5Request();
JSONObject optJSONObject = jSONObject.optJSONObject("data");
if (optJSONObject != null) {
h5Request.messageId = optJSONObject.optString(Constants.MessagePayloadKeys.MSGID_SERVER);
final String distinctId = SensorsDataAPI.sharedInstance().getDistinctId();
new SensorsABTestApiRequestHelper().requestExperiments(optJSONObject.optJSONObject("request_body"), new IApiCallback<String>() {
@Override
public void onFailure(int i2, String str) {
JSONObject jSONObject2 = new JSONObject();
try {
jSONObject2.put(Constants.MessagePayloadKeys.MSGID_SERVER, h5Request.messageId);
SALog.i(SensorsABTestH5Helper.TAG, "onFailure callJS object: " + jSONObject2.toString());
SensorsABTestH5Helper.this.callJs(SensorsABTestH5Helper.string2Base64(jSONObject2.toString()));
} catch (JSONException e2) {
SALog.printStackTrace(e2);
}
}
@Override
public void onSuccess(String str) {
if (TextUtils.isEmpty(str)) {
SALog.i(SensorsABTestH5Helper.TAG, "response is null");
return;
}
JSONObject jSONObject2 = new JSONObject();
try {
jSONObject2.put(Constants.MessagePayloadKeys.MSGID_SERVER, h5Request.messageId);
jSONObject2.put("data", new JSONObject(str));
SALog.i(SensorsABTestH5Helper.TAG, "onSuccess callJS object: " + jSONObject2.toString());
SensorsABTestH5Helper.this.callJs(SensorsABTestH5Helper.string2Base64(jSONObject2.toString()));
} catch (JSONException e2) {
SALog.printStackTrace(e2);
}
try {
JSONObject jSONObject3 = new JSONObject(str);
JSONArray optJSONArray = jSONObject3.optJSONArray("results");
if (TextUtils.equals(AppConstants.AB_TEST_SUCCESS, jSONObject3.optString(AnalyticsEvents.PARAMETER_SHARE_DIALOG_CONTENT_STATUS))) {
JSONObject jSONObject4 = null;
if (optJSONArray != null) {
jSONObject4 = new JSONObject();
jSONObject4.put("experiments", optJSONArray);
jSONObject4.put("distinct_id", distinctId);
}
SensorsABTestCacheManager.getInstance().loadExperimentsFromCache(jSONObject4 != null ? jSONObject4.toString() : "");
}
} catch (JSONException e3) {
SALog.printStackTrace(e3);
}
}
});
return;
}
return;
}
return;
}
SALog.i(TAG, "mWebView is null");
} catch (Exception e2) {
SALog.printStackTrace(e2);
}
}
}