| | |
| | | /** |
| | | * 网络请求retrofit初始化。 |
| | | */ |
| | | class RRetrofit private constructor() { |
| | | class RRetrofit(val isUseCert: Boolean = true, val isTrustAll: Boolean = false) { |
| | | |
| | | private val loggingInterceptor by lazy { |
| | | LoggingInterceptor() |
| | |
| | | chain.proceed(request) |
| | | } |
| | | .apply { |
| | | createTrustManager(R.raw.star_gopost_ci)?.also { |
| | | sslSocketFactory(getSSLSocketFactory(it), it) |
| | | if (isUseCert) { |
| | | createTrustManager(R.raw.star_gopost_ci)?.also { |
| | | sslSocketFactory(getSSLSocketFactory(it), it) |
| | | } |
| | | } else { |
| | | if (isTrustAll) { |
| | | val trustManager = object : X509TrustManager { |
| | | override fun checkClientTrusted(chain: Array<out X509Certificate>?, authType: String?) {} |
| | | override fun checkServerTrusted(chain: Array<out X509Certificate>?, authType: String?) {} |
| | | override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf() |
| | | } |
| | | sslSocketFactory(getSSLSocketFactory(trustManager), trustManager) |
| | | } |
| | | } |
| | | if (BuildConfig.DEBUG) { |
| | | addInterceptor(loggingInterceptor) |
| | |
| | | .build() |
| | | |
| | | companion object { |
| | | fun instance() = RRetrofit() |
| | | fun instance(isUseCert: Boolean = true, isTrustAll: Boolean = false) = RRetrofit(isUseCert, isTrustAll) |
| | | fun getLanguageType(language: String): String { |
| | | return when (language) { |
| | | Const.Language.CHINESE -> "1" |