com.taptap.sdk.core 4.5.2 → 4.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,12 +4,12 @@
4
4
  <repositories>
5
5
  <repository>https://repo.maven.apache.org/maven2</repository>
6
6
  </repositories>
7
- <androidPackage spec="com.taptap.sdk:tap-core-unity:4.5.2"/>
7
+ <androidPackage spec="com.taptap.sdk:tap-core-unity:4.5.4"/>
8
8
  </androidPackages>
9
9
  <iosPods>
10
10
  <sources>
11
11
  <source>https://github.com/CocoaPods/Specs.git</source>
12
12
  </sources>
13
- <iosPod name="TapTapCoreSDK" version="~> 4.5.2" bitcodeEnabled="false" addToAllTargets="false"/>
13
+ <iosPod name="TapTapCoreSDK" version="~> 4.5.4" bitcodeEnabled="false" addToAllTargets="false"/>
14
14
  </iosPods>
15
15
  </dependencies>
@@ -9,8 +9,7 @@ using UnityEngine.Networking;
9
9
 
10
10
  namespace TapSDK.Core.Internal.Utils {
11
11
  public class ImageUtils {
12
- private readonly static string CacheDirName = "tap-cache";
13
-
12
+ private readonly static string OldCacheDirName = "tap-cache";
14
13
  private readonly static MD5 md5 = MD5.Create();
15
14
 
16
15
  private readonly static Dictionary<string, WeakReference<Texture>> cachedTextures = new Dictionary<string, WeakReference<Texture>>();
@@ -136,11 +135,22 @@ namespace TapSDK.Core.Internal.Utils {
136
135
 
137
136
  static string CacheDirPath {
138
137
  get {
139
- string path = Path.Combine(Application.persistentDataPath, CacheDirName);
140
- if (!Directory.Exists(path)) {
141
- Directory.CreateDirectory(path);
138
+
139
+ string newCacheDirPath = Path.Combine(Application.persistentDataPath, OldCacheDirName);
140
+ if (TapTapSDK.taptapSdkOptions != null && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId) ){
141
+ newCacheDirPath = Path.Combine(Application.persistentDataPath, OldCacheDirName + "_" + TapTapSDK.taptapSdkOptions.clientId);
142
+ }
143
+ if(!Directory.Exists(newCacheDirPath)) {
144
+ string oldPath = Path.Combine(Application.persistentDataPath, OldCacheDirName);
145
+ if (Directory.Exists(oldPath)) {
146
+ Directory.Move(oldPath, newCacheDirPath);
147
+ }
148
+ }
149
+
150
+ if (!Directory.Exists(newCacheDirPath)) {
151
+ Directory.CreateDirectory(newCacheDirPath);
142
152
  }
143
- return path;
153
+ return newCacheDirPath;
144
154
  }
145
155
  }
146
156
  }
@@ -14,21 +14,32 @@ namespace TapSDK.Core
14
14
  private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
15
15
  public static void SaveString(string key, string value)
16
16
  {
17
- SaveStringToCache(key, value);
18
- PlayerPrefs.SetString(key, EncodeString(value));
17
+ string storageKey = GenerateStorageKey(key);
18
+ SaveStringToCache(storageKey, value);
19
+ PlayerPrefs.SetString(storageKey, EncodeString(value));
19
20
  }
20
21
 
21
22
  public static string LoadString(string key)
22
23
  {
23
- string value = LoadStringFromCache(key);
24
+ string storageKey = GenerateStorageKey(key);
25
+ string value = LoadStringFromCache(storageKey);
24
26
  if (!string.IsNullOrEmpty(value))
25
27
  {
26
28
  return value;
27
29
  }
28
- value = PlayerPrefs.HasKey(key) ? DecodeString(PlayerPrefs.GetString(key)) : null;
30
+ value = PlayerPrefs.HasKey(storageKey) ? DecodeString(PlayerPrefs.GetString(storageKey)) : null;
31
+ // 尝试从本地获取旧版本数据
32
+ if (value == null){
33
+ value = PlayerPrefs.HasKey(key) ? DecodeString(PlayerPrefs.GetString(key)) : null;
34
+ // 旧版本存在有效数据时,转储为新的 storageKey
35
+ if (value != null) {
36
+ PlayerPrefs.SetString(storageKey, EncodeString(value));
37
+ PlayerPrefs.DeleteKey(key);
38
+ }
39
+ }
29
40
  if (value != null)
30
41
  {
31
- SaveStringToCache(key, value);
42
+ SaveStringToCache(storageKey, value);
32
43
  }
33
44
  return value;
34
45
  }
@@ -137,5 +148,13 @@ namespace TapSDK.Core
137
148
  }
138
149
  return physicalAddress;
139
150
  }
