1
0
mirror of synced 2026-02-22 05:47:52 +08:00

🎨 #571 微信小程序接口请求增加多种http客户端

This commit is contained in:
Mario Luo
2020-06-01 22:35:59 +08:00
committed by GitHub
parent 6c3d090ebd
commit 1c60839890
9 changed files with 653 additions and 426 deletions

View File

@@ -23,7 +23,7 @@
wx.miniapp.config-storage.redis.host = 127.0.0.1
wx.miniapp.config-storage.redis.port = 6379
# http客户端配置
wx.miniapp.config-storage.http-client-type=HttpClient # http客户端类型: HttpClient(默认)
wx.miniapp.config-storage.http-client-type=HttpClient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
wx.miniapp.config-storage.http-proxy-host=
wx.miniapp.config-storage.http-proxy-port=
wx.miniapp.config-storage.http-proxy-username=

View File

@@ -1,11 +1,14 @@
package com.binarywang.spring.starter.wxjava.miniapp.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceJoddHttpImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import com.binarywang.spring.starter.wxjava.miniapp.enums.StorageType;
import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.miniapp.properties.ConfigStorage;
import com.binarywang.spring.starter.wxjava.miniapp.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
@@ -49,9 +52,19 @@ public class WxMaAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WxMaService.class)
public WxMaService service(WxMaConfig wxMaConfig) {
final WxMaServiceImpl service = new WxMaServiceImpl();
service.setWxMaConfig(wxMaConfig);
return service;
HttpClientType httpClientType = wxMaProperties.getConfigStorage().getHttpClientType();
WxMaService wxMaService;
if (httpClientType == HttpClientType.OkHttp) {
wxMaService = new WxMaServiceOkHttpImpl();
} else if (httpClientType == HttpClientType.JoddHttp) {
wxMaService = new WxMaServiceJoddHttpImpl();
} else if (httpClientType == HttpClientType.HttpClient) {
wxMaService = new WxMaServiceHttpClientImpl();
} else {
wxMaService = new WxMaServiceImpl();
}
wxMaService.setWxMaConfig(wxMaConfig);
return wxMaService;
}
@Bean

View File

@@ -10,5 +10,13 @@ public enum HttpClientType {
/**
* HttpClient.
*/
HttpClient
HttpClient,
/**
* OkHttp.
*/
OkHttp,
/**
* JoddHttp.
*/
JoddHttp,
}