RestClientConfig.java 1.24 KB
package vion.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
import org.springframework.web.util.DefaultUriBuilderFactory;

/**
 * @author vion
 * @date 2024/7/19
 */
@Configuration
@Slf4j
public class RestClientConfig {

    @Bean(name = "bongRestClient")
    public RestClient getBongRestClient() {
        return RestClient.builder()
                .baseUrl("https://proapi.xbongbong.com")
                .build();
    }

    @Bean(name = "oDingRestClient")
    public RestClient getODingRestClient() {
        // disable url encoding
        // 在对 + 号进行处理时,默认对该字符不处理
        var uriBuilderFactory = new DefaultUriBuilderFactory("https://oapi.dingtalk.com");
        uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
        return RestClient.builder()
                .uriBuilderFactory(uriBuilderFactory)
                .build();
    }

    @Bean(name = "dingRestClient")
    public RestClient getdingRestClient() {
        return RestClient.builder()
                .baseUrl("https://api.dingtalk.com")
                .build();
    }
}