1:添加备用服务器,在请求themeData的时候,返回的不对的时候,就切换服务器

This commit is contained in:
2025-12-31 03:31:31 +08:00
parent 479e039e56
commit c2fd1df529
12 changed files with 147 additions and 83 deletions

View File

@@ -44,6 +44,7 @@ import com.tencent.qcloud.tuicore.TUILogin;
import com.tencent.qcloud.tuicore.interfaces.TUICallback;
import com.xscm.moduleutil.bean.UserBean;
import com.xscm.moduleutil.bean.UserInfo;
import com.xscm.moduleutil.dialog.ConfirmDialog;
import com.xscm.moduleutil.event.AppLifecycleEvent;
import com.xscm.moduleutil.event.UnreadCountEvent;
import com.xscm.moduleutil.http.RetrofitClient;
@@ -165,14 +166,14 @@ public class CommonAppContext extends MultiDexApplication implements Application
SpUtil.setShelf(1);
}
if (SpUtil.getTaskService()==1){
selectRelease = 2;
if (SpUtil.getTaskService() == 1){//当如果是正式服的时候,这里就变成可以设置成辅助服务器,当如果是测试服务的时候,就是变成了测试了,
selectRelease = 1;
}
//设置mqtt环境 false 测试环境 true 正式环境
// ExternalResConstants.INSTANCE.setIS_MQTT_RELEASE(false);
//设置http环境 false 测试环境 true 正式环境
ExternalResConstants.INSTANCE.setIS_HTTP_RELEASE(selectRelease != -1);
ExternalResConstants.INSTANCE.setIS_HTTP_RELEASE(selectRelease);
currentEnvironment = ExternalResConstants.INSTANCE.HTTP_PATH();
initialization();
@@ -220,6 +221,38 @@ public class CommonAppContext extends MultiDexApplication implements Application
}
}
public void dialogHttp(){
new ConfirmDialog(ActivityUtils.getTopActivity(),
"提示",
"当前网络环境异常,请重试",
"确认",
"取消",
v -> {
// 点击“确认”按钮时执行删除操作
selectRelease = 3;
initHttp();
},
v -> {
selectRelease = 3;
initHttp();
// 点击“取消”按钮时什么都不做
}, false, 0).show();
}
public void initHttp(){
ExternalResConstants.INSTANCE.setIS_HTTP_RELEASE(selectRelease);
currentEnvironment = ExternalResConstants.INSTANCE.HTTP_PATH();
try {
RetrofitClient.INSTANCE=null;
RetrofitClient.getInstance();
clearLoginInfo();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
// 更新未读消息数的方法
private void updateUnreadMessageCount() {
V2TIMManager.getConversationManager().getTotalUnreadMessageCount(new V2TIMValueCallback<Long>() {

View File

@@ -4,7 +4,7 @@ import com.xscm.moduleutil.utils.config.EnvironmentEnum
object ExternalResConstants {
//================================================================================MQTT======================================================================================
//================================================================================MQTT======================================================================================
// var IS_MQTT_RELEASE = true
// val MQTT_PATH_DEBUG = "tcp://1.13.181.248"
// val MQTT_PATH_RELEASE = "tcp://1.13.101.98"
@@ -17,12 +17,15 @@ object ExternalResConstants {
// }
// }
//================================================================================HTTP======================================================================================
var IS_HTTP_RELEASE = true
val HTTP_PATH_DEBUG:EnvironmentEnum = EnvironmentEnum.TEST
val HTTP_PATH_RELEASE:EnvironmentEnum = EnvironmentEnum.PRODUCTION
var IS_HTTP_RELEASE: Int = 1 //0 测试环境 1 正式环境 2 辅助环境
val HTTP_PATH_DEBUG: EnvironmentEnum = EnvironmentEnum.TEST
val HTTP_PATH_RELEASE: EnvironmentEnum = EnvironmentEnum.PRODUCTION
val HTTP_AUXILIARY: EnvironmentEnum = EnvironmentEnum.Auxiliary
fun HTTP_PATH(): EnvironmentEnum {
return if (IS_HTTP_RELEASE) {
return if (IS_HTTP_RELEASE == 1) {
HTTP_PATH_RELEASE
} else if (IS_HTTP_RELEASE == 3) {
HTTP_AUXILIARY
} else {
HTTP_PATH_DEBUG
}

View File

@@ -61,9 +61,9 @@ import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
public class RetrofitClient {
private static RetrofitClient INSTANCE;
public static RetrofitClient INSTANCE;
private static ApiServer sApiServer;
public static final int DEFAULT_TIME_OUT = 30;
public static final int DEFAULT_TIME_OUT = 10;
private static OkHttpClient client;
private final Retrofit mRetrofit;
@@ -1695,10 +1695,11 @@ public class RetrofitClient {
observer.onNext(baseModel.getData());
}
} else {
observer.onNext(null);
CommonAppContext.getInstance().dialogHttp();
}
}
} else {
CommonAppContext.getInstance().dialogHttp();
LogUtils.e("获取主题数据失败", response.message());
}
}
@@ -1706,6 +1707,7 @@ public class RetrofitClient {
@Override
public void onFailure(Call<BaseModel<ThemeBean>> call, Throwable t) {
LogUtils.e("获取主题数据失败", t);
CommonAppContext.getInstance().dialogHttp();
}
});
}

View File

@@ -90,7 +90,7 @@ public class SystemUtils {
ConfigUtils configUtils = ConfigUtils.getInstance(context);
configUtils.setConfigName(system_uuid_key);
String system_config_uuid = configUtils.findStringByKey(system_uuid_key);
if (system_config_uuid == null) {
if (system_config_uuid == null || system_config_uuid.isEmpty()) {
// system_config_uuid = DeviceUtils.getUniqueDeviceId();
configUtils.addOrUpdateText(system_uuid_key, system_config_uuid);
}

View File

@@ -5,6 +5,7 @@ import android.content.SharedPreferences;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
public class ConfigUtils {
@@ -74,8 +75,11 @@ public class ConfigUtils {
*/
public String findStringByKey(String key) {
if (data_list==null){
data_list = new HashMap<String, Object>();
}
if (data_list.containsKey(key))
return data_list.get(key).toString();
return data_list.get(key)!=null?data_list.get(key).toString():"";
else
return sp.getString(key, null);
}

View File

@@ -20,6 +20,26 @@ public enum EnvironmentEnum {
// "https://vespa.qxyushen.top/h5",
"https://yushengapi.qxyushen.top/h5",
0),
Auxiliary(//辅助生产环境
//"https://vespa.qxyushen.top/",
"https://qixinghuishen.qxhs.xyz/",
"KvNmqZc+VMzO4CfGMd5zmG6w6OFwpFO/19TwXUWfHDOBgmnl9DgIuE+kbrjNNnxqhtP3pH7bBrnSaSeFtunr72q6sgpLsfuswcUroMvz2slaTBcNzCaLi+GSnM3gB/GdO47mwLdk+iYBTvPUOCIuT608Z29z09w+vPeUDoMCHJBGXu6uh7Nj6PtV1dfGoUvByk1ZF0WYVjIqKDcb3tXY4jonFh3XAWhzMy8xKwN6F2nuK2IcdIwaSPsvuMZmhatP6f9kOE+vnfweyCHS3RxiG474WIoZGJM8omrl3/pOVqE=",
"https://oss-cn-beijing.aliyuncs.com/",
"LTAI5tKgrfcFQxH46ZwWYgFW",
"ZOjTqAJmUL563EKFKySrUwAHtx4hKt",
"midi01",
"https://midi01.oss-cn-beijing.aliyuncs.com/",
"wxc7681513be9f926b",
1600096860,
"3e8f3add448d4692bc1d04c75ffe801b",
//"tcp://1.13.101.98",
// "tcp://1.13.20.30",
"tcp://qixinghuishen.qxhs.xyz",
// "https://vespa.qxyushen.top/h5",
"https://qixinghuishen.qxhs.xyz/h5",
0),
TEST(//测试环境
"https://test.vespa.qxyushen.top/",
"6rdWuz058oq5OahdbFiGEybUcdahd12J83L34Uc7MrPIrxtFG+rXiwDvRcqNvjwbClbbmvMrmxKVkIysFByBsl0Qe9kqd2w8T/nhK5G6eXXlk2V9AjYCieIU+jRnjZBB+Cfechr6rCGJ2aeBARIsXcRPW7wm9WFK9euh5T+v6Pyte68yNaNdcYCll3+U4/uCEog7HygCnMIbAU+kqoPdmn2H+51YOHW+VsnsHd4w1+I3f8Tt0xLIXGM4GWnQueZ5GR46GTWiSYMy8dCIh9SPIMRyC91GosVcfGPMJSdcXqc=",