151
+
152
+ // 生成存储在本地文件中 key
153
+ private static string GenerateStorageKey(string originKey){
154
+ if(TapTapSDK.taptapSdkOptions != null && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId)){
155
+ return originKey + "_" + TapTapSDK.taptapSdkOptions.clientId;
156
+ }
157
+ return originKey;
158
+ }
140
159
  }
141
160
  }
@@ -12,7 +12,7 @@ using System.ComponentModel;
12
12
 
13
13
  namespace TapSDK.Core {
14
14
  public class TapTapSDK {
15
- public static readonly string Version = "4.5.2";
15
+ public static readonly string Version = "4.5.4";
16
16
 
17
17
  public static string SDKPlatform = "TapSDK-Unity";
18
18
 
@@ -13,7 +13,7 @@ namespace TapSDK.Core.Standalone.Internal {
13
13
  public readonly static string DEVICE_LOGIN = "device_login";
14
14
  public readonly static string USER_LOGIN = "user_login";
15
15
 
16
- internal static string ClientSettingsFileName = "TapSDKClientSettings.json";
16
+ internal static string ClientSettingsFileName = "TapSDKClientSettings";
17
17
  internal static string ClientSettingsEventKey = "ClientSettingsEventKey";
18
18
  }
19
19
 
@@ -16,7 +16,7 @@ namespace TapSDK.Core.Standalone.Internal
16
16
  {
17
17
  public class EventSender
18
18
  {
19
- private const string EventFilePath = "events.json";
19
+ private const string OldEventFilePath = "events.json";
20
20
 
21
21
  private readonly TapLog log = new TapLog("TapEvent");
22
22
  private string persistentDataPath = Application.persistentDataPath;
@@ -131,9 +131,25 @@ namespace TapSDK.Core.Standalone.Internal
131
131
  timer.Change(TimeSpan.FromSeconds(SendInterval), TimeSpan.FromSeconds(SendInterval));
132
132
  }
133
133
 
134
+ private string GetEventCacheFileName(){
135
+ if (TapTapSDK.taptapSdkOptions != null
136
+ && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId)){
137
+ return "events_" + TapTapSDK.taptapSdkOptions.clientId + ".json";
138
+ }
139
+ return OldEventFilePath;
140
+ }
141
+
134
142
  private void LoadEvents()
135
- {
136
- string filePath = Path.Combine(persistentDataPath, EventFilePath);
143
+ {
144
+ string filePath = Path.Combine(persistentDataPath, GetEventCacheFileName());
145
+ if(!File.Exists(filePath)){
146
+ string oldFilePath = Path.Combine(persistentDataPath, OldEventFilePath);
147
+ // 兼容旧版本文件
148
+ if (File.Exists(oldFilePath)) {
149
+ File.Move(oldFilePath, filePath);
150
+ }
151
+ }
152
+
137
153
  if (File.Exists(filePath))
138
154
  {
139
155
  string jsonData = File.ReadAllText(filePath);
@@ -165,13 +181,13 @@ namespace TapSDK.Core.Standalone.Internal
165
181
  var eventList = eventQueue.ToList();
166
182
  string jsonData = Json.Serialize(eventList);
167
183
 
168
- if (string.IsNullOrEmpty(EventFilePath))
184
+ if (string.IsNullOrEmpty(GetEventCacheFileName()))
169
185
  {
170
186
  Debug.LogError("EventFilePath is null or empty");
171
187
  return;
172
188
  }
173
189
 
174
- string filePath = Path.Combine(persistentDataPath, EventFilePath);
190
+ string filePath = Path.Combine(persistentDataPath, GetEventCacheFileName());
175
191
 
176
192
  if (string.IsNullOrEmpty(filePath))
177
193
  {
@@ -4,7 +4,9 @@ namespace TapSDK.Core.Standalone.Internal.Http
4
4
  {
5
5
  using System;
6
6
  using System.Collections.Generic;
7
+ using System.Linq;
7
8
  using System.Net.Http.Headers;
9
+ using System.Net.NetworkInformation;
8
10
  using System.Text;
9
11
  using System.Threading.Tasks;
10
12
  using Newtonsoft.Json;
@@ -24,7 +26,10 @@ namespace TapSDK.Core.Standalone.Internal.Http
24
26
  public static readonly string HOST_CN = "https://tapsdk.tapapis.cn";
25
27
  public static readonly string HOST_IO = "https://tapsdk.tapapis.com";
26
28
 
27
- private static HttpClient client = new HttpClient();
29
+ private static HttpClient client = new HttpClient{
30
+ // 默认超时 10 秒
31
+ Timeout = TimeSpan.FromMilliseconds(CONNECT_TIMEOUT_MILLIS)
32
+ };
28
33
 
29
34
  private readonly TapHttpConfig httpConfig;
30
35
 
@@ -242,6 +247,11 @@ namespace TapSDK.Core.Standalone.Internal.Http
242
247
  object body = null
243
248
  )
244
249
  {
250
+ if(!CheckNetworkConnection()){
251
+ return TapHttpResult<T>.NetworkError(new TapHttpNetworkErrorException("network error"));
252
+ }else{
253
+ TapLog.Log("current network is connected");
254
+ }
245
255
  // 处理查询参数
246
256
  Dictionary<string, string> allQueryParams = new Dictionary<string, string>();
247
257
  if (queryParams != null)
@@ -379,5 +389,49 @@ namespace TapSDK.Core.Standalone.Internal.Http
379
389
  return TapHttpResult<T>.UnknownFailure(new TapHttpUnknownException(ex));
380
390
  }
381
391
  }
392
+
393
+ // 判断网络连接状态
394
+ private bool CheckNetworkConnection(){
395
+ try {
396
+ var networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
397
+
398
+ foreach (var netInterface in networkInterfaces)
399
+ {
400
+ // 忽略虚拟网卡
401
+ if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Loopback ||
402
+ netInterface.NetworkInterfaceType == NetworkInterfaceType.Tunnel)
403
+ {
404
+ continue;
405
+ }
406
+
407
+ // 检查是否有网络连接
408
+ if (netInterface.OperationalStatus == OperationalStatus.Up)
409
+ {
410
+ // 检查是否有有效的 IPv4 地址
411
+ var ipProperties = netInterface.GetIPProperties();
412
+ var ipv4Address = ipProperties.UnicastAddresses.FirstOrDefault(ip => ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
413
+
414
+ if (ipv4Address != null)
415
+ {
416
+ // 有有效的 IP 地址,则说明已连接到网络
417
+ if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
418
+ {
419
+ return true; // 有线连接
420
+ }
421
+ else if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211)
422
+ {
423
+ return true; // 无线连接
424
+ }
425
+ }
426
+ }
427
+ }
428
+
429
+ return false; // 无连接
430
+ }catch(Exception e){
431
+ TapLog.Log("checkout network connected error = " + e);
432
+ // 发生异常时,当做有网处理
433
+ return true;
434
+ }
435
+ }
382
436
  }
383
437
  }
@@ -21,6 +21,14 @@ namespace TapSDK.Core.Standalone.Internal.Http
21
21
  }
22
22
  }
23
23
 
24
+ public class TapHttpNetworkErrorException : AbsTapHttpException
25
+ {
26
+ public TapHttpNetworkErrorException(string msg) : base("network error")
27
+ {
28
+
29
+ }
30
+ }
31
+
24
32
  public class TapHttpInvalidResponseException : AbsTapHttpException
25
33
  {
26
34
  public HttpStatusCode StatusCode { get; }
@@ -84,6 +84,10 @@ namespace TapSDK.Core.Standalone.Internal.Http
84
84
  try
85
85
  {
86
86
  httpResponse = JsonConvert.DeserializeObject<TapHttpResponse>(content);
87
+ // 设置当前服务端返回的事件戳
88
+ if (httpResponse.Now > 0){
89
+ TapHttpTime.ResetLastServerTime(httpResponse.Now);
90
+ }
87
91
  }
88
92
  catch (Exception)
89
93
  {
@@ -119,12 +123,12 @@ namespace TapSDK.Core.Standalone.Internal.Http
119
123
  }
120
124
  else
121
125
  {
122
- TapHttpErrorData httpErrorData = httpResponse.Data.ToObject<TapHttpErrorData>();
126
+ TapHttpErrorData httpErrorData = httpResponse.Data?.ToObject<TapHttpErrorData>();
123
127
  if (httpErrorData == null)
124
128
  {
125
129
  return TapHttpResult<T>.InvalidResponseFailure(new TapHttpInvalidResponseException(statusCode, "TapHttpErrorData is null"));
126
130
  }
127
- return TapHttpResult<T>.ServerFailure(new TapHttpServerException((HttpStatusCode)500, httpResponse, httpErrorData));
131
+ return TapHttpResult<T>.ServerFailure(new TapHttpServerException((HttpStatusCode)statusCode, httpResponse, httpErrorData));
128
132
  }
129
133
  }
130
134
  }
@@ -86,5 +86,14 @@ namespace TapSDK.Core.Standalone.Internal.Http
86
86
  };
