左晓为主开发手持机充值管理机
zuojincheng
2025-03-21 8521954fa97bdfc54123afb4a72755ece311db06
generallibrary/src/main/java/com/dayu/general/net/RetrofitClient.kt
@@ -1,7 +1,6 @@
package com.dayu.general.net
import com.dayu.baselibrary.BuildConfig
import com.dayu.qiheonlinelibrary.net.MyIntercepterApplication
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
@@ -14,7 +13,13 @@
 * Author: zuo
 * Date: 2025-03-06
 */
class RetrofitClient {
class RetrofitClient// 包含header、body数据
//        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
//设置连接和读取时间
//添加统一的header
//添加日志拦截器
//添加数据请求统一处理拦截器
    () {
@@ -22,26 +27,19 @@
    val READ_TIME_OUT: Int = 10
    val CONNECT_TIME_OUT: Int = 10
    private fun RetrofitClient() {
    init {
        val loggingInterceptor = HttpLoggingInterceptor()
        // 包含header、body数据
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
        //        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
        val builder:  OkHttpClient.Builder = OkHttpClient().newBuilder()
        //设置连接和读取时间
        builder.readTimeout(READ_TIME_OUT.toLong(), TimeUnit.SECONDS)
        builder.connectTimeout(CONNECT_TIME_OUT.toLong(), TimeUnit.SECONDS)
        builder.writeTimeout(CONNECT_TIME_OUT.toLong(), TimeUnit.SECONDS)
        //添加统一的header
        builder.addInterceptor(MyIntercepterApplication())
        //添加日志拦截器
        //添加数据请求统一处理拦截器
        if (BuildConfig.DEBUG) {
            builder.addInterceptor(loggingInterceptor)
        }
        val client: OkHttpClient = builder.build()
        retrofit = Retrofit.Builder()
            .baseUrl(NetConstans.BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
@@ -49,6 +47,7 @@
            .client(client).build()
    }
    @Synchronized