Commit f4bc0d3d by YKai

Merge remote-tracking branch 'origin/okhttp配置防抓包' into 4.1.69(强绑手机号)

# Conflicts:
#	config.gradle
parents 720bcebb 7a6e2320
......@@ -88,22 +88,22 @@ ext {
// -------------- 业务模块 --------------
//第三步 若干
"m-confide" : "0.0.49.07",
"m-consultant" : "0.0.59.70",
"m-fm" : "0.0.30.03",
"m-user" : "0.0.61.30",
"m-home" : "0.0.22.60",
"m-im" : "0.0.18.49",
"m-dynamic" : "0.0.7.21",
"m-article" : "0.0.0.8",
"m-confide" : "0.0.49.02",
"m-consultant" : "0.0.59.65",
"m-fm" : "0.0.30.01",
"m-user" : "0.0.61.18",
"m-home" : "0.0.22.54",
"m-im" : "0.0.18.40",
"m-dynamic" : "0.0.7.19",
"m-article" : "0.0.0.6",
"m-muse" : "0.0.28.22",
"m-tests" : "0.0.24.12",
"m-course" : "0.0.42.23",
"m-muse" : "0.0.20.7",
"m-tests" : "0.0.24.9",
"m-course" : "0.0.42.20",
//-------------- 业务模块 API 层 --------------
"m-audioim-api" : "0.0.6",
"m-confide-api" : "0.0.2.11",
"m-consultant-api": "0.0.5.61",
"m-confide-api" : "0.0.2.1",
"m-consultant-api": "0.0.5.6",
"m-course-api" : "0.0.3.6",
"m-fm-api" : "0.0.3",
"m-muse-api" : "0.0.1",
......
......@@ -2,6 +2,7 @@ package com.ydl.ydlnet.builder.config;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;
import com.ydl.ydlnet.builder.cookie.CookieJarImpl;
import com.ydl.ydlnet.builder.cookie.store.CookieStore;
......@@ -16,8 +17,14 @@ import com.ydl.ydlnet.builder.manage.HttpUrlManager;
import com.ydl.ydlnet.client.interfaces.BuildHeadersListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.SocketAddress;
import java.net.URI;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
......@@ -197,6 +204,7 @@ public class OkHttpConfig {
setTimeout();
setMultipleUrl();
setDebugConfig();
setProxy();
okHttpClient = okHttpClientBuilder.build();
return okHttpClient;
......@@ -225,6 +233,25 @@ public class OkHttpConfig {
okHttpClientBuilder.addInterceptor(new RequestLogInterceptor(isDebug,requestHandler));
}
/**
* 配置线上环境防止抓包
*/
private void setProxy(){
if (!isDebug) {
okHttpClientBuilder.proxySelector(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
return Collections.singletonList(Proxy.NO_PROXY);
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
/**
* 配置headers
......
......@@ -137,7 +137,7 @@ class HttpConfig {
//获取证书
val cerInputStream = context.resources.openRawResource(com.ydl.ydlcommon.R.raw.ydl_trust);
val builder = OkHttpConfig.Builder(context);
val builder = OkHttpConfig.Builder(context)
if (appDebug) {
builder.setNetInterceptor(StethoInterceptor())
} else {
......
package com.ydl.utils
import android.content.Context
import android.net.Proxy
import android.os.Build
import android.text.TextUtils
/**
* Created by Ykai on 2021/4/1.
*/
object ProxyCheckUtils {
/**
* 判断设备 是否使用代理上网
* @param context 上下文对象
* return 当前网络是否开启了代理
*/
fun isWifiProxy(context: Context): Boolean {
val IS_ICS_OR_LATER: Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
val proxyAddress: String
val proxyPort: Int
if (IS_ICS_OR_LATER) {
proxyAddress = System.getProperty("http.proxyHost")
val portStr = System.getProperty("http.proxyPort")
proxyPort = (portStr ?: "-1").toInt()
} else {
proxyAddress = Proxy.getHost(context)
proxyPort = Proxy.getPort(context)
}
return !TextUtils.isEmpty(proxyAddress) && proxyPort != -1
}
}
\ No newline at end of file
......@@ -35,6 +35,7 @@ import com.tencent.smtt.sdk.WebViewClient;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.ydl.utils.PopUtils;
import com.ydl.utils.ProxyCheckUtils;
import com.ydl.utils.WebUrlParamsUtils;
import com.ydl.ydl_router.manager.YDLRouterManager;
import com.ydl.ydlcommon.base.BaseActivity;
......@@ -371,7 +372,10 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
tellData = new TellData();
}
initView();
if (!BaseApp.instance.getGlobalConfig().getAppDebug()&& ProxyCheckUtils.INSTANCE.isWifiProxy(this)){
ToastUtil.toastShort("网络设置错误");
return;
}
startType = getIntent().getIntExtra("startType", 0);
rightText = getIntent().getStringExtra("rightText");
if (h5Params == null) {
......@@ -380,6 +384,7 @@ public class NewH5Activity extends BaseActivity implements PtrHandler {
finish();
return;
}
setUrlHeightParams();
EventBus.getDefault().register(this);
jtoJHandle = WebModularServiceUtils.Companion.getWebService().getJavascripHandler(this, tellData = tellData);
......
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