正在查看: Rilo v2.0.21 应用的 HttpRequestUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Rilo v2.0.21 应用的 HttpRequestUtil.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.tiktok.util;
import com.stripe.android.model.PaymentMethodOptionsParams;
import com.tiktok.TikTokBusinessSdk;
import com.tiktok.appevents.TTCrashHandler;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
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 = "/app/monitor/";
private static final String TAG = "com.tiktok.util.HttpRequestUtil";
private static final TTLogger ttLogger = new TTLogger(HttpRequestUtil.class.getCanonicalName(), TikTokBusinessSdk.getLogLevel());
public static boolean shouldRedirect(int status) {
if (status != 200) {
return status == 302 || status == 301 || status == 303 || status == 307;
}
return false;
}
public static class HttpRequestOptions {
private static int UNSET = -1;
public int connectTimeout;
public int readTimeout;
public HttpRequestOptions() {
int i2 = UNSET;
this.connectTimeout = i2;
this.readTimeout = i2;
}
public void configConnection(HttpURLConnection connection) {
int i2 = this.connectTimeout;
if (i2 != UNSET) {
connection.setConnectTimeout(i2);
}
int i3 = this.readTimeout;
if (i3 != UNSET) {
connection.setReadTimeout(i3);
}
}
}
public static String doGet(String url, Map<String, String> headerParamMap) {
HttpRequestOptions httpRequestOptions = new HttpRequestOptions();
httpRequestOptions.connectTimeout = 2000;
httpRequestOptions.readTimeout = 5000;
return doGet(url, headerParamMap, httpRequestOptions);
}
public static HttpsURLConnection connect(String url, Map<String, String> headerParamMap, HttpRequestOptions options, String method, String contentLength) {
HttpsURLConnection httpsURLConnection = null;
try {
HttpsURLConnection httpsURLConnection2 = (HttpsURLConnection) new URL(url).openConnection();
try {
httpsURLConnection2.setRequestMethod(method);
options.configConnection(httpsURLConnection2);
httpsURLConnection2.setDoInput(true);
httpsURLConnection2.setUseCaches(false);
if (method.equals("GET")) {
httpsURLConnection2.setDoOutput(false);
} else if (method.equals("POST")) {
httpsURLConnection2.setDoOutput(true);
httpsURLConnection2.setRequestProperty("Content-Length", contentLength);
}
for (Map.Entry<String, String> entry : headerParamMap.entrySet()) {
httpsURLConnection2.setRequestProperty(entry.getKey(), entry.getValue());
}
httpsURLConnection2.connect();
return httpsURLConnection2;
} catch (Exception e2) {
e = e2;
httpsURLConnection = httpsURLConnection2;
TTCrashHandler.handleCrash(TAG, e, 1);
if (httpsURLConnection != null) {
try {
httpsURLConnection.disconnect();
} catch (Exception e3) {
TTCrashHandler.handleCrash(TAG, e3, 1);
}
}
return httpsURLConnection;
}
} catch (Exception e4) {
e = e4;
}
}
public static String doGet(String url, Map<String, String> headerParamMap, HttpRequestOptions options) {
String str;
String str2;
long currentTimeMillis = System.currentTimeMillis();
try {
URL url2 = new URL(url);
if (url2.getPath().contains(TikTokBusinessSdk.getApiAvailableVersion())) {
str = url2.getPath().split(TikTokBusinessSdk.getApiAvailableVersion())[1];
} else {
str = url2.getPath().split("open_api")[1];
}
} catch (MalformedURLException unused) {
str = "";
}
HttpsURLConnection connect = connect(url, headerParamMap, options, "GET", null);
if (connect == null) {
return null;
}
int i2 = 0;
try {
try {
if (shouldRedirect(connect.getResponseCode())) {
String headerField = connect.getHeaderField("Location");
connect.disconnect();
connect = connect(headerField, headerParamMap, options, "GET", null);
}
i2 = connect.getResponseCode();
str2 = i2 == 200 ? streamToString(connect.getInputStream()) : null;
if (connect != null) {
try {
connect.disconnect();
} catch (Exception e2) {
TTCrashHandler.handleCrash(TAG, e2, 1);
}
}
} catch (Exception e3) {
TTCrashHandler.handleCrash(TAG, e3, 1);
if (connect != null) {
try {
connect.disconnect();
} catch (Exception e4) {
TTCrashHandler.handleCrash(TAG, e4, 1);
}
}
str2 = null;
}
long currentTimeMillis2 = System.currentTimeMillis();
try {
if (getCodeFromApi(str2) != 0) {
TikTokBusinessSdk.getAppEventLogger().monitorMetric(API_ERR, TTUtil.getMetaWithTS(Long.valueOf(currentTimeMillis)).put("latency", currentTimeMillis2 - currentTimeMillis).put("api_type", str).put("status_code", i2).put("log_id", getLogIDFromApi(str2)), null);
}
} catch (Exception unused2) {
}
return str2;
} catch (Throwable th) {
if (connect != null) {
try {
connect.disconnect();
} catch (Exception e5) {
TTCrashHandler.handleCrash(TAG, e5, 1);
}
}
throw th;
}
}
public static String doPost(String url, Map<String, String> headerParamMap, String jsonStr) {
HttpRequestOptions httpRequestOptions = new HttpRequestOptions();
httpRequestOptions.connectTimeout = 2000;
httpRequestOptions.readTimeout = 5000;
return doPost(url, headerParamMap, jsonStr, httpRequestOptions);
}
public static java.lang.String doPost(java.lang.String r12, java.util.Map<java.lang.String, java.lang.String> r13, java.lang.String r14, com.tiktok.util.HttpRequestUtil.HttpRequestOptions r15) {
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):java.lang.String");
}
private static String streamToString(InputStream is) {
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
try {
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
sb.append(readLine);
} else {
String trim = sb.toString().trim();
bufferedReader.close();
return trim;
}
}
} finally {
}
} catch (Exception e2) {
TTCrashHandler.handleCrash(TAG, e2, 1);
return null;
}
}
public static int getCodeFromApi(String resp) {
if (resp == null) {
return -1;
}
try {
return new JSONObject(resp).getInt(PaymentMethodOptionsParams.Blik.PARAM_CODE);
} catch (Exception unused) {
return -2;
}
}
public static String getLogIDFromApi(String resp) {
if (resp != null) {
try {
return new JSONObject(resp).getString("request_id");
} catch (Exception unused) {
}
}
return null;
}
}