代理切换
This commit is contained in:
parent
b2162a97ca
commit
f6b4de5838
|
@ -91,8 +91,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
// 定义支持的国家代码常量
|
// 定义支持的国家代码常量
|
||||||
private static final class CountryCode {
|
private static final class CountryCode {
|
||||||
|
|
||||||
static final String US = "us";
|
static final String US = "US";
|
||||||
static final String RU = "ru";
|
static final String RU = "RU";
|
||||||
// 默认使用美国
|
// 默认使用美国
|
||||||
static final String DEFAULT = US;
|
static final String DEFAULT = US;
|
||||||
}
|
}
|
||||||
|
@ -368,8 +368,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
LogFileUtil.logAndWrite(Log.ERROR, TAG, "Change device failed", null);
|
LogFileUtil.logAndWrite(Log.ERROR, TAG, "Change device failed", null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// ChangeDeviceInfoUtil.changeDeviceInfo(result, this, bigoDevice, afDevice);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,9 @@ public class ClashUtil {
|
||||||
}
|
}
|
||||||
int port = -1;
|
int port = -1;
|
||||||
try{
|
try{
|
||||||
|
Log.d("TAG", "getProxyPort: "+text);
|
||||||
JSONObject config = new JSONObject(text.toString());
|
JSONObject config = new JSONObject(text.toString());
|
||||||
config.optInt("port", -1);
|
port = config.optInt("port", -1);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
Log.e("TAG", "getProxyPort: ", e);
|
Log.e("TAG", "getProxyPort: ", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,45 @@
|
||||||
package com.example.studyapp.update
|
package com.example.studyapp.update
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.google.gson.Gson
|
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
import okhttp3.logging.HttpLoggingInterceptor
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.security.SecureRandom
|
||||||
|
import java.security.cert.X509Certificate
|
||||||
import java.util.concurrent.TimeUnit
|
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 {
|
object HttpUtils {
|
||||||
const val HOST: String = "https://openapi-hk.armcloud.net"
|
const val HOST: String = "https://openapi-hk.armcloud.net"
|
||||||
// OkHttp客户端配置
|
|
||||||
private val client: OkHttpClient by lazy {
|
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()
|
OkHttpClient.Builder()
|
||||||
.connectTimeout(15, TimeUnit.SECONDS)
|
.connectTimeout(15, TimeUnit.SECONDS)
|
||||||
.readTimeout(15, TimeUnit.SECONDS)
|
.readTimeout(15, TimeUnit.SECONDS)
|
||||||
|
@ -21,6 +47,8 @@ object HttpUtils {
|
||||||
.addInterceptor(HttpLoggingInterceptor().apply {
|
.addInterceptor(HttpLoggingInterceptor().apply {
|
||||||
level = HttpLoggingInterceptor.Level.BODY
|
level = HttpLoggingInterceptor.Level.BODY
|
||||||
})
|
})
|
||||||
|
.sslSocketFactory(sslContext.socketFactory, trustAllCerts[0] as X509TrustManager)
|
||||||
|
.hostnameVerifier(HostnameVerifier { _, _ -> true })
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -235,6 +235,7 @@ object UpdateUtil {
|
||||||
}
|
}
|
||||||
} catch (e: JSONException) {
|
} catch (e: JSONException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
callback.changeFailed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue