代理切换

This commit is contained in:
Administrator 2025-07-09 14:58:30 +08:00
parent b2162a97ca
commit f6b4de5838
4 changed files with 35 additions and 7 deletions

View File

@ -91,8 +91,8 @@ public class MainActivity extends AppCompatActivity {
// 定义支持的国家代码常量
private static final class CountryCode {
static final String US = "us";
static final String RU = "ru";
static final String US = "US";
static final String RU = "RU";
// 默认使用美国
static final String DEFAULT = US;
}
@ -368,8 +368,6 @@ public class MainActivity extends AppCompatActivity {
LogFileUtil.logAndWrite(Log.ERROR, TAG, "Change device failed", null);
}
});
// ChangeDeviceInfoUtil.changeDeviceInfo(result, this, bigoDevice, afDevice);
}

View File

@ -121,8 +121,9 @@ public class ClashUtil {
}
int port = -1;
try{
Log.d("TAG", "getProxyPort: "+text);
JSONObject config = new JSONObject(text.toString());
config.optInt("port", -1);
port = config.optInt("port", -1);
}catch (Exception e){
Log.e("TAG", "getProxyPort: ", e);
}

View File

@ -1,19 +1,45 @@
package com.example.studyapp.update
import android.util.Log
import com.google.gson.Gson
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.logging.HttpLoggingInterceptor
import java.io.IOException
import java.security.SecureRandom
import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit
import javax.net.ssl.HostnameVerifier
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
object HttpUtils {
const val HOST: String = "https://openapi-hk.armcloud.net"
// OkHttp客户端配置
private val client: OkHttpClient by lazy {
val trustAllCerts: Array<TrustManager> = arrayOf<TrustManager>(object : X509TrustManager {
override fun checkClientTrusted(
chain: Array<X509Certificate?>?,
authType: String?
) {
}
override fun checkServerTrusted(
chain: Array<X509Certificate?>?,
authType: String?
) {
}
override fun getAcceptedIssuers(): Array<X509Certificate?>? {
return arrayOf<X509Certificate?>()
}
}
)
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, SecureRandom())
OkHttpClient.Builder()
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
@ -21,6 +47,8 @@ object HttpUtils {
.addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})
.sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager)
.hostnameVerifier(HostnameVerifier { _, _ -> true })
.build()
}

View File

@ -235,6 +235,7 @@ object UpdateUtil {
}
} catch (e: JSONException) {
e.printStackTrace()
callback.changeFailed()
}
}
}