From 906aae5997e3564728efb0141444a71351d5bc1a Mon Sep 17 00:00:00 2001
From: wp-byte <83280126+wp-byte@users.noreply.github.com>
Date: Wed, 19 May 2021 15:32:34 +0800
Subject: [PATCH] feat: dynamic domain (#17)
* fix: url parse bug
* fix: change comments
* feat: change version
* feat: api change
* fix: change detail
* fix: add comment
* fix: change domain
* fix: no test header
* fix: chang default domain
---
.../src/main/java/com/tiktok/TikTokBusinessSdk.java | 12 ++++++++++++
.../java/com/tiktok/appevents/TTAppEventLogger.java | 2 ++
.../main/java/com/tiktok/appevents/TTRequest.java | 9 ++++-----
gradle.properties | 2 +-
samples/.settings/org.eclipse.buildship.core.prefs | 2 --
.../.settings/org.eclipse.buildship.core.prefs | 2 --
samples/internalmonitor/build.gradle | 2 +-
7 files changed, 20 insertions(+), 11 deletions(-)
delete mode 100644 samples/.settings/org.eclipse.buildship.core.prefs
delete mode 100644 samples/TestApp/.settings/org.eclipse.buildship.core.prefs
diff --git a/business-core/src/main/java/com/tiktok/TikTokBusinessSdk.java b/business-core/src/main/java/com/tiktok/TikTokBusinessSdk.java
index efcebf8..78c4048 100644
--- a/business-core/src/main/java/com/tiktok/TikTokBusinessSdk.java
+++ b/business-core/src/main/java/com/tiktok/TikTokBusinessSdk.java
@@ -53,6 +53,10 @@ public class TikTokBusinessSdk {
* api available version
*/
private static String apiAvailableVersion = "v1.1";
+ /**
+ * api treckEvent sent Domain
+ */
+ private static String apiTrackDomain = "business-api.tiktok.com";
/**
* {@link LogLevel} of initialized sdk
*/
@@ -435,6 +439,14 @@ public static void setApiAvailableVersion(String apiAvailableVersion) {
TikTokBusinessSdk.apiAvailableVersion = apiAvailableVersion;
}
+ public static String getApiTrackDomain() {
+ return apiTrackDomain;
+ }
+
+ public static void setApiTrackDomain(String apiTrackDomain) {
+ TikTokBusinessSdk.apiTrackDomain = apiTrackDomain;
+ }
+
/**
* Should be called whenever the user info changes
* - when the user logins in
diff --git a/business-core/src/main/java/com/tiktok/appevents/TTAppEventLogger.java b/business-core/src/main/java/com/tiktok/appevents/TTAppEventLogger.java
index bc13fca..ca26728 100644
--- a/business-core/src/main/java/com/tiktok/appevents/TTAppEventLogger.java
+++ b/business-core/src/main/java/com/tiktok/appevents/TTAppEventLogger.java
@@ -361,6 +361,7 @@ public void fetchGlobalConfig(int delaySeconds) {
JSONObject businessSdkConfig = (JSONObject) requestResult.get("business_sdk_config");
Boolean enableSDK = (Boolean) businessSdkConfig.get("enable_sdk");
String availableVersion = (String) businessSdkConfig.get("available_version");
+ String trackEventDomain = (String) businessSdkConfig.get("domain");
TikTokBusinessSdk.setSdkGlobalSwitch(enableSDK);
logger.debug("enable_sdk=" + enableSDK);
@@ -370,6 +371,7 @@ public void fetchGlobalConfig(int delaySeconds) {
clearAllImmediately();
}
TikTokBusinessSdk.setApiAvailableVersion(availableVersion);
+ TikTokBusinessSdk.setApiTrackDomain(trackEventDomain);
logger.debug("available_version=" + availableVersion);
TikTokBusinessSdk.setGlobalConfigFetched();
} catch (JSONException e) {
diff --git a/business-core/src/main/java/com/tiktok/appevents/TTRequest.java b/business-core/src/main/java/com/tiktok/appevents/TTRequest.java
index 551f5dc..35b9c25 100644
--- a/business-core/src/main/java/com/tiktok/appevents/TTRequest.java
+++ b/business-core/src/main/java/com/tiktok/appevents/TTRequest.java
@@ -50,7 +50,7 @@ class TTRequest {
headParamMap.put("Content-Type", "application/json");
headParamMap.put("Connection", "Keep-Alive");
// headParamMap.put("X-USE-PPE", "1");
-// headParamMap.put("X-TT-ENV", "ppe_opensite_i18n_m");
+// headParamMap.put("X-TT-ENV", "ppe_bofang");
String ua = String.format("tiktok-business-android-sdk/%s/%s",
BuildConfig.VERSION_NAME,
@@ -75,7 +75,7 @@ public static JSONObject getBusinessSDKConfig(Map options) {
paramsMap.put("tiktok_app_id", TikTokBusinessSdk.getTTAppId());
paramsMap.putAll(options);
- String url = "https://ads.tiktok.com/open_api/business_sdk_config/get/?" + TTUtil.mapToString(paramsMap, "&");
+ String url = "https://business-api.tiktok.com/open_api/business_sdk_config/get/?" + TTUtil.mapToString(paramsMap, "&");
logger.debug(url);
String result = HttpRequestUtil.doGet(url, getHeadParamMap);
logger.debug(result);
@@ -128,9 +128,8 @@ public static synchronized List reportAppEvent(JSONObject basePayloa
failedRequests = 0;
successfulRequests = 0;
notifyChange();
-
- String url = "https://ads.tiktok.com/open_api/" + TikTokBusinessSdk.getApiAvailableVersion() + "/app/batch/";
-// String url = "http://10.231.253.20:6789/open_api/" + TikTokBusinessSdk.getApiAvailableVersion() + "/app/batch/";
+ // dynamic req domain and version
+ String url = "https://" + TikTokBusinessSdk.getApiTrackDomain() + "/open_api/" + TikTokBusinessSdk.getApiAvailableVersion() + "/app/batch/";
List failedEventsToBeSaved = new ArrayList<>();
List failedEventsToBeDiscarded = new ArrayList<>();
diff --git a/gradle.properties b/gradle.properties
index 3485c49..fb1ce75 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -11,7 +11,7 @@ android.enableJetifier=true
GROUP=com.tiktok
-VERSION_NAME=1.2.3
+VERSION_NAME=1.2.4
mavenGroupId = com.tiktok
mavenArtifactId = tiktok-business-android-sdk
diff --git a/samples/.settings/org.eclipse.buildship.core.prefs b/samples/.settings/org.eclipse.buildship.core.prefs
deleted file mode 100644
index b1886ad..0000000
--- a/samples/.settings/org.eclipse.buildship.core.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-connection.project.dir=..
-eclipse.preferences.version=1
diff --git a/samples/TestApp/.settings/org.eclipse.buildship.core.prefs b/samples/TestApp/.settings/org.eclipse.buildship.core.prefs
deleted file mode 100644
index 62e3e7e..0000000
--- a/samples/TestApp/.settings/org.eclipse.buildship.core.prefs
+++ /dev/null
@@ -1,2 +0,0 @@
-connection.project.dir=../..
-eclipse.preferences.version=1
diff --git a/samples/internalmonitor/build.gradle b/samples/internalmonitor/build.gradle
index effbae7..3eb55c0 100644
--- a/samples/internalmonitor/build.gradle
+++ b/samples/internalmonitor/build.gradle
@@ -41,7 +41,7 @@ dependencies {
implementation project(':business-core')
// implementation 'com.tiktok:tiktok-business-android-sdk:1.1.0-alpha.2'
-// implementation 'com.github.bytedance:tiktok-business-android-sdk:1.2.3'
+ //implementation 'com.github.bytedance:tiktok-business-android-sdk:1.2.4'
implementation 'androidx.cardview:cardview:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'