Commit 42f451b3 by YKai

feat:动态获取网关代码配置

parent ecf3abfe
...@@ -9,3 +9,5 @@ const val YDL_DOMAIN = "Domain-Name:" ...@@ -9,3 +9,5 @@ const val YDL_DOMAIN = "Domain-Name:"
const val YDL_DOMAIN_JAVA = "JAVA_BASE_URL" const val YDL_DOMAIN_JAVA = "JAVA_BASE_URL"
//JAVA 域名 //JAVA 域名
const val YDL_DOMAIN_JAVA_URL = "YDL_DOMAIN_JAVA_URL" const val YDL_DOMAIN_JAVA_URL = "YDL_DOMAIN_JAVA_URL"
// JAVA Api 登录注册地址
const val YDL_DOMAIN_LOGIN_BASE_URL = "JAVA_LOGIN_BASE_URL"
package com.ydl.ydlcommon.base.config package com.ydl.ydlcommon.base.config
import android.content.Context import android.content.Context
import com.ydl.ydlcommon.base.BaseApp import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.utils.YDLPreconditions import com.ydl.ydlcommon.utils.YDLPreconditions
import com.ydl.ydlnet.YDLHttpUtils import com.ydl.ydlnet.YDLHttpUtils
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
/** /**
* Created by haorui on 2019-08-29 . * Created by haorui on 2019-08-29 .
* Des: 模块配置类,使用建造者模式注入外部配置 * Des: 模块配置类,使用建造者模式注入外部配置
*/ */
class GlobalConfig private constructor(var builder: Builder) { class GlobalConfig private constructor(var builder: Builder) {
var appFrom: String = YDLConstants.FROM_YDL var appFrom: String = YDLConstants.FROM_YDL
var appEnv: String = YDLConstants.ENV_PROD var appEnv: String = YDLConstants.ENV_PROD
var appDebug: Boolean = false var appDebug: Boolean = false
var appName: String = "" var appName: String = ""
var appID: String = "" var appID: String = ""
var appWxPayType: String = "" var appWxPayType: String = ""
init { init {
this.appFrom = builder.appFrom this.appFrom = builder.appFrom
this.appEnv = builder.appEnv this.appEnv = builder.appEnv
this.appDebug = builder.appDebug this.appDebug = builder.appDebug
this.appName = builder.appName this.appName = builder.appName
this.appID = builder.appID this.appID = builder.appID
this.appWxPayType = builder.appWxPayType this.appWxPayType = builder.appWxPayType
} }
fun initEnv() { fun initEnv() {
builder.initEnv(BaseApp.instance) builder.initEnv(BaseApp.instance)
} }
class Builder() { class Builder() {
private var okHttpClient: OkHttpClient? = null private var okHttpClient: OkHttpClient? = null
var appFrom: String = YDLConstants.FROM_YDL var appFrom: String = YDLConstants.FROM_YDL
var appEnv: String = YDLConstants.ENV_PROD var appEnv: String = YDLConstants.ENV_PROD
var appBaseURL: String? = null var appBaseURL: String? = null
var multipleUrl: HashMap<String, String> = hashMapOf() var multipleUrl: HashMap<String, String> = hashMapOf()
var appDebug: Boolean = false var appDebug: Boolean = false
var appID: String = "" var appID: String = ""
var appName: String = "" var appName: String = ""
var appWxPayType: String = "" var appWxPayType: String = ""
fun setOkHttpClient(okHttpClient: OkHttpClient): Builder { fun setOkHttpClient(okHttpClient: OkHttpClient): Builder {
this.okHttpClient = okHttpClient this.okHttpClient = okHttpClient
return this return this
} }
fun setBaseURL(baseURL: String): Builder { fun setBaseURL(baseURL: String): Builder {
this.appBaseURL = baseURL this.appBaseURL = baseURL
return this return this
} }
fun setName(appName: String): Builder { fun setName(appName: String): Builder {
this.appName = appName this.appName = appName
return this return this
} }
fun setId(appID: String): Builder { fun setId(appID: String): Builder {
this.appID = appID this.appID = appID
return this return this
} }
fun setWxPayType(wxPayType: String): Builder { fun setWxPayType(wxPayType: String): Builder {
this.appWxPayType = wxPayType this.appWxPayType = wxPayType
return this return this
} }
fun setDebug(isDebug: Boolean): Builder { fun setDebug(isDebug: Boolean): Builder {
this.appDebug = isDebug this.appDebug = isDebug
return this return this
} }
/** /**
* 设置除了默认的BaseUrl的其他URL * 设置除了默认的BaseUrl的其他URL
*/ */
fun setMultipleUrlMap(multipleUrl: HashMap<String, String>): Builder { fun setMultipleUrlMap(multipleUrl: HashMap<String, String>): Builder {
this.multipleUrl.putAll(multipleUrl); this.multipleUrl.putAll(multipleUrl);
return this return this
} }
fun addUrl(domainName: String, domainUrl: String): Builder { fun addUrl(domainName: String, domainUrl: String): Builder {
YDLPreconditions.checkEmpty(domainName, "%s cannot be empty", "domainName") YDLPreconditions.checkEmpty(domainName, "%s cannot be empty", "domainName")
YDLPreconditions.checkEmpty(domainUrl, "%s cannot be empty", "domainUrl") YDLPreconditions.checkEmpty(domainUrl, "%s cannot be empty", "domainUrl")
multipleUrl[domainName] = domainUrl multipleUrl[domainName] = domainUrl
return this return this
} }
fun setFrom(appFrom: String): Builder { fun setFrom(appFrom: String): Builder {
this.appFrom = appFrom this.appFrom = appFrom
return this return this
} }
fun setEnv(@YDLConstants.AppEnv appEnv: String): Builder { fun setEnv(@YDLConstants.AppEnv appEnv: String): Builder {
this.appEnv = appEnv this.appEnv = appEnv
return this return this
} }
fun build(): GlobalConfig { fun build(): GlobalConfig {
return GlobalConfig(this) return GlobalConfig(this)
} }
fun initEnv(context: Context) { fun initEnv(context: Context) {
HttpConfig.getInstance().initEnv(context, appEnv) HttpConfig.getInstance().initEnv(context, appEnv)
val apiFactory = YDLHttpUtils val apiFactory = YDLHttpUtils
.getInstance() .getInstance()
.init(context) .init(context)
.config() .config()
.setBaseUrl(appBaseURL ?: HttpConfig.PHP_BASE_URL) .setBaseUrl(appBaseURL ?: HttpConfig.PHP_BASE_URL)
.addUrl(YDL_DOMAIN_JAVA, HttpConfig.JAVA_BASE_URL) .addUrl(YDL_DOMAIN_JAVA, HttpConfig.JAVA_BASE_URL)
.addUrl(YDL_DOMAIN_JAVA_URL, HttpConfig.JAVA_URL) .addUrl(YDL_DOMAIN_JAVA_URL, HttpConfig.JAVA_URL)
.setMultipleUrlMap(multipleUrl) .setMultipleUrlMap(multipleUrl)
if (okHttpClient == null) { if (okHttpClient == null) {
okHttpClient = HttpConfig.getInstance().createOkHttp() okHttpClient = HttpConfig.getInstance().createOkHttp()
} }
apiFactory.setOkClient(okHttpClient) apiFactory.setOkClient(okHttpClient)
HttpConfig.getInstance().initAuth() HttpConfig.getInstance().initAuth()
} HttpConfig.getInstance().initLoginBaseUrlConfig()
} }
}
companion object {
fun builder(): Builder { companion object {
return Builder() fun builder(): Builder {
} return Builder()
} }
} }
}
...@@ -99,6 +99,8 @@ class HttpConfig { ...@@ -99,6 +99,8 @@ class HttpConfig {
*/ */
var ACTION_URL = "" var ACTION_URL = ""
var JAVA_LOGIN_BASE_URL = "" // 登录注册动态配置网关地址
fun getInstance(): HttpConfig { fun getInstance(): HttpConfig {
return Holder.INSTANCE return Holder.INSTANCE
} }
...@@ -361,6 +363,7 @@ class HttpConfig { ...@@ -361,6 +363,7 @@ class HttpConfig {
PHP_BASE_URL = properties.getProperty("serverurl.$appEnv") PHP_BASE_URL = properties.getProperty("serverurl.$appEnv")
JAVA_BASE_URL = properties.getProperty("javaapi.$appEnv") JAVA_BASE_URL = properties.getProperty("javaapi.$appEnv")
JAVA_LOGIN_BASE_URL = JAVA_BASE_URL
ACTION_URL = properties.getProperty("actionurl.$appEnv") ACTION_URL = properties.getProperty("actionurl.$appEnv")
H5_URL = properties.getProperty("h5url.$appEnv") H5_URL = properties.getProperty("h5url.$appEnv")
...@@ -401,6 +404,26 @@ class HttpConfig { ...@@ -401,6 +404,26 @@ class HttpConfig {
} }
} }
/**
* 注册登录动态获取网关
*
*/
@SuppressLint("CheckResult")
fun initLoginBaseUrlConfig(){
ApiRequestUtil.getBaseUrl()
.compose(RxUtils.applySchedulers())
.compose(RxUtils.resultJavaData())
.subscribe({
if (it.baseUrlGatewayDTOList.isNotEmpty()){
if (it.baseUrlGatewayDTOList[0].goGateway){
JAVA_LOGIN_BASE_URL = it.baseUrlGatewayDTOList[0].baseUrl
}
}
}) {
LogUtil.i("HttpConfig", it.toString())
}
}
private object Holder { private object Holder {
val INSTANCE = HttpConfig() val INSTANCE = HttpConfig()
} }
......
package com.ydl.ydlcommon.bean
/**
* Created by Ykai on 2021/1/8.
*/
data class BaseUrlBean(
var baseUrlGatewayDTOList:List<UrlBean>
)
data class UrlBean(
var baseUrl:String,
var bizType:String?,
var goGateway:Boolean
)
\ No newline at end of file
...@@ -2,6 +2,7 @@ package com.ydl.ydlcommon.data.http.api; ...@@ -2,6 +2,7 @@ package com.ydl.ydlcommon.data.http.api;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.ydl.ydlcommon.bean.AuthBean; import com.ydl.ydlcommon.bean.AuthBean;
import com.ydl.ydlcommon.bean.BaseUrlBean;
import com.ydl.ydlcommon.bean.JavaGlobalInfo; import com.ydl.ydlcommon.bean.JavaGlobalInfo;
import com.ydl.ydlcommon.bean.MustUP; import com.ydl.ydlcommon.bean.MustUP;
import com.ydl.ydlcommon.data.http.BaseAPIResponse; import com.ydl.ydlcommon.data.http.BaseAPIResponse;
...@@ -58,4 +59,11 @@ public class ApiRequestUtil { ...@@ -58,4 +59,11 @@ public class ApiRequestUtil {
public static Observable<BaseAPIResponse<JavaGlobalInfo>> getJavaGlobalInfo() { public static Observable<BaseAPIResponse<JavaGlobalInfo>> getJavaGlobalInfo() {
return YDLHttpUtils.Companion.obtainApi(NetApiStore.class).getJavaGlobalInfo(); return YDLHttpUtils.Companion.obtainApi(NetApiStore.class).getJavaGlobalInfo();
} }
/**
* 获取登录注册模块网关
*/
public static Observable<BaseAPIResponse<BaseUrlBean>> getBaseUrl(){
return YDLHttpUtils.Companion.obtainApi(NetApiStore.class).getBaseUrl();
}
} }
package com.ydl.ydlcommon.data.http.api; package com.ydl.ydlcommon.data.http.api;
import com.ydl.ydlcommon.bean.AuthBean; import com.ydl.ydlcommon.bean.AuthBean;
import com.ydl.ydlcommon.bean.BaseUrlBean;
import com.ydl.ydlcommon.bean.JavaGlobalInfo; import com.ydl.ydlcommon.bean.JavaGlobalInfo;
import com.ydl.ydlcommon.bean.MustUP; import com.ydl.ydlcommon.bean.MustUP;
import com.ydl.ydlcommon.data.http.BaseAPIResponse; import com.ydl.ydlcommon.data.http.BaseAPIResponse;
...@@ -14,6 +15,7 @@ import retrofit2.http.Body; ...@@ -14,6 +15,7 @@ import retrofit2.http.Body;
import retrofit2.http.FieldMap; import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded; import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET; import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers; import retrofit2.http.Headers;
import retrofit2.http.POST; import retrofit2.http.POST;
...@@ -49,4 +51,7 @@ interface NetApiStore { ...@@ -49,4 +51,7 @@ interface NetApiStore {
@GET("config/socket-config") @GET("config/socket-config")
Observable<BaseAPIResponse<JavaGlobalInfo>> getJavaGlobalInfo(); Observable<BaseAPIResponse<JavaGlobalInfo>> getJavaGlobalInfo();
@Headers({YDL_DOMAIN+ YDL_DOMAIN_JAVA,"userPort:1"})
@POST("systemconfig/get_gateway_base_url")
Observable<BaseAPIResponse<BaseUrlBean>> getBaseUrl();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment