From fa9c81461146d388dc530adebbe5ad341d662566 Mon Sep 17 00:00:00 2001 From: zhongchao Date: Tue, 16 Nov 2021 19:47:29 +0800 Subject: [PATCH] socket divide origin and new --- .../cloud/socket/third/core/SocketConfig.java | 28 +++++++++++++++---- .../socket/third/core/SocketConstants.java | 2 ++ .../third/core/network/RequestManager.java | 18 ++++++++---- .../third/core/network/ServiceFactory.java | 16 +++++++++++ .../core/network/TechOriginApiService.java | 15 ++++++++++ gradle.properties | 2 +- 6 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/TechOriginApiService.java diff --git a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConfig.java b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConfig.java index e8ff777..df847ed 100644 --- a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConfig.java +++ b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConfig.java @@ -1,9 +1,13 @@ package com.mogo.cloud.socket.third.core; +import static com.mogo.cloud.socket.third.core.SocketConstants.DEFAULT_AUTH_ORIGIN_PUB_KEY; +import static com.mogo.cloud.socket.third.core.SocketConstants.DEFAULT_AUTH_PUB_KEY; + import android.content.Context; import android.text.TextUtils; import com.mogo.cloud.TelephoneUtil; +import com.mogo.cloud.passport.MoGoAiCloudClientConfig; import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon; public class SocketConfig { @@ -13,7 +17,9 @@ public class SocketConfig { private Context appContext; - /**Need to be registered by server before it can be applied*/ + /** + * Need to be registered by server before it can be applied + */ private String channelId; private Environment environment; @@ -22,7 +28,9 @@ public class SocketConfig { private boolean openAnalytics; - /**Customized sn can be set*/ + /** + * Customized sn can be set + */ private String sn; private String uid; @@ -96,12 +104,16 @@ public class SocketConfig { return this; } - /**Retrieve sn of current device, and return customized sn first*/ + /** + * Retrieve sn of current device, and return customized sn first + */ public String getSn() { return TextUtils.isEmpty(sn) ? TelephoneUtil.getSerialNumber() : sn; } - /**The third-party device can set a customized sn*/ + /** + * The third-party device can set a customized sn + */ public SocketConfig setSn(String sn) { this.sn = sn; return this; @@ -126,8 +138,12 @@ public class SocketConfig { } public String getAuthPubKey() { - if(TextUtils.isEmpty(authPubKey)){ - authPubKey = SocketConstants.DEFAULT_AUTH_PUB_KEY; + if (TextUtils.isEmpty(authPubKey)) { + if (MoGoAiCloudClientConfig.getInstance().isUseOriginSocket()) { + authPubKey = DEFAULT_AUTH_ORIGIN_PUB_KEY; + } else { + authPubKey = DEFAULT_AUTH_PUB_KEY; + } } return authPubKey; } diff --git a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConstants.java b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConstants.java index f4e5177..131e814 100644 --- a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConstants.java +++ b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/SocketConstants.java @@ -19,4 +19,6 @@ public interface SocketConstants { String DEFAULT_AUTH_PUB_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC1En+aK8zhDRI2495gwmFYuIAHJxFV8MQuBWSY+xRJMtNq6UITx72NgfMWxmxzoxrvv6T1mb3HMVpIto1H3mliPg9LbZ48GAuDRWXHxLxNR69W45okhGAkDxU1GmlRPzEplwwfbar5Bdv3Bd24ABpGQhzozfEK5T5Ej9KrT/a7YwIDAQAB"; + String DEFAULT_AUTH_ORIGIN_PUB_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCLe57ORPgOnBrcWmGac3esB4PtIyI0rAHiyk5QoCRTnTyanwWLfstu7mz2MSHD3YuveNWDiIY8vtRvFNE4M/yA7eb4Mct01VKhKFI/JqwyXgNaSh5YCfmv0vg9687c7IUjTEAg+ReC/bSLDqEB3a0vuP95Txtj9smMlx1e37XFYQIDAQAB"; + } diff --git a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/RequestManager.java b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/RequestManager.java index 8923100..76cb592 100644 --- a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/RequestManager.java +++ b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/RequestManager.java @@ -11,6 +11,7 @@ import com.elegant.network.RequestOptions; import com.elegant.network.utils.GsonUtil; import com.elegant.network.utils.NetworkSdkUtils; import com.elegant.utils.CommonUtils; +import com.mogo.cloud.passport.MoGoAiCloudClientConfig; import com.mogo.cloud.socket.third.core.SocketConfig; import com.mogo.cloud.socket.third.core.network.model.MessageCallbackData; import com.mogo.cloud.socket.third.core.network.model.SocketAddressData; @@ -20,6 +21,7 @@ import java.util.List; import java.util.Map; import okhttp3.RequestBody; +import rx.Observable; public class RequestManager { @@ -42,19 +44,19 @@ public class RequestManager { @Override protected void onFailure(int code, String message) { super.onFailure(code, message); - Logger.d(TAG,"socket message callback failed"); + Logger.d(TAG, "socket message callback failed"); } @Override protected void onSuccess(BaseResp o) { super.onSuccess(o); - Logger.d(TAG,"socket message callback succeeded"); + Logger.d(TAG, "socket message callback succeeded"); } @Override protected void onNetworkLost() { super.onNetworkLost(); - Logger.d(TAG,"request socket message callback, network is not available."); + Logger.d(TAG, "request socket message callback, network is not available."); } }); } @@ -76,8 +78,13 @@ public class RequestManager { .append("versionName", CommonUtils.getVersionName(SocketConfig.instance().getAppContext())) .build(); - ServiceFactory.newTechApiService().requestSocketAddress(params) - .compose(NetworkSdkUtils.transformer()) + Observable observable; + if (MoGoAiCloudClientConfig.getInstance().isUseOriginSocket()) { + observable = ServiceFactory.newTechOriginApiService().requestSocketAddress(params); + } else { + observable = ServiceFactory.newTechApiService().requestSocketAddress(params); + } + observable.compose(NetworkSdkUtils.transformer()) .subscribe(new DefSubscriberImpl(RequestOptions.of(context)) { @Override protected void onSuccess(SocketAddressData o) { @@ -110,6 +117,7 @@ public class RequestManager { public interface SocketAddressCallback { void onGetSocketAddressSuccess(SocketAddressData data); + void onGetSocketAddressFailed(int code, String msg); } } diff --git a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/ServiceFactory.java b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/ServiceFactory.java index 48af8b1..7b5a6d8 100644 --- a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/ServiceFactory.java +++ b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/ServiceFactory.java @@ -18,6 +18,10 @@ public class ServiceFactory extends SimpleServiceFactory { return newService(getTechUrl(), TechApiService.class); } + public static synchronized TechOriginApiService newTechOriginApiService() { + return newService(getTechOriginUrl(), TechOriginApiService.class); + } + private static String getTechUrl(){ final Environment environment = SocketConfig.instance().getEnvironment(); @@ -30,6 +34,18 @@ public class ServiceFactory extends SimpleServiceFactory { } } + private static String getTechOriginUrl(){ + final Environment environment = SocketConfig.instance().getEnvironment(); + + if(environment == Environment.release){ + return "http://tech.zhidaohulian.com/"; + }else if(environment == Environment.qa){ + return "http://tech-qa.zhidaohulian.com/"; + }else{ + return "http://tech-dev.zhidaohulian.com/"; + } + } + private static String getUrl(){ final Environment environment = SocketConfig.instance().getEnvironment(); diff --git a/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/TechOriginApiService.java b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/TechOriginApiService.java new file mode 100644 index 0000000..6cf01eb --- /dev/null +++ b/foudations/mogo-socket/src/main/java/com/mogo/cloud/socket/third/core/network/TechOriginApiService.java @@ -0,0 +1,15 @@ +package com.mogo.cloud.socket.third.core.network; + + +import com.mogo.cloud.socket.third.core.network.model.SocketAddressData; + +import java.util.Map; + +import retrofit2.http.GET; +import retrofit2.http.QueryMap; +import rx.Observable; + +public interface TechOriginApiService { + @GET("/alloc/connsvrAddr") + Observable requestSocketAddress(@QueryMap Map params); +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 14c3849..b8ec00b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,7 +33,7 @@ SNAPSHOT_REPOSITORY_URL=http://nexus.zhidaoauto.com/repository/maven-snapshots/ USERNAME=xintai PASSWORD=xintai2018 # 编译模式: false - 依赖本地版本, true - 依赖 maven 版本 -RELEASE=true +RELEASE=false # AI CLOUD 云平台 # 工具类 MOGO_UTILS_VERSION=1.2.3