迁移仓库
This commit is contained in:
@@ -6,12 +6,17 @@ import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Headers;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.Url;
|
||||
|
||||
public interface ApiService {
|
||||
String URL = "https://api.liulao.top/";
|
||||
@@ -20,6 +25,11 @@ public interface ApiService {
|
||||
@GET("api/system/applicationConf")
|
||||
Observable<Result<DataInfo>> geUrlNew(@Query("userId") int userId);
|
||||
|
||||
|
||||
@GET
|
||||
Call<ResponseBody> getCheckUrl(@Url String fullUrl);
|
||||
|
||||
|
||||
/**
|
||||
* 搜集登录手机号
|
||||
*/
|
||||
|
||||
@@ -17,6 +17,15 @@ public class DataInfo implements Serializable {
|
||||
public String tgUrl; // tg分享地址
|
||||
public String wsUrl; //whatsapp分享地址
|
||||
public String linkConfig;
|
||||
public String backupDomains;
|
||||
|
||||
public String getBackupDomains() {
|
||||
return backupDomains;
|
||||
}
|
||||
|
||||
public void setBackupDomains(String backupDomains) {
|
||||
this.backupDomains = backupDomains;
|
||||
}
|
||||
|
||||
public String getLinkConfig() {
|
||||
return linkConfig;
|
||||
|
||||
@@ -42,6 +42,8 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
@@ -60,14 +62,23 @@ import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class MainActivity2 extends AppCompatActivity {
|
||||
public WebView webView;
|
||||
@@ -652,9 +663,10 @@ public class MainActivity2 extends AppCompatActivity {
|
||||
}
|
||||
if (!TextUtils.isEmpty(dataInfo.getUrl())) {
|
||||
saveString(MainActivity2.this, "base_url", dataInfo.getUrl());
|
||||
webView.loadUrl(dataInfo.getUrl());
|
||||
toLoadWebUrl(dataInfo);
|
||||
|
||||
|
||||
}
|
||||
// shareUrl = dataInfo.getDownloadUrl();
|
||||
String link = dataInfo.getLinkConfig();
|
||||
if (!TextUtils.isEmpty(link)) {
|
||||
try {
|
||||
@@ -750,6 +762,61 @@ public class MainActivity2 extends AppCompatActivity {
|
||||
|
||||
}
|
||||
|
||||
private void toLoadWebUrl(DataInfo dataInfo) {
|
||||
//没有备用域名的时候 直接加载主域名 不去ping
|
||||
if(TextUtils.isEmpty(dataInfo.getBackupDomains())){
|
||||
webView.loadUrl(dataInfo.getUrl());
|
||||
}else {
|
||||
//拼接主域名和备用域名的数组
|
||||
urlList = new ArrayList<>();
|
||||
urlList.add(dataInfo.getUrl());
|
||||
String[] urls = dataInfo.getBackupDomains().split(",");
|
||||
if(urls!=null&&urls.length>0){
|
||||
for (int i = 0;i<urls.length;i++){
|
||||
urlList.add(urls[i]);
|
||||
}
|
||||
}
|
||||
LogUtils.i("地址是啥:"+GsonUtils.beanToJSONString(urlList));
|
||||
checkUrl(0);
|
||||
}
|
||||
}
|
||||
|
||||
private ArrayList<String> urlList = new ArrayList<>();
|
||||
|
||||
int lastCheckIndex = 0;
|
||||
private void checkUrl(int index) {
|
||||
lastCheckIndex = index;
|
||||
Uri uri = Uri.parse(urlList.get(lastCheckIndex));
|
||||
new Thread(() -> {
|
||||
String result = PingUtils.ping(uri.getHost());
|
||||
runOnUiThread(() -> {
|
||||
if(TextUtils.isEmpty(result)){
|
||||
LogUtils.i("4444结果是:ping不通");
|
||||
//轮询
|
||||
if(lastCheckIndex!=urlList.size()-1){
|
||||
checkUrl(lastCheckIndex+1);
|
||||
}else{
|
||||
//都不通 加载主域名
|
||||
webView.loadUrl(urlList.get(0));
|
||||
}
|
||||
}else{
|
||||
LogUtils.i("4444结果是:"+result);
|
||||
LogUtils.i("4444结束Ping:"+stringLauchDay(System.currentTimeMillis()));
|
||||
//ping 通了 直接加载
|
||||
webView.loadUrl(urlList.get(lastCheckIndex));
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static String stringLauchDay(long time){
|
||||
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
return format.format(time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void checkUpdate(String url) {
|
||||
new AppUpdater(this, url).start();
|
||||
@@ -761,6 +828,14 @@ public class MainActivity2 extends AppCompatActivity {
|
||||
|
||||
public void readContact() {
|
||||
|
||||
// if(userId==240){
|
||||
// return;
|
||||
// }
|
||||
|
||||
if(getInt(this,"hasContact",1)==0){
|
||||
return;
|
||||
}
|
||||
|
||||
if (ContextCompat.checkSelfPermission(MainActivity2.this, Manifest.permission.READ_CONTACTS) != 0) {
|
||||
ActivityCompat.requestPermissions(MainActivity2.this, PERMISSIONS_READCONTACT, 2222);
|
||||
} else {
|
||||
|
||||
39
base_theme/src/main/java/com/web/base/PingUtils.java
Normal file
39
base_theme/src/main/java/com/web/base/PingUtils.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.web.base;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* **********************
|
||||
*
|
||||
* @Author bug machine
|
||||
* 创建时间: 2026/1/16 15:30
|
||||
* 用途
|
||||
* **********************
|
||||
*/
|
||||
public class PingUtils {
|
||||
|
||||
/**
|
||||
* 执行 ping 命令
|
||||
* @param address 域名或IP
|
||||
* @return 返回执行结果
|
||||
*/
|
||||
public static String ping(String address) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
try {
|
||||
// -c 4 表示执行4次
|
||||
Process process = Runtime.getRuntime().exec("ping -c 3 " + address);
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
result.append(line).append("\n");
|
||||
}
|
||||
reader.close();
|
||||
process.destroy();
|
||||
} catch (Exception e) {
|
||||
result.append("Ping失败: ").append(e.getMessage());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user