87
87
  }
88
88
 
89
+ public static TapHttpResult<T> NetworkError(TapHttpNetworkErrorException httpException)
90
+ {
91
+ return new TapHttpResult<T>
92
+ {
93
+ IsSuccess = false,
94
+ HttpException = httpException,
95
+ };
96
+ }
97
+
89
98
  }
90
99
  }
@@ -32,6 +32,28 @@ namespace TapSDK.Core.Standalone.Internal.Http
32
32
  }
33
33
  SetTimeOffset(time - (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
34
34
  }
35
+
36
+
37
+ // 服务端同步的时间戳
38
+ private static long LastServerTime = 0;
39
+ // 设置服务端时间时,当前应用启动时间
40
+ private static long LastStartUpTime = 0 ;
41
+ internal static void ResetLastServerTime(long time){
42
+ LastServerTime = time;
43
+ LastStartUpTime = (long) Time.realtimeSinceStartup;
44
+ }
45
+
46
+ /// <summary>
47
+ /// 根据服务端时间获取当前时间戳,单位:秒
48
+ /// </summary>
49
+ /// <returns>当前时间戳,当服务端时间未设置过时,返回值为 0</returns>
50
+ public static long GetCurrentServerTime(){
51
+ if(LastServerTime == 0){
52
+ return 0;
53
+ }
54
+ long startUpTime = (long) Time.realtimeSinceStartup;
55
+ return LastServerTime + startUpTime - LastStartUpTime;
56
+ }
35
57
  }
36
58
 
37
59
  public static class TapHttpUtils
@@ -161,7 +183,7 @@ namespace TapSDK.Core.Standalone.Internal.Http
161
183
  StringBuilder sb = new StringBuilder();
162
184
  sb.AppendLine("=== HTTP Response Start ===");
163
185
  sb.AppendLine($"URL: {response.RequestMessage.RequestUri}");
164
- sb.AppendLine($"Status Code: {response.StatusCode}");
186
+ sb.AppendLine($"Status Code: {response.StatusCode}");
165
187
  string contentString = null;
166
188
  try
167
189
  {
@@ -142,7 +142,17 @@ namespace TapSDK.Core.Standalone.Internal.Openlog
142
142
  }
143
143
  openlogStartParameter[TapOpenlogStartParamConstants.PARAM_LOG_TO_CONSOLE] = 1;
144
144
  openlogStartParameter[TapOpenlogStartParamConstants.PARAM_LOG_LEVEL] = 1;
145
- openlogStartParameter[TapOpenlogStartParamConstants.PARAM_DATA_DIR] = Path.Combine(Application.persistentDataPath, "OpenlogData");
145
+ string openLogDirPath = Path.Combine(Application.persistentDataPath, "OpenlogData");
146
+ if (TapTapSDK.taptapSdkOptions != null && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId)){
147
+ openLogDirPath = Path.Combine(Application.persistentDataPath, "OpenlogData_" + TapTapSDK.taptapSdkOptions.clientId);
148
+ if( !Directory.Exists(openLogDirPath)){
149
+ string oldPath = Path.Combine(Application.persistentDataPath, "OpenlogData");
150
+ if(Directory.Exists(oldPath)){
151
+ Directory.Move(oldPath, openLogDirPath);
152
+ }
153
+ }
154
+ }
155
+ openlogStartParameter[TapOpenlogStartParamConstants.PARAM_DATA_DIR] = openLogDirPath;
146
156
  openlogStartParameter[TapOpenlogStartParamConstants.PARAM_ENV] = "local";
147
157
  openlogStartParameter[TapOpenlogStartParamConstants.PARAM_PLATFORM] = "PC";
148
158
  openlogStartParameter[TapOpenlogStartParamConstants.PARAM_UA] = TapHttpUtils.GenerateUserAgent();
@@ -9,7 +9,7 @@ using TapSDK.Core;
9
9
 
