content: package com.cn.xmf.job.admin.common;
  
  import com.alibaba.fastjson.serializer.SerializerFeature;
  import com.alibaba.fastjson.support.config.FastJsonConfig;
  import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
  import feign.auth.BasicAuthRequestInterceptor;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.http.MediaType;
  import org.springframework.http.converter.HttpMessageConverter;
  
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * 权限验证
   */
  @Configuration
  public class HttpBasicAuthConfig {
  
      @Value("${base-service.name}")
      private  String name;
      @Value("${base-service.password}")
      private String password;
  
      /**
       * 访问base-service的用户名密码.
       *
       */
      @Bean
      public BasicAuthRequestInterceptor appServiceAuthRequestInterceptor() {
          return new BasicAuthRequestInterceptor(name, password);
      }
  
      /**
       * 替换springMVC JSON格式化工具为FastJSON，同时支持输出value=null的字段
       *
       * @return http message converters
       */
      @Bean
      public HttpMessageConverters fastJsonHttpMessageConverters(){
          //1.需要定义一个convert转换消息的对象;
          FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
          //2:添加fastJson的配置信息;
          FastJsonConfig fastJsonConfig = new FastJsonConfig();
          fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
          fastJsonConfig.setSerializeFilters();
          //3处理中文乱码问题
          List<MediaType> fastMediaTypes = new ArrayList<>();
          fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
          //4.在convert中添加配置信息.
          fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
          fastJsonHttpMessageConverter.setFastJsonConfig(fastJsonConfig);
          return new HttpMessageConverters((HttpMessageConverter<?>) fastJsonHttpMessageConverter);
  
      }
  
  }
  