悦享送 v3.5.1版本的 MD5 值为:111dc8a16f422da8b2f1cf208abae9ea

以下内容为反编译后的 SetServerIdActivity.java 源代码,内容仅作参考


package com.x52im.rainbowchat.logic.main;

import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import cn.jpush.android.api.JThirdPlatFormInterface;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eva.android.widget.ActivityRoot;
import com.eva.android.widget.WidgetUtils;
import com.eva.android.widget.alert.AlertDialog;
import com.eva.framework.dto.DataFromServer;
import com.x52im.rainbowchat.MyApplication;
import com.x52im.rainbowchat.R;
import com.x52im.rainbowchat.network.http.async.QueryClientConfigNewAsync;
import com.x52im.rainbowchat.utils.CheckIpHelper;
import com.x52im.rainbowchat.utils.IntentFactory;
import com.x52im.rainbowchat.utils.PreferencesToolkits;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HttpsURLConnection;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class SetServerIdActivity extends ActivityRoot {
    private static final String aliYunOssUrl = "https://nos-poko-im-gz.oss-accelerate.aliyuncs.com/";
    private static final String aliYunOssUrl_CD = "https://nos-poko-im-cd.oss-accelerate.aliyuncs.com/";
    private static final String aliYunOssUrl_BJ = "https://nos-poko-im-bj.oss-accelerate.aliyuncs.com/";
    private static final String aliYunOssUrl_SH = "https://nos-poko-im-sh.oss-accelerate.aliyuncs.com/";
    private static final String aliYunOssUrl_US = "https://nos-poko-im-us.oss-accelerate.aliyuncs.com/";
    private static final String aliYunOssUrl_SG = "https://nos-poko-im-sg.oss-accelerate.aliyuncs.com/";
    private static final String amazonUrl = "https://dl6x87dtkahwb.cloudfront.net/";
    private static final String[] ossUrlSrr = {aliYunOssUrl, aliYunOssUrl_CD, aliYunOssUrl_BJ, aliYunOssUrl_SH, aliYunOssUrl_US, aliYunOssUrl_SG, amazonUrl};
    private static final String[] apiUrlArr = {"https://xljk.jdt0.cn/api/index/getipList", "https://xlappjk.cc/api/index/getipList", "https://xlappjk.top/api/index/getipList", "https://xlappjk.vip/api/index/getipList", "https://xlappjk.xyz/api/index/getipList", "https://xlbz.jdt0.cn/api/index/getipList", "https://xljk115.mwa9.cn/api/index/getipList", "https://xljk115.qawis.cn/api/index/getipList"};
    private CheckBox customerApiUrlChx = null;
    private EditText apiUrlEditText = null;
    private EditText serverIdEditText = null;
    private Button nextButton = null;
    private final String TAG = "SetServerIdActivity";

    @Override
    public void initViews(Bundle bundle) {
        this.customeTitleBarResId = R.id.set_server_id_title_bar;
        setContentView(R.layout.set_server_id);
        this.customerApiUrlChx = (CheckBox) findViewById(R.id.customer_api_url_chx);
        this.serverIdEditText = (EditText) findViewById(R.id.server_id_edit_text);
        this.apiUrlEditText = (EditText) findViewById(R.id.api_url_edit_text);
        Button button = (Button) findViewById(R.id.save_btn);
        this.nextButton = button;
        button.setEnabled(true);
        this.nextButton.setText($$(R.string.set_server_id_btn));
        this.nextButton.setAlpha(1.0f);
        String initApiUrl = PreferencesToolkits.getInitApiUrl(this);
        if (!TextUtils.isEmpty(initApiUrl)) {
            this.apiUrlEditText.setVisibility(0);
            this.apiUrlEditText.setText(initApiUrl);
            this.customerApiUrlChx.setChecked(true);
        } else {
            this.apiUrlEditText.setVisibility(8);
            this.customerApiUrlChx.setChecked(false);
        }
        setTitle($$(R.string.set_server_id_title));
        super.initViews(bundle);
    }

    @Override
    public void initListeners() {
        this.nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (SetServerIdActivity.this.customerApiUrlChx.isChecked() && String.valueOf(SetServerIdActivity.this.apiUrlEditText.getText()).trim().length() == 0) {
                    SetServerIdActivity.this.apiUrlEditText.setError(SetServerIdActivity.this.$$(R.string.set_server_id_no_url));
                    return;
                }
                if (String.valueOf(SetServerIdActivity.this.serverIdEditText.getText()).trim().length() == 0) {
                    SetServerIdActivity.this.serverIdEditText.setError(SetServerIdActivity.this.$$(R.string.set_server_id_no_id));
                    return;
                }
                SetServerIdActivity.this.nextButton.setEnabled(false);
                SetServerIdActivity.this.nextButton.setText(SetServerIdActivity.this.$$(R.string.set_server_id_btn_tip));
                SetServerIdActivity.this.nextButton.setAlpha(0.3f);
                new GetIpList().execute(new String[0]);
            }
        });
        this.customerApiUrlChx.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                SetServerIdActivity.this.m889x96deda6f(view);
            }
        });
    }

    public void m889x96deda6f(View view) {
        if (this.customerApiUrlChx.isChecked()) {
            this.apiUrlEditText.setVisibility(0);
        } else {
            this.apiUrlEditText.setVisibility(8);
            this.apiUrlEditText.setText("");
        }
    }

    protected int executeSetServer(String str, String str2) {
        int i = -1;
        if (!TextUtils.isEmpty(str)) {
            return setAvailableIp2(getIpsFromApiUrl(str, str2), str, str2) ? 1 : -1;
        }
        List<String> arrayList = new ArrayList<>();
        for (String str3 : ossUrlSrr) {
            arrayList = getIpsFromBucket(str2, str3);
            if (arrayList.size() > 0) {
                break;
            }
        }
        if (arrayList.size() > 0 && (i = setAvailableIp(str2, arrayList)) > 0) {
            return i;
        }
        JSONArray jSONArray = null;
        for (String str4 : apiUrlArr) {
            jSONArray = getIpsFromApiUrl(str4, str2);
            if (jSONArray != null && jSONArray.size() > 0) {
                break;
            }
        }
        if (jSONArray == null || jSONArray.size() <= 0 || !setAvailableIp2(jSONArray, "", str2)) {
            return i;
        }
        return 1;
    }

    protected JSONArray getIpsFromApiUrl(String str, String str2) {
        try {
            Response execute = new OkHttpClient.Builder().callTimeout(3L, TimeUnit.SECONDS).build().newCall(new Request.Builder().url(str).post(new FormBody.Builder().add("id", str2).build()).build()).execute();
            if (!execute.isSuccessful()) {
                return null;
            }
            String string = execute.body().string();
            Log.d(this.TAG, "查询成功-信息【" + string + "】");
            JSONObject parseObject = JSONObject.parseObject(string);
            if (parseObject.getInteger(JThirdPlatFormInterface.KEY_CODE).intValue() == 1) {
                return parseObject.getJSONArray("data");
            }
            return null;
        } catch (Exception e) {
            Log.e(this.TAG, "Request ip list failed | from api: " + e.getMessage());
            return null;
        }
    }

    protected boolean setAvailableIp2(JSONArray jSONArray, String str, String str2) {
        String str3;
        int i = 0;
        while (true) {
            if (i >= jSONArray.size()) {
                str3 = "";
                break;
            }
            str3 = jSONArray.getJSONObject(i).getString("ip");
            if (CheckIpHelper.isIpAddressAvailable(str3)) {
                break;
            }
            i++;
        }
        if (str3.length() <= 0) {
            return false;
        }
        PreferencesToolkits.setServerIp(this, str3);
        PreferencesToolkits.setInitServerId(this, str2);
        if (!this.customerApiUrlChx.isChecked()) {
            str = "";
        }
        PreferencesToolkits.setInitApiUrl(this, str);
        MyApplication.getInstance2().getIMClientManager().setServerIp(str3);
        new QueryClientConfigNewAsync(this).execute(new Object[0]);
        return true;
    }

    protected List<String> getIpsFromBucket(String str, String str2) {
        ArrayList arrayList = new ArrayList();
        String str3 = null;
        try {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL(str2 + str + ".txt").openConnection();
            httpsURLConnection.setRequestMethod("GET");
            httpsURLConnection.setConnectTimeout(2000);
            httpsURLConnection.setReadTimeout(2000);
            if (httpsURLConnection.getResponseCode() == 200) {
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream()));
                StringBuilder sb = new StringBuilder();
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        break;
                    }
                    sb.append(readLine);
                }
                bufferedReader.close();
                str3 = sb.toString();
            } else {
                Log.e(this.TAG, "Response Code: " + httpsURLConnection.getResponseCode());
            }
            httpsURLConnection.disconnect();
        } catch (Exception e) {
            Log.e(this.TAG, "Request ip list failed | from Yun: " + e.getMessage());
        }
        return (str3 == null || str3.length() <= 0) ? arrayList : Arrays.asList(new String(Base64.decode(str3, 0), StandardCharsets.UTF_8).replace("\n", "").replace("\r\n", "").split(","));
    }

    protected int setAvailableIp(String str, List<String> list) {
        String str2;
        int i = 0;
        while (true) {
            if (i >= list.size()) {
                str2 = "";
                break;
            }
            str2 = list.get(i).trim();
            if (CheckIpHelper.isIpAddressAvailable(str2)) {
                break;
            }
            i++;
        }
        if (str2.length() <= 0) {
            return 0;
        }
        PreferencesToolkits.setServerIp(this, str2);
        PreferencesToolkits.setInitServerId(this, str);
        PreferencesToolkits.setInitApiUrl(this, "");
        MyApplication.getInstance2().getIMClientManager().setServerIp(str2);
        new QueryClientConfigNewAsync(this).execute(new Object[0]);
        return 1;
    }

    private class GetIpList extends AsyncTask<String, Integer, DataFromServer> {
        private GetIpList() {
        }

        @Override
        public DataFromServer doInBackground(String... strArr) {
            DataFromServer dataFromServer = new DataFromServer();
            SetServerIdActivity setServerIdActivity = SetServerIdActivity.this;
            dataFromServer.setReturnValue(Integer.valueOf(setServerIdActivity.executeSetServer(String.valueOf(setServerIdActivity.apiUrlEditText.getText()).trim(), String.valueOf(SetServerIdActivity.this.serverIdEditText.getText()).trim())));
            return dataFromServer;
        }

        @Override
        public void onPostExecute(DataFromServer dataFromServer) {
            SetServerIdActivity setServerIdActivity;
            int i;
            if (isCancelled() || SetServerIdActivity.this.isFinishing() || SetServerIdActivity.this.isDestroyed()) {
                return;
            }
            int intValue = ((Integer) dataFromServer.getReturnValue()).intValue();
            if (intValue > 0) {
                SetServerIdActivity setServerIdActivity2 = SetServerIdActivity.this;
                WidgetUtils.showToast(setServerIdActivity2, setServerIdActivity2.$$(R.string.set_server_id_save_success), WidgetUtils.ToastType.OK);
                SetServerIdActivity setServerIdActivity3 = SetServerIdActivity.this;
                setServerIdActivity3.startActivityForResult(IntentFactory.createLoginIntent(setServerIdActivity3.self(), String.valueOf(SetServerIdActivity.this.serverIdEditText.getText()).trim()), 3);
                SetServerIdActivity.this.finish();
                return;
            }
            if (SetServerIdActivity.this.customerApiUrlChx.isChecked()) {
                setServerIdActivity = SetServerIdActivity.this;
                i = R.string.set_server_id_error1;
            } else if (intValue == 0) {
                setServerIdActivity = SetServerIdActivity.this;
                i = R.string.set_server_id_error3;
            } else {
                setServerIdActivity = SetServerIdActivity.this;
                i = R.string.set_server_id_error2;
            }
            new AlertDialog.Builder(SetServerIdActivity.this).setTitle(R.string.general_tip).setMessage(setServerIdActivity.$$(i)).setNegativeButton(R.string.general_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i2) {
                    dialogInterface.dismiss();
                    SetServerIdActivity.this.nextButton.setEnabled(true);
                    SetServerIdActivity.this.nextButton.setText(SetServerIdActivity.this.$$(R.string.set_server_id_btn));
                    SetServerIdActivity.this.nextButton.setAlpha(1.0f);
                }
            }).show();
        }
    }
}