Skip to content

Commit

Permalink
1.完善acid自动获取(增加另一种不同情况下的获取方式) (#24)
Browse files Browse the repository at this point in the history
2.添加网络超时限制,避免特定情况下出现长时间停顿
  • Loading branch information
hhll16384 committed Sep 15, 2023
1 parent a2caeab commit d6dc8d4
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.Log;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import cn.hutool.core.util.StrUtil;
import okhttp3.OkHttpClient;
Expand All @@ -15,7 +16,7 @@ public static Integer queryAcid() {
String id = null;
try {

OkHttpClient client = new OkHttpClient();
OkHttpClient client = new OkHttpClient.Builder().connectTimeout(3, TimeUnit.SECONDS).build();//增加3秒超时设置避免等待太久
Request request = new Request.Builder().url("http://8.8.8.8").get().build();
Response response = client.newCall(request).execute();
String url = response.request().url().toString();
Expand All @@ -32,8 +33,14 @@ public static Integer queryAcid() {
int begin = body.indexOf("/index_") + 7;
int end = body.indexOf(".html", begin);
if (begin == 6 || end == -1) {
Log.i("QueryAcidClient","Could not find acid in Response body!");
return -1;

//return -1; //在这增加新的一种获取方法
begin = body.indexOf("ac_id=") + 6;
end = body.indexOf("&", begin);
if (begin == 5 || end == -1) {
Log.i("QueryAcidClient","Could not find acid in Response body!");
return -1;
}
}
id = body.substring(begin, end);
}
Expand Down

0 comments on commit d6dc8d4

Please sign in to comment.