导航菜单

页面标题

页面副标题

pg 娱乐 v1.0.7.202506242308 - DomainManager.java 源代码

正在查看: pg 娱乐 v1.0.7.202506242308 应用的 DomainManager.java JAVA 源代码文件

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


package com.yueyi.container.util;

import android.util.Log;
import com.blankj.utilcode.util.LogUtils;
import com.google.ai.client.generativeai.common.SerializationException;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.yueyi.container.API;
import io.ktor.client.utils.CIOKt;
import io.ktor.http.auth.HttpAuthHeader;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import kotlin.Metadata;
import kotlin.TuplesKt;
import kotlin.UByte;
import kotlin.Unit;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.collections.IntIterator;
import kotlin.collections.MapsKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.internal.Intrinsics;
import kotlin.random.Random;
import kotlin.ranges.IntRange;
import kotlin.ranges.RangesKt;
import kotlin.text.Charsets;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;

@Metadata(d1 = {"\u0000:\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0004\n\u0002\u0010\b\n\u0000\n\u0002\u0010 \n\u0002\b\u0006\n\u0002\u0010\u000b\n\u0002\b\u0004\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\bÆ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0018\u0010\u0006\u001a\u00020\u00042\u0006\u0010\u0007\u001a\u00020\u00042\u0006\u0010\b\u001a\u00020\tH\u0002J\u0016\u0010\n\u001a\b\u0012\u0004\u0012\u00020\u00040\u000b2\u0006\u0010\f\u001a\u00020\tH\u0002J\u001a\u0010\r\u001a\u00020\u00042\u0006\u0010\u000e\u001a\u00020\t2\b\b\u0002\u0010\u000f\u001a\u00020\u0004H\u0002J\u000e\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u00040\u000bH\u0002J\u0010\u0010\u0011\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00020\u0004H\u0002J\u0010\u0010\u0014\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00020\u0004H\u0002J\u0006\u0010\u0016\u001a\u00020\u0017J$\u0010\u0018\u001a\u00020\u00172\u0006\u0010\f\u001a\u00020\t2\u0014\u0010\u0019\u001a\u0010\u0012\u0006\u0012\u0004\u0018\u00010\u0004\u0012\u0004\u0012\u00020\u00170\u001aJ\u0010\u0010\u001b\u001a\u00020\u00172\u0006\u0010\u0013\u001a\u00020\u0004H\u0002R\u000e\u0010\u0003\u001a\u00020\u0004X\u0086T¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082T¢\u0006\u0002\n\u0000¨\u0006\u001c"}, d2 = {"Lcom/yueyi/container/util/DomainManager;", "", "()V", "BACKUP_KEY", "", "CACHE_KEY", "generateDomain", "date", "index", "", "generateListDomain", "", "maxDays", "generateRandomString", "length", HttpAuthHeader.Parameters.Charset, "getListBackupDomain", "isDomainAvailable", "", "domain", "md5", "input", "resetAllCache", "", "resolveDomain", "callback", "Lkotlin/Function1;", "saveToCache", "app_kaiyuanRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class DomainManager {
    public static final String BACKUP_KEY = "backup_domains";
    private static final String CACHE_KEY = "last_success_domain";
    public static final DomainManager INSTANCE = new DomainManager();

    private DomainManager() {
    }

    private final List<String> getListBackupDomain() {
        return SharedPrefsUtil.INSTANCE.getStringArray(BACKUP_KEY);
    }

    private final String generateDomain(String date, int index) {
        String str = "KAIYUANPRO_" + date + '_' + index;
        StringBuilder sb = new StringBuilder("http://kkiiffap.");
        String substring = md5(str).substring(0, 12);
        Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String…ing(startIndex, endIndex)");
        return sb.append(substring).append(".top").toString();
    }

    private final String md5(String input) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] bytes = input.getBytes(Charsets.UTF_8);
            Intrinsics.checkNotNullExpressionValue(bytes, "this as java.lang.String).getBytes(charset)");
            byte[] digest = messageDigest.digest(bytes);
            Intrinsics.checkNotNullExpressionValue(digest, "md.digest(inputBytes)");
            return ArraysKt.joinToString$default(digest, (CharSequence) "", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (Function1) new Function1<Byte, CharSequence>() {
                public final CharSequence invoke(byte b) {
                    String format = String.format("%02x", Arrays.copyOf(new Object[]{Integer.valueOf(b & UByte.MAX_VALUE)}, 1));
                    Intrinsics.checkNotNullExpressionValue(format, "format(this, *args)");
                    return format;
                }

                @Override
                public CharSequence invoke(Byte b) {
                    return invoke(b.byteValue());
                }
            }, 30, (Object) null);
        } catch (NoSuchAlgorithmException unused) {
            return "";
        }
    }

    public final void resetAllCache() {
        SharedPrefsUtil.INSTANCE.clearKey(CACHE_KEY);
        SharedPrefsUtil.INSTANCE.clearKey(BACKUP_KEY);
        Log.d("DomainManager", "所有域名缓存已重置");
    }

    public final void resolveDomain(int maxDays, Function1<? super String, Unit> callback) {
        Intrinsics.checkNotNullParameter(callback, "callback");
        String string = SharedPrefsUtil.INSTANCE.getString(CACHE_KEY);
        if (string != null) {
            System.out.println((Object) ("cacheKey: " + string));
            if (!INSTANCE.isDomainAvailable(string)) {
                string = null;
            }
            if (string != null) {
                callback.invoke(string);
                return;
            }
        }
        DomainManager$resolveDomain$3 domainManager$resolveDomain$3 = new Function0<Unit>() {
            @Override
            public Unit invoke() {
                invoke2();
                return Unit.INSTANCE;
            }

            public final void invoke2() {
                SharedPrefsUtil.INSTANCE.clearKey("last_success_domain");
            }
        };
        List plus = CollectionsKt.plus((Collection) CollectionsKt.plus((Collection) getListBackupDomain(), (Iterable) generateListDomain(maxDays)), (Iterable) API.INSTANCE.getLIST_BASE_DOMAIN());
        final AtomicReference atomicReference = new AtomicReference(null);
        ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        final AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        System.out.println((Object) ("listDomain: " + plus.size()));
        List<String> list = plus;
        ArrayList arrayList = new ArrayList(CollectionsKt.collectionSizeOrDefault(list, 10));
        for (final String str : list) {
            arrayList.add(newCachedThreadPool.submit(new Runnable() {
                @Override
                public final void run() {
                    DomainManager.resolveDomain$lambda$3$lambda$2(atomicBoolean, str, atomicReference);
                }
            }));
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            try {
                ((Future) it.next()).get(3L, TimeUnit.SECONDS);
            } catch (Exception unused) {
            }
        }
        newCachedThreadPool.shutdownNow();
        callback.invoke(atomicReference.get());
    }

    public static final void resolveDomain$lambda$3$lambda$2(AtomicBoolean found, String domain, AtomicReference validDomain) {
        Intrinsics.checkNotNullParameter(found, "$found");
        Intrinsics.checkNotNullParameter(domain, "$domain");
        Intrinsics.checkNotNullParameter(validDomain, "$validDomain");
        if (found.get()) {
            return;
        }
        DomainManager domainManager = INSTANCE;
        if (domainManager.isDomainAvailable(domain) && found.compareAndSet(false, true)) {
            validDomain.set(domain);
            domainManager.saveToCache(domain);
        }
    }

    private final List<String> generateListDomain(int maxDays) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd", Locale.getDefault());
        ArrayList arrayList = new ArrayList();
        Iterator<Integer> it = RangesKt.until(0, maxDays).iterator();
        while (it.hasNext()) {
            int nextInt = ((IntIterator) it).nextInt();
            Calendar calendar = Calendar.getInstance();
            calendar.add(5, -nextInt);
            String dateStr = simpleDateFormat.format(calendar.getTime());
            Iterator<Integer> it2 = new IntRange(0, 4).iterator();
            while (it2.hasNext()) {
                int nextInt2 = ((IntIterator) it2).nextInt();
                DomainManager domainManager = INSTANCE;
                Intrinsics.checkNotNullExpressionValue(dateStr, "dateStr");
                arrayList.add(domainManager.generateDomain(dateStr, nextInt2 + 1));
            }
        }
        return arrayList;
    }

    private final boolean isDomainAvailable(String domain) {
        int i;
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(null, 1, null);
        httpLoggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient build = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).followRedirects(false).connectTimeout(3L, TimeUnit.SECONDS).build();
        try {
            long currentTimeMillis = System.currentTimeMillis() / CIOKt.DEFAULT_HTTP_POOL_SIZE;
            String generateRandomString$default = generateRandomString$default(this, 16, null, 2, null);
            String jsonStr = new Gson().toJson(MapsKt.mapOf(TuplesKt.to("reqStr", generateRandomString$default), TuplesKt.to("reqTime", String.valueOf(currentTimeMillis))));
            PublicKey publicKeyFromString = RSAUtil.INSTANCE.publicKeyFromString(API.PUBLIC_KEY);
            RSAUtil rSAUtil = RSAUtil.INSTANCE;
            Intrinsics.checkNotNullExpressionValue(jsonStr, "jsonStr");
            try {
                try {
                    Response execute = build.newCall(new Request.Builder().url(domain + "/app-api/api/domainvalidate/check").post(RequestBody.INSTANCE.create("{\"data\": \"" + rSAUtil.encrypt(publicKeyFromString, jsonStr) + "\"}", MediaType.INSTANCE.get("application/json; charset=utf-8"))).build()).execute();
                    if (execute.code() != 200) {
                        throw new IOException("Status code: " + execute.code());
                    }
                    if (!execute.isSuccessful()) {
                        throw new IOException("Response not success: " + execute.code());
                    }
                    if (execute.body() == null) {
                        throw new IOException("空响应体");
                    }
                    Gson gson = new Gson();
                    ResponseBody body = execute.body();
                    Intrinsics.checkNotNull(body);
                    Object fromJson = gson.fromJson(body.string(), ApiCheckResponse.class);
                    Intrinsics.checkNotNullExpressionValue(fromJson, "gson.fromJson(response.b…heckResponse::class.java)");
                    ApiCheckResponse apiCheckResponse = (ApiCheckResponse) fromJson;
                    CheckBodyResponse data = apiCheckResponse.getData();
                    if (apiCheckResponse.getCode() != 200) {
                        try {
                            Object[] objArr = new Object[1];
                            objArr[0] = "isDomainAvailable checkBody is " + data + " status code: " + apiCheckResponse.getCode() + ", domain: " + domain;
                            LogUtils.e(objArr);
                        } catch (IOException e) {
                            e = e;
                            i = 1;
                            Object[] objArr2 = new Object[i];
                            objArr2[0] = "isDomainAvailable IOException: " + domain;
                            LogUtils.e(objArr2);
                            LogUtils.e(new Object[]{"isDomainAvailable IOException: " + e.getMessage()});
                            build.dispatcher().executorService().shutdown();
                            return false;
                        }
                    }
                    int res = data.getRes() + 1;
                    RSAUtil rSAUtil2 = RSAUtil.INSTANCE;
                    PrivateKey privateKeyFromString = RSAUtil.INSTANCE.privateKeyFromString(API.PRIVATE_KEY);
                    String substring = data.getData().substring(res);
                    Intrinsics.checkNotNullExpressionValue(substring, "this as java.lang.String).substring(startIndex)");
                    JsonObject asJsonObject = JsonParser.parseString(rSAUtil2.decrypt(privateKeyFromString, substring)).getAsJsonObject();
                    String asString = asJsonObject.get("reqStr").getAsString();
                    String asString2 = asJsonObject.get("reqTime").getAsString();
                    if (Intrinsics.areEqual(generateRandomString$default, asString) && Intrinsics.areEqual(asString2, String.valueOf(currentTimeMillis))) {
                        build.dispatcher().executorService().shutdown();
                        return true;
                    }
                    build.dispatcher().executorService().shutdown();
                    return false;
                } catch (SerializationException unused) {
                    build.dispatcher().executorService().shutdown();
                    return false;
                }
            } catch (IOException e2) {
                e = e2;
                i = 1;
            }
        } catch (Exception unused2) {
            build.dispatcher().executorService().shutdown();
            return false;
        } catch (Throwable th) {
            build.dispatcher().executorService().shutdown();
            throw th;
        }
    }

    private final void saveToCache(String domain) {
        SharedPrefsUtil.INSTANCE.saveString(CACHE_KEY, domain);
    }

    static String generateRandomString$default(DomainManager domainManager, int i, String str, int i2, Object obj) {
        if ((i2 & 2) != 0) {
            str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklklmnopqrstuvwxyz0123456789";
        }
        return domainManager.generateRandomString(i, str);
    }

    private final String generateRandomString(int length, String charset) {
        if (!(length > 0)) {
            throw new IllegalArgumentException("字符串长度必须大于0".toString());
        }
        IntRange until = RangesKt.until(0, length);
        ArrayList arrayList = new ArrayList(CollectionsKt.collectionSizeOrDefault(until, 10));
        Iterator<Integer> it = until.iterator();
        while (it.hasNext()) {
            ((IntIterator) it).nextInt();
            arrayList.add(Character.valueOf(charset.charAt(Random.INSTANCE.nextInt(charset.length()))));
        }
        return CollectionsKt.joinToString$default(arrayList, "", null, null, 0, null, null, 62, null);
    }
}