10
10
  namespace TapSDK.Core.Standalone.Internal {
11
11
  public class Prefs {
12
- internal static readonly string PERSISTENT_FILE_NAME = "tapdb_storage_v2";
12
+ internal static readonly string OLD_PERSISTENT_FILE_NAME = "tapdb_storage_v2";
13
13
 
14
14
  private string persistentFilePath;
15
15
 
@@ -20,12 +20,23 @@ namespace TapSDK.Core.Standalone.Internal {
20
20
  private readonly AutoResetEvent persistEvent;
21
21
 
22
22
  public Prefs() {
23
- persistentFilePath = Path.Combine(Application.persistentDataPath, PERSISTENT_FILE_NAME);
23
+ string newCacheFileName = OLD_PERSISTENT_FILE_NAME;
24
+ if( TapTapSDK.taptapSdkOptions != null && !string.IsNullOrEmpty(TapTapSDK.taptapSdkOptions.clientId)) {
25
+ newCacheFileName = OLD_PERSISTENT_FILE_NAME + "_" + TapTapSDK.taptapSdkOptions.clientId;
26
+ }
27
+ persistentFilePath = Path.Combine(Application.persistentDataPath, newCacheFileName);
28
+ // 兼容旧版缓存文件
29
+ if( !File.Exists(persistentFilePath)) {
30
+ string oldPath = Path.Combine(Application.persistentDataPath, OLD_PERSISTENT_FILE_NAME);
31
+ if (File.Exists(oldPath)){
32
+ File.Move(oldPath, persistentFilePath);
33
+ }
34
+ }
24
35
  if (File.Exists(persistentFilePath)) {
25
36
  try {
26
37
  string json = File.ReadAllText(persistentFilePath);
27
38
  Dictionary<string, object> jsonData = Json.Deserialize(json) as Dictionary<string, object>;
28
- ConcurrentDictionary<string, object> data = new ConcurrentDictionary<string, object>(jsonData);
39
+ data = new ConcurrentDictionary<string, object>(jsonData);
29
40
  } catch (Exception e) {
30
41
  TapLogger.Error(e.Message);
31
42
  File.Delete(persistentFilePath);
@@ -37,7 +37,7 @@ namespace TapSDK.Core.Standalone
37
37
  public TapCoreStandalone()
38
38
  {
39
39
  // Instantiate modules
40
- Prefs = new Prefs();
40
+
41
41
  Tracker = new Tracker();
42
42
  User = new User();
43
43
  TapLoom.Initialize();
@@ -69,10 +69,19 @@ namespace TapSDK.Core.Standalone
69
69
  }
70
70
  TapLog.Log("SDK Init Options : ", "coreOption : " + JsonConvert.SerializeObject(coreOption) + "\notherOptions : " + JsonConvert.SerializeObject(otherOptions));
71
71
  coreOptions = coreOption;
72
-
72
+ if (Prefs == null) {
73
+ Prefs = new Prefs();
74
+ }
73
75
  TapOpenlogStandalone.Init();
74
76
 
75
- var path = Path.Combine(Application.persistentDataPath, Constants.ClientSettingsFileName);
77
+ var path = Path.Combine(Application.persistentDataPath, Constants.ClientSettingsFileName + "_" + coreOption.clientId + ".json");
78
+ // 兼容旧版文件
79
+ if (!File.Exists(path)) {
80
+ var oldPath = Path.Combine(Application.persistentDataPath, Constants.ClientSettingsFileName + ".json");
81
+ if(File.Exists(oldPath)){
82
+ File.Move(oldPath, path);
83
+ }
84
+ }
76
85
  if (File.Exists(path))
77
86
  {
78
87
  var clientSettings = File.ReadAllText(path);
@@ -182,7 +191,7 @@ namespace TapSDK.Core.Standalone
182
191
  private void saveClientSettings(TapGatekeeper settings)
183
192
  {
184
193
  string json = JsonConvert.SerializeObject(settings);
185
- File.WriteAllText(Path.Combine(Application.persistentDataPath, Constants.ClientSettingsFileName), json);
194
+ File.WriteAllText(Path.Combine(Application.persistentDataPath, Constants.ClientSettingsFileName + "_" + TapTapSDK.taptapSdkOptions.clientId + ".json"), json);
186
195
  }
187
196
 
188
197
  private void SetAutoEvent(TapGatekeeper gatekeeper)
@@ -217,6 +226,7 @@ namespace TapSDK.Core.Standalone
217
226
  public static string GetCurrentUserId(){
218
227
  return User?.Id;
219
228
  }
229
+
220
230
  }
221
231
 
222
232
  public interface IOpenIDProvider
package/link.xml ADDED
@@ -0,0 +1,4 @@
1
+ <linker>
2
+ <assembly fullname="TapSDK.Core.Runtime" preserve="all" />
3
+ <assembly fullname="TapSDK.Core.Mobile.Runtime" preserve="all" />
4
+ </linker>
package/link.xml.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 5777dc227a00a4ed9a0fb312ee3630e7
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "com.taptap.sdk.core",
3
3
  "displayName": "TapTapSDK Core",
4
4
  "description": "TapTapSDK Core",
5
- "version": "4.5.2",
5
+ "version": "4.5.4",
6
6
  "unity": "2019.4",
7
7
  "license": "MIT",
8
8
  "dependencies": {