导航菜单

页面标题

页面副标题

Hopscotch v9.7.2 - RetrofitApiBuilder.java 源代码

正在查看: Hopscotch v9.7.2 应用的 RetrofitApiBuilder.java JAVA 源代码文件

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


package in.hopscotch.android.api;

import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.jakewharton.retrofit2.adapter.rxjava2.f;
import com.payu.paymentparamhelper.PayuConstants;
import in.hopscotch.android.api.ApiParam;
import in.hopscotch.android.api.cookies.CookiesAddInterceptor;
import in.hopscotch.android.api.cookies.CookiesReceiverInterceptor;
import in.hopscotch.android.api.cookies.HSCookieStore;
import in.hopscotch.android.api.factory.CustomerInfoApiFactory;
import in.hopscotch.android.api.factory.LatencyApiFactory;
import in.hopscotch.android.api.response.LatencyCheckResponse;
import in.hopscotch.android.api.response.LoginResponse;
import in.hopscotch.android.application.HsApplication;
import in.hopscotch.android.attribution.AttributionData;
import in.hopscotch.android.attribution.OrderAttributionHelper;
import in.hopscotch.android.common.util.j;
import in.hopscotch.android.remote.config.e;
import in.hopscotch.android.util.a1;
import in.hopscotch.android.util.d0;
import in.hopscotch.android.util.g;
import in.hopscotch.android.util.u0;
import java.io.IOException;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSession;
import okhttp3.Headers;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitApiBuilder {
    public static final String SUB_URL = "Hs_SubUrl";
    private static final String TAG = "RetrofitApiBuilder";
    private static RetrofitApiBuilder mRetrofitApiBuilder;
    private static RetrofitApiBuilder mockRetrofitApiBuilder;
    private Retrofit mRetrofitClient;
    private OkHttpClient mockOkHttpClient;
    private Retrofit mockRetrofitClient;
    private OkHttpClient okHttpClient;

    private RetrofitApiBuilder() {
    }

    private Headers addHeaders() {
        Headers.Builder builder = new Headers.Builder();
        builder.set("client-id", "android-client/9.7.2");
        builder.set("client-auth-method", "v1");
        builder.set("secret-key", in.hopscotch.android.util.a.a);
        builder.set("api-version", "v2.0");
        builder.set("device-id", in.hopscotch.android.util.a.c);
        builder.set("install-id", in.hopscotch.android.util.a.d);
        builder.set("os", in.hopscotch.android.util.a.b);
        builder.set("appBuild", "2025072909");
        builder.set("appVersion", "9.7.2");
        builder.set("Accept", "application/json");
        e.a.getClass();
        if (e.d()) {
            builder.set("x-nv-hd-hl-key", HsApplication.b().b.getN7HdHlKey());
            builder.set("x-nv-security-key", HsApplication.b().b.getN7securityKey());
            if (e.b() != null) {
                builder.set("x-nv-hd-token", e.b());
            }
        }
        if (getBaseUrl().contains("qa.")) {
            builder.set("x-nv", "true");
            builder.set("x-nv-security-magic", HsApplication.b().b.getN7DebugMagicSecurityKey());
        }
        try {
            builder.set("device-type", in.hopscotch.android.util.a.e);
            builder.set(PayuConstants.UPI_USER_AGENT, System.getProperty("http.agent"));
        } catch (Exception e) {
            g.b(e);
        }
        builder.set("device-profile", in.hopscotch.android.db.a.j());
        builder.set("X-Request-ID", UUID.randomUUID().toString());
        if (!TextUtils.isEmpty(in.hopscotch.android.db.a.x().getString(ApiParam.LoginParam.TICKET, null))) {
            builder.set("hs-persistent-ticket", in.hopscotch.android.db.a.x().getString(ApiParam.LoginParam.TICKET, null));
        }
        try {
            String str = in.hopscotch.android.db.a.x().getBoolean("header_first_call", true) ? "" : "last-";
            String str2 = !TextUtils.isEmpty(u0.m().l()) ? u0.m().l().split("//")[1] : "";
            if (!TextUtils.isEmpty(u0.m().u())) {
                builder.set(str.concat("utm-source"), u0.m().u());
            }
            if (!TextUtils.isEmpty(u0.m().q())) {
                builder.set(str.concat("utm-medium"), u0.m().q());
            }
            if (!TextUtils.isEmpty(u0.m().n())) {
                builder.set(str.concat("utm-campaign"), u0.m().n());
            }
            if (!TextUtils.isEmpty(u0.m().t())) {
                builder.set(str.concat("utm-section"), u0.m().t());
            }
            if (!TextUtils.isEmpty(u0.m().o())) {
                builder.set(str.concat("utm-content"), u0.m().o());
            }
            if (!TextUtils.isEmpty(str2)) {
                builder.set(str.concat(ApiParam.Search.DEEPLINK), str2);
            }
            if (!TextUtils.isEmpty(u0.m().s())) {
                builder.set(str.concat("utm-promo"), u0.m().s());
            }
            if (!TextUtils.isEmpty(u0.m().r())) {
                builder.set(str.concat("utm-product"), u0.m().r());
            }
            if (!TextUtils.isEmpty(u0.m().v())) {
                builder.set(str.concat("utm-term"), u0.m().v());
            }
            if (!TextUtils.isEmpty(u0.m().p())) {
                builder.set(str.concat("utm-gender"), u0.m().p());
            }
            AttributionData currentAttributionData = OrderAttributionHelper.getInstance().getCurrentAttributionData();
            if (currentAttributionData != null) {
                if (!TextUtils.isEmpty(currentAttributionData.getFunnel())) {
                    builder.set(ApiParam.OrderAttributionParam.FUNNEL, currentAttributionData.getFunnel());
                }
                if (!TextUtils.isEmpty(currentAttributionData.getFunnelSection())) {
                    builder.set("funnel-section", currentAttributionData.getFunnelSection());
                }
                if (!TextUtils.isEmpty(currentAttributionData.getSection())) {
                    builder.set(ApiParam.OrderAttributionParam.SECTION, currentAttributionData.getSection());
                }
                if (!TextUtils.isEmpty(currentAttributionData.getSortBar())) {
                    builder.set("gender", currentAttributionData.getSortBar());
                }
                if (!TextUtils.isEmpty(currentAttributionData.getSortBarGroup())) {
                    builder.set("age-group", currentAttributionData.getSortBarGroup());
                }
                if (!TextUtils.isEmpty(currentAttributionData.getFunnelTile())) {
                    builder.set("funnel-tile", currentAttributionData.getFunnelTile());
                }
                if (currentAttributionData.getSubsections() != null && currentAttributionData.getSubsections().size() > 0) {
                    builder.set("sub-section", TextUtils.join("~", currentAttributionData.getSubsections()));
                }
            }
        } catch (Exception e2) {
            g.b(e2);
        }
        if (in.hopscotch.android.db.a.x().getString("usersOn1_3AndHigher", "").equals("userFROM1_3AndAbove") && !in.hopscotch.android.db.a.x().getBoolean("ab_test_first_call_request_sent", false) && in.hopscotch.android.db.a.x().getBoolean("ab_test_first_call_trigger", false)) {
            builder.set("firstHomePage", "true");
            in.hopscotch.android.db.a.k().putBoolean("ab_test_first_call_trigger", false);
            in.hopscotch.android.db.a.k().apply();
            in.hopscotch.android.db.a.k().putBoolean("ab_test_first_call_request_sent", true);
            in.hopscotch.android.db.a.k().apply();
        }
        return builder.build();
    }

    private String getBaseUrl() {
        return "https://www.hopscotch.in/api";
    }

    private String getCMSBaseUrl() {
        return "https://www.hopscotch.in/api";
    }

    public static RetrofitApiBuilder getInstance() {
        synchronized (RetrofitApiBuilder.class) {
            try {
                if (mRetrofitApiBuilder == null) {
                    mRetrofitApiBuilder = new RetrofitApiBuilder();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return mRetrofitApiBuilder;
    }

    @NonNull
    private Interceptor getInterceptor() {
        return new Interceptor() {
            public final Response intercept(Interceptor.Chain chain) {
                Response lambda$getInterceptor$1;
                lambda$getInterceptor$1 = RetrofitApiBuilder.this.lambda$getInterceptor$1(chain);
                return lambda$getInterceptor$1;
            }
        };
    }

    public static RetrofitApiBuilder getMockRetrofitInstance() {
        return mockRetrofitApiBuilder;
    }

    private static boolean lambda$configRetrofitClient$0(String str, SSLSession sSLSession) {
        return true;
    }

    public Response lambda$getInterceptor$1(Interceptor.Chain chain) throws IOException {
        Request request = chain.request();
        try {
            if (request.method().equalsIgnoreCase("get")) {
                if (in.hopscotch.android.db.a.x().getString("customTileId", null) != null) {
                    Request build = request.newBuilder().url(request.url().newBuilder().addQueryParameter("from", in.hopscotch.android.db.a.x().getString("customTileId", null)).build()).headers(addHeaders()).build();
                    in.hopscotch.android.db.a.k().putString("customTileId", null);
                    in.hopscotch.android.db.a.k().apply();
                    return chain.proceed(build);
                }
                if (j.f() != 0) {
                    Request build2 = request.newBuilder().url(request.url().newBuilder().addQueryParameter("cptId", String.valueOf(j.f())).build()).headers(addHeaders()).build();
                    j.O(0);
                    return chain.proceed(build2);
                }
            }
        } catch (Exception e) {
            g.b(e);
        }
        Request build3 = chain.request().newBuilder().headers(addHeaders()).build();
        if (request != null) {
            try {
                if (request.url() != null && !TextUtils.isEmpty(request.url().toString()) && !request.url().toString().contains("latencycheck")) {
                    latencyCheck(System.nanoTime());
                }
            } catch (Exception e2) {
                g.b(e2);
            }
        }
        return chain.proceed(build3);
    }

    private void latencyCheck(final long j) {
        if (TextUtils.isEmpty(in.hopscotch.android.db.a.j()) || in.hopscotch.android.db.a.j().equalsIgnoreCase("low")) {
            return;
        }
        HashMap hashMap = new HashMap();
        hashMap.put(ApiParam.PayURequestParam.PARAM, Long.valueOf(d0.b().a()));
        LatencyApiFactory.getInstance().latencyCheck(hashMap, new Callback<LatencyCheckResponse>() {
            public void onFailure(Call<LatencyCheckResponse> call, Throwable th) {
            }

            public void onResponse(Call<LatencyCheckResponse> call, retrofit2.Response<LatencyCheckResponse> response) {
                LatencyCheckResponse latencyCheckResponse;
                if (response == null || !response.isSuccessful() || (latencyCheckResponse = (LatencyCheckResponse) response.body()) == null) {
                    return;
                }
                String str = latencyCheckResponse.action;
                String str2 = a1.a;
                if ("success".equalsIgnoreCase(str)) {
                    long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - j);
                    d0.b().c();
                    d0.b().d(millis);
                    d0.b().a();
                    if (millis > latencyCheckResponse.threshold) {
                        in.hopscotch.android.db.a.N("medium");
                    } else {
                        in.hopscotch.android.db.a.N("normal");
                    }
                }
            }
        });
    }

    public void cancelAllRequests() {
        this.okHttpClient.dispatcher().cancelAll();
    }

    public void configRetrofitClient() {
        try {
            OkHttpClient.Builder addInterceptor = new OkHttpClient.Builder().addInterceptor(getInterceptor()).addInterceptor(new CookiesAddInterceptor()).addInterceptor(new CookiesReceiverInterceptor());
            TimeUnit timeUnit = TimeUnit.SECONDS;
            this.okHttpClient = addInterceptor.connectTimeout(60L, timeUnit).readTimeout(60L, timeUnit).build();
            createRetrofitClient();
        } catch (Exception e) {
            g.b(e);
        }
    }

    public void createMockRetrofitClient() {
    }

    public void createRetrofitClient() {
        HSCookieStore.setHost(getBaseUrl());
        this.mRetrofitClient = new Retrofit.Builder().baseUrl(getBaseUrl() + "/").client(this.okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(f.a()).build();
    }

    public void createRetrofitClientForCMS() {
        HSCookieStore.setHost(getBaseUrl());
        this.mRetrofitClient = new Retrofit.Builder().baseUrl(getBaseUrl() + "/").client(this.okHttpClient).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(f.a()).build();
    }

    public void doAutoLogin(Callback<LoginResponse> callback) {
        HashMap hashMap = new HashMap();
        hashMap.put(ApiParam.LoginParam.TICKET, in.hopscotch.android.db.a.x().getString(ApiParam.LoginParam.TICKET, null));
        CustomerInfoApiFactory.getInstance().autoLogin(hashMap, callback);
    }

    public synchronized void environmentChanged() {
    }

    public Retrofit getMockRetrofitClient() {
        return null;
    }

    public Retrofit getRetrofitClient() {
        return this.mRetrofitClient;
    }
}