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

me.chanjar.weixin.qidian.solon.config.WxQidianServiceAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 3.0.0-M4
Show newest version
package me.chanjar.weixin.qidian.solon.config;

import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;
import me.chanjar.weixin.qidian.solon.enums.HttpClientType;
import me.chanjar.weixin.qidian.solon.properties.WxQidianProperties;

import me.chanjar.weixin.qidian.api.WxQidianService;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceHttpClientImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceJoddHttpImpl;
import me.chanjar.weixin.qidian.api.impl.WxQidianServiceOkHttpImpl;
import me.chanjar.weixin.qidian.config.WxQidianConfigStorage;

/**
 * 腾讯企点相关服务自动注册.
 *
 * @author alegria
 */
@Configuration
public class WxQidianServiceAutoConfiguration {

  @Bean
  @Condition(onMissingBean = WxQidianService.class)
  public WxQidianService wxQidianService(WxQidianConfigStorage configStorage, WxQidianProperties wxQidianProperties) {
    HttpClientType httpClientType = wxQidianProperties.getConfigStorage().getHttpClientType();
    WxQidianService wxQidianService;
    switch (httpClientType) {
      case OkHttp:
        wxQidianService = newWxQidianServiceOkHttpImpl();
        break;
      case JoddHttp:
        wxQidianService = newWxQidianServiceJoddHttpImpl();
        break;
      case HttpClient:
        wxQidianService = newWxQidianServiceHttpClientImpl();
        break;
      default:
        wxQidianService = newWxQidianServiceImpl();
        break;
    }

    wxQidianService.setWxMpConfigStorage(configStorage);
    return wxQidianService;
  }

  private WxQidianService newWxQidianServiceImpl() {
    return new WxQidianServiceImpl();
  }

  private WxQidianService newWxQidianServiceHttpClientImpl() {
    return new WxQidianServiceHttpClientImpl();
  }

  private WxQidianService newWxQidianServiceOkHttpImpl() {
    return new WxQidianServiceOkHttpImpl();
  }

  private WxQidianService newWxQidianServiceJoddHttpImpl() {
    return new WxQidianServiceJoddHttpImpl();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy