All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.rwocj.wx.pay.common.OkHttpClientBuilderUtil Maven / Gradle / Ivy

There is a newer version: 0.13-javax
Show newest version
package top.rwocj.wx.pay.common;

import lombok.experimental.UtilityClass;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;

import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

@UtilityClass
public class OkHttpClientBuilderUtil {

    public static OkHttpClient.Builder wxPayOkHttpClient(Interceptor interceptor, List> customizers) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.hostnameVerifier((hostname, session) -> hostname.endsWith(".weixin.qq.com"))
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(10000, TimeUnit.MILLISECONDS)
                .connectTimeout(3000, TimeUnit.MILLISECONDS);
        if (interceptor != null) {
            builder.addInterceptor(interceptor);
        }
        if (customizers != null) {
            for (Consumer customizer : customizers) {
                customizer.accept(builder);
            }
        }
        return builder;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy