正在查看: SpeedCash v6.5.1482 应用的 HttpRequestUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: SpeedCash v6.5.1482 应用的 HttpRequestUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.tiktok.util;
import androidx.annotation.Nullable;
import com.google.common.net.HttpHeaders;
import com.google.firebase.perf.FirebasePerformance;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
import com.google.firebase.perf.util.Constants;
import com.rabbitmq.client.StringRpcServer;
import com.tiktok.TikTokBusinessSdk;
import com.tiktok.appevents.TTCrashHandler;
import eu.davidea.flexibleadapter.helpers.UndoHelper;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.util.zip.GZIPOutputStream;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;
public class HttpRequestUtil {
private static final String API_ERR = "api_err";
private static final String MONITOR_API_TYPE = "monitor";
private static final String TAG = "com.tiktok.util.HttpRequestUtil";
private static final TTLogger ttLogger = new TTLogger(HttpRequestUtil.class.getCanonicalName(), TikTokBusinessSdk.getLogLevel());
public static class HttpRequestOptions {
private static int UNSET = -1;
public int connectTimeout;
public int readTimeout;
public HttpRequestOptions() {
int i = UNSET;
this.connectTimeout = i;
this.readTimeout = i;
}
public void configConnection(HttpURLConnection httpURLConnection) {
int i = this.connectTimeout;
if (i != UNSET) {
httpURLConnection.setConnectTimeout(i);
}
int i2 = this.readTimeout;
if (i2 != UNSET) {
httpURLConnection.setReadTimeout(i2);
}
}
}
private static byte[] compress2Gzip(String str) {
?? r3;
GZIPOutputStream gZIPOutputStream;
?? r0 = 0;
r0 = null;
GZIPOutputStream gZIPOutputStream2 = null;
r0 = 0;
if (str == null || str.length() == 0) {
return null;
}
int i = 0;
i = 0;
i = 0;
i = 0;
i = 0;
i = 0;
byte[] bArr = new byte[0];
try {
try {
r3 = new ByteArrayOutputStream();
try {
gZIPOutputStream = new GZIPOutputStream(r3);
} catch (IOException e) {
e = e;
}
} catch (Throwable th) {
th = th;
}
try {
String str2 = "utf-8";
gZIPOutputStream.write(str.getBytes("utf-8"));
try {
gZIPOutputStream.close();
r0 = str2;
} catch (IOException e2) {
TTLogger tTLogger = ttLogger;
tTLogger.error(e2, e2.toString(), new Object[0]);
r0 = tTLogger;
}
bArr = r3.toByteArray();
try {
r3.close();
} catch (IOException e3) {
r0 = ttLogger;
r3 = e3.toString();
i = new Object[0];
r0.error(e3, r3, i);
}
} catch (IOException e4) {
e = e4;
gZIPOutputStream2 = gZIPOutputStream;
ttLogger.error(e, e.toString(), new Object[0]);
r0 = gZIPOutputStream2;
if (gZIPOutputStream2 != null) {
try {
gZIPOutputStream2.close();
r0 = gZIPOutputStream2;
} catch (IOException e5) {
TTLogger tTLogger2 = ttLogger;
tTLogger2.error(e5, e5.toString(), new Object[0]);
r0 = tTLogger2;
}
}
if (r3 != 0) {
bArr = r3.toByteArray();
try {
r3.close();
} catch (IOException e6) {
r0 = ttLogger;
r3 = e6.toString();
i = new Object[0];
r0.error(e6, r3, i);
}
}
return bArr;
} catch (Throwable th2) {
th = th2;
r0 = gZIPOutputStream;
if (r0 != 0) {
try {
r0.close();
} catch (IOException e7) {
ttLogger.error(e7, e7.toString(), new Object[i]);
}
}
if (r3 == 0) {
throw th;
}
r3.toByteArray();
try {
r3.close();
throw th;
} catch (IOException e8) {
ttLogger.error(e8, e8.toString(), new Object[i]);
throw th;
}
}
} catch (IOException e9) {
e = e9;
r3 = 0;
} catch (Throwable th3) {
th = th3;
r3 = 0;
}
return bArr;
}
public static HttpsURLConnection connect(String str, Map<String, String> map, HttpRequestOptions httpRequestOptions, String str2, String str3) {
HttpsURLConnection httpsURLConnection;
HttpsURLConnection httpsURLConnection2 = null;
try {
httpsURLConnection = (HttpsURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(new URL(str).openConnection()));
} catch (Exception e) {
e = e;
}
try {
httpsURLConnection.setRequestMethod(str2);
httpRequestOptions.configConnection(httpsURLConnection);
httpsURLConnection.setDoInput(true);
httpsURLConnection.setUseCaches(false);
if (str2.equals(FirebasePerformance.HttpMethod.GET)) {
httpsURLConnection.setDoOutput(false);
} else if (str2.equals(FirebasePerformance.HttpMethod.POST)) {
httpsURLConnection.setDoOutput(true);
httpsURLConnection.setRequestProperty(HttpHeaders.CONTENT_LENGTH, str3);
}
for (Map.Entry<String, String> entry : map.entrySet()) {
httpsURLConnection.setRequestProperty(entry.getKey(), entry.getValue());
}
httpsURLConnection.setRequestProperty(HttpHeaders.CONTENT_ENCODING, "gzip");
httpsURLConnection.connect();
return httpsURLConnection;
} catch (Exception e2) {
e = e2;
httpsURLConnection2 = httpsURLConnection;
TTCrashHandler.handleCrash(TAG, e, 1);
if (httpsURLConnection2 != null) {
try {
httpsURLConnection2.disconnect();
} catch (Exception e3) {
TTCrashHandler.handleCrash(TAG, e3, 1);
}
}
return httpsURLConnection2;
}
}
public static String doGet(String str, Map<String, String> map, HttpRequestOptions httpRequestOptions) {
String message;
String str2;
long currentTimeMillis = System.currentTimeMillis();
String str3 = "";
try {
message = "";
str3 = new URL(str).getPath().split("/app_sdk/")[1];
} catch (Throwable th) {
message = th.getMessage();
}
HttpsURLConnection connect = connect(str, map, httpRequestOptions, FirebasePerformance.HttpMethod.GET, null);
if (connect == null) {
return null;
}
int i = 0;
try {
try {
if (shouldRedirect(connect.getResponseCode())) {
String headerField = connect.getHeaderField(HttpHeaders.LOCATION);
connect.disconnect();
connect = connect(headerField, map, httpRequestOptions, FirebasePerformance.HttpMethod.GET, null);
}
i = connect.getResponseCode();
str2 = i == 200 ? streamToString(connect.getInputStream()) : null;
try {
connect.disconnect();
} catch (Exception e) {
message = e.getMessage();
TTCrashHandler.handleCrash(TAG, e, 1);
}
} catch (Throwable th2) {
if (connect != null) {
try {
connect.disconnect();
} catch (Exception e2) {
e2.getMessage();
TTCrashHandler.handleCrash(TAG, e2, 1);
}
}
throw th2;
}
} catch (Exception e3) {
message = e3.getMessage();
TTCrashHandler.handleCrash(TAG, e3, 1);
if (connect != null) {
try {
connect.disconnect();
} catch (Exception e4) {
message = e4.getMessage();
TTCrashHandler.handleCrash(TAG, e4, 1);
}
}
str2 = null;
}
long currentTimeMillis2 = System.currentTimeMillis();
try {
int codeFromApi = getCodeFromApi(str2);
if (codeFromApi != 0) {
if (i == 200) {
message = getMessageFromApi(str2);
i = codeFromApi;
}
TikTokBusinessSdk.getAppEventLogger().monitorMetric(API_ERR, TTUtil.getMetaWithTS(Long.valueOf(currentTimeMillis)).put("latency", currentTimeMillis2 - currentTimeMillis).put("api_type", str3).put("status_code", i).put("message", message).put("log_id", getLogIDFromApi(str2)), null);
}
} catch (Exception unused) {
}
return str2;
}
public static String doPost(String str, Map<String, String> map, String str2, boolean z) {
HttpRequestOptions httpRequestOptions = new HttpRequestOptions();
httpRequestOptions.connectTimeout = Constants.MAX_URL_LENGTH;
httpRequestOptions.readTimeout = UndoHelper.UNDO_TIMEOUT;
return doPost(str, map, str2, httpRequestOptions, z);
}
public static int getCodeFromApi(@Nullable String str) {
if (str == null) {
return -1;
}
try {
return new JSONObject(str).getInt("code");
} catch (Exception unused) {
return -2;
}
}
public static String getLogIDFromApi(@Nullable String str) {
if (str != null) {
try {
return new JSONObject(str).getString("request_id");
} catch (Exception unused) {
}
}
return null;
}
public static String getMessageFromApi(@Nullable String str) {
if (str == null) {
return "result is empty";
}
try {
return new JSONObject(str).getString("message");
} catch (Exception e) {
return e.getMessage();
}
}
public static boolean shouldRedirect(int i) {
if (i != 200) {
return i == 302 || i == 301 || i == 303 || i == 307;
}
return false;
}
private static String streamToString(InputStream inputStream) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, StringRpcServer.STRING_ENCODING));
try {
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
String trim = sb.toString().trim();
bufferedReader.close();
return trim;
}
sb.append(readLine);
}
} finally {
}
} catch (Exception e) {
TTCrashHandler.handleCrash(TAG, e, 1);
return null;
}
}
public static String doPost(String str, Map<String, String> map, String str2) {
return doPost(str, map, str2, true);
}
public static java.lang.String doPost(java.lang.String r18, java.util.Map<java.lang.String, java.lang.String> r19, java.lang.String r20, com.tiktok.util.HttpRequestUtil.HttpRequestOptions r21, boolean r22) {
throw new UnsupportedOperationException("Method not decompiled: com.tiktok.util.HttpRequestUtil.doPost(java.lang.String, java.util.Map, java.lang.String, com.tiktok.util.HttpRequestUtil$HttpRequestOptions, boolean):java.lang.String");
}
}