导航菜单

页面标题

页面副标题

Moneyman v2.316.0.0 - GeneralHttpService.java 源代码

正在查看: Moneyman v2.316.0.0 应用的 GeneralHttpService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.singular.sdk.internal;

import B.g;
import Z.l;
import android.net.Uri;
import com.singular.sdk.internal.GeneralHttpServiceBase;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.HttpsURLConnection;
import org.json.JSONObject;

public class GeneralHttpService extends GeneralHttpServiceBase {
    private static final String BASE_URL = "https://sdk-api-v1.singular.net/api/v1";
    private final SingularLog logger;

    public GeneralHttpService() {
        super("https://sdk-api-v1.singular.net/api/v1");
        this.logger = SingularLog.getLogger("GeneralHttpService");
    }

    private HttpURLConnection buildRequest(String str, Map<String, String> map) {
        try {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection();
            httpsURLConnection.setConnectTimeout(10000);
            httpsURLConnection.setReadTimeout(10000);
            httpsURLConnection.setRequestMethod("POST");
            httpsURLConnection.setDoInput(true);
            httpsURLConnection.setDoOutput(true);
            httpsURLConnection.setUseCaches(false);
            httpsURLConnection.setRequestProperty("User-Agent", Constants.HTTP_USER_AGENT);
            httpsURLConnection.setRequestProperty("Content-Type", "application/json");
            httpsURLConnection.setRequestProperty("Accept-Encoding", "gzip");
            try {
                JSONObject jSONObject = map != null ? new JSONObject(map) : new JSONObject();
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpsURLConnection.getOutputStream(), Constants.ENCODING);
                outputStreamWriter.write(jSONObject.toString());
                outputStreamWriter.close();
                return httpsURLConnection;
            } catch (Throwable th2) {
                this.logger.error("Error in JSON Serialization ", th2);
                this.logger.error(Utils.formatException(th2));
                return null;
            }
        } catch (Throwable th3) {
            this.logger.error(Utils.formatException(th3));
            return null;
        }
    }

    @Override
    public void sendRequest(final String str, final Map<String, String> map, final Map<String, String> map2, final GeneralHttpServiceBase.CompletionHandler completionHandler) {
        Executors.newSingleThreadExecutor().execute(new Runnable() {
            @Override
            public void run() {
                GeneralHttpService.this.sendSynchronousRequest(str, map, map2, completionHandler);
            }
        });
    }

    public void sendSynchronousRequest(String str, Map<String, String> map, Map<String, String> map2, GeneralHttpServiceBase.CompletionHandler completionHandler) {
        HttpURLConnection httpURLConnection;
        String str2 = "?a=" + SingularInstance.getInstance().getSingularConfig().apiKey;
        if (map != null) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                StringBuilder t = l.t(str2, "&");
                t.append(Uri.encode(entry.getKey()));
                t.append("=");
                t.append(Uri.encode(entry.getValue()));
                str2 = t.toString();
            }
        }
        try {
            httpURLConnection = buildRequest(getBaseUrl() + str + g.m(str2, "&h=", Utils.sha1Hash(str2, SingularInstance.getInstance().getSingularConfig().secret)), map2);
        } catch (Throwable th2) {
            th = th2;
            httpURLConnection = null;
        }
        try {
            if (httpURLConnection == null) {
                completionHandler.onFailure("Error sending request: connection is null");
                this.logger.error("Error sending request: connection is null");
                if (httpURLConnection != null) {
                    return;
                } else {
                    return;
                }
            }
            httpURLConnection.connect();
            int responseCode = httpURLConnection.getResponseCode();
            StringBuffer stringBuffer = new StringBuffer();
            InputStream inputStream = httpURLConnection.getInputStream();
            BufferedReader bufferedReader = new BufferedReader((httpURLConnection.getContentEncoding() == null || !httpURLConnection.getContentEncoding().equals("gzip")) ? new InputStreamReader(inputStream) : new InputStreamReader(new GZIPInputStream(inputStream)));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    completionHandler.onSuccess(stringBuffer.toString(), responseCode);
                    httpURLConnection.disconnect();
                    return;
                }
                stringBuffer.append(readLine);
            }
        } catch (Throwable th3) {
            th = th3;
            try {
                completionHandler.onFailure("Error sending request: message - " + th.getMessage());
                this.logger.error(Utils.formatException(th));
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
            } finally {
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
            }
        }
    }
}