feat:增加接口路径混淆拦截器

This commit is contained in:
Max
2024-01-19 18:21:13 +08:00
parent 4feed5409d
commit 9b27d3b395
2 changed files with 38 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.util.NIMUtil;
import com.nnbc123.app.AgentActivity;
import com.nnbc123.core.interceptor.PathInterceptor;
import com.nnbc123.library.common.application.BaseApp;
import com.nnbc123.library.common.file.FileHelper;
import com.nnbc123.library.utils.ResUtil;
@@ -404,6 +405,7 @@ public class XChatApplication extends BaseApp {
RxNet.init(context)
.debug(BuildConfig.DEBUG)
.setBaseUrl(url)
.addInterceptors(new PathInterceptor())
.addInterceptors(new ParamsInterceptor(httpParams))
.addInterceptors(new NoParamsInterceptor())//注意:拦截器的添加顺序,请求的拦截顺序
.build();

View File

@@ -0,0 +1,36 @@
package com.nnbc123.core.interceptor
import android.util.Log
import com.nnbc123.core.Env
import com.nnbc123.core.UriProvider
import com.nnbc123.library.utils.codec.DESUtils
import okhttp3.Interceptor
import okhttp3.Response
/**
* Created by Max on 2024/1/19 17:26
* Desc:路径转化
**/
class PathInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val builder = request.newBuilder()
val url = request.url()
val path = url.encodedPath()
if (!url.toString().startsWith(UriProvider.API_URL)) {
return chain.proceed(request)
}
val newPath = DESUtils.DESAndBase64(path)
return if (newPath.isNullOrEmpty()) {
chain.proceed(request)
} else {
val newUrl = url.newBuilder().encodedPath("/$newPath").build()
if (Env.isDebug()) {
Log.d("PathInterceptor", "$url -> $newUrl")
}
builder.url(newUrl)
builder.addHeader("des_path", "true")
chain.proceed(builder.build())
}
}
}