com.taptap.sdk.core 4.5.2 → 4.5.3
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.
- package/Mobile/Editor/NativeDependencies.xml +2 -2
- package/Runtime/Public/TapTapSDK.cs +1 -1
- package/Standalone/Plugins/x86/tapsdkcore.dll +0 -0
- package/Standalone/Plugins/x86_64/tapsdkcore.dll +0 -0
- package/Standalone/Runtime/Internal/Http/TapHttp.cs +55 -1
- package/Standalone/Runtime/Internal/Http/TapHttpException.cs +8 -0
- package/Standalone/Runtime/Internal/Http/TapHttpParser.cs +6 -2
- package/Standalone/Runtime/Internal/Http/TapHttpResult.cs +9 -0
- package/Standalone/Runtime/Internal/Http/TapHttpUtils.cs +23 -1
- package/Standalone/Runtime/Public/TapCoreStandalone.cs +1 -0
- package/link.xml +4 -0
- package/link.xml.meta +7 -0
- package/package.json +1 -1
|
@@ -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.
|
|
7
|
+
<androidPackage spec="com.taptap.sdk:tap-core-unity:4.5.3"/>
|
|
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.
|
|
13
|
+
<iosPod name="TapTapCoreSDK" version="~> 4.5.3" bitcodeEnabled="false" addToAllTargets="false"/>
|
|
14
14
|
</iosPods>
|
|
15
15
|
</dependencies>
|
|
Binary file
|
|
Binary file
|
|
@@ -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
|
|
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)
|
|
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
|
{
|
package/link.xml
ADDED
package/link.xml.meta
ADDED