com.xd.sdk.account 7.7.3 → 7.8.0

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.
@@ -11,9 +11,7 @@ namespace XD.SDK.Account.Editor
11
11
  var sdkVersion = VersionCatalog.XDAndroidSdkVersion;
12
12
  var result = new List<AndroidGradleProjectConfig.Dependency>
13
13
  {
14
- new AndroidGradleProjectConfig.Dependency(group: "com.xd.sdk.android", module: "account-bridge",
15
- version: sdkVersion),
16
- new AndroidGradleProjectConfig.Dependency(group: "com.xd.sdk.android", module: "support",
14
+ new AndroidGradleProjectConfig.Dependency(group: "com.xd.sdk.android", module: "account",
17
15
  version: sdkVersion),
18
16
  };
19
17
 
@@ -4,6 +4,6 @@
4
4
  //
5
5
  // Created by Fattycat on 2023/4/14.
6
6
  //
7
- #define XDGAccount_VERSION @"7.7.3"
8
- #define XDSAccount_VERSION_CODE @"7070300"
9
- // HASH 18c75b8c
7
+ #define XDGAccount_VERSION @"7.8.0"
8
+ #define XDSAccount_VERSION_CODE @"7080000"
9
+ // HASH 0094cc326
@@ -23,6 +23,8 @@ namespace XD.SDK.Account.Internal.Standalone
23
23
  private static AccountFeaturesImpl _instance;
24
24
 
25
25
  private static readonly object LockObj = new object();
26
+ private const string GlobalComplianceLogout = "GLOBAL_COMPLIANCE_LOGOUT";
27
+ private const string GlobalComplianceExit = "GLOBAL_COMPLIANCE_EXIT";
26
28
 
27
29
  public static AccountFeaturesImpl Instance
28
30
  {
@@ -248,15 +250,12 @@ namespace XD.SDK.Account.Internal.Standalone
248
250
 
249
251
  // 登录埋点
250
252
  AliyunTrack.LoginStart(loginType.ToString());
253
+ XDCompliance.LogoutHandler = needNotify => InternalLogout(GlobalComplianceExit, needNotify);
251
254
  try
252
255
  {
253
256
  var user = await UserModule.Login(loginType);
254
257
  AliyunTrack.LoginAntiAddictionStartup();
255
258
  var complianceResult = await XDGEventBus.PublishAsync<Dictionary<string, object>>(XDGEvents.TapSDKComplianceStartup, ConfigModule.IsGlobal, user.UserId);
256
- // TODO 统一走回调进行埋点
257
- // AliyunTrack.LoginAntiAddictionResult(XDDictionary.GetValue(complianceResult, "code", -100),
258
- // XDDictionary.GetValue<string>(complianceResult, "reason"),
259
- // XDDictionary.GetValue<string>(complianceResult, "extras"));
260
259
  var compliance = complianceResult.GetValueOrDefault();
261
260
  if (XDDictionary.GetValue<bool>(compliance, "success"))
262
261
  {
@@ -270,7 +269,11 @@ namespace XD.SDK.Account.Internal.Standalone
270
269
  }
271
270
  catch (XDHttpException e)
272
271
  {
273
- if ((e.HttpStatusCode == 401 && loginType == LoginType.Default) || e.Code == 40311 || e.Code == 40312)
272
+ if (XDCompliance.IsRequired(e))
273
+ {
274
+ InternalLogout(GlobalComplianceLogout, false);
275
+ }
276
+ else if ((e.HttpStatusCode == 401 && loginType == LoginType.Default) || e.Code == 40311 || e.Code == 40312)
274
277
  {
275
278
  InternalLogout("LOGOUT_API", false);
276
279
  }
@@ -281,6 +284,18 @@ namespace XD.SDK.Account.Internal.Standalone
281
284
  AliyunTrack.LoginFail(errorMsg);
282
285
  throw;
283
286
  }
287
+ catch (XDComplianceException e)
288
+ {
289
+ var originalException = e.OriginalException;
290
+ AliyunTrack.LoginFail(originalException?.Message ?? e.ErrorMsg);
291
+ InternalLogout(GlobalComplianceLogout, false);
292
+ if (originalException != null)
293
+ {
294
+ throw originalException;
295
+ }
296
+
297
+ throw;
298
+ }
284
299
  catch (Exception e)
285
300
  {
286
301
  if (e is XDGError error)
@@ -302,16 +317,26 @@ namespace XD.SDK.Account.Internal.Standalone
302
317
  // SDK 登陆成功
303
318
  AliyunTrack.LoginLogout(logoutType);
304
319
 
305
- ClearUserCache();
320
+ var preserveAgreement = logoutType == GlobalComplianceLogout
321
+ || logoutType == GlobalComplianceExit;
322
+ ClearUserCache(preserveAgreement);
306
323
 
307
324
  XDGEventBus.Publish(XDGEvents.TdsSDKLogout);
308
325
  XDGEventBus.Publish(XDGEvents.TapSDKLogout);
309
- if (logoutType != "SWITCH_ACCOUNT" && logoutType != "COMPLIANCE_EXIT")
326
+ if (logoutType != "SWITCH_ACCOUNT"
327
+ && logoutType != "COMPLIANCE_EXIT"
328
+ && logoutType != GlobalComplianceLogout
329
+ && logoutType != GlobalComplianceExit)
310
330
  {
311
331
  XDGEventBus.Publish(XDGEvents.TapSDKComplianceExit, ConfigModule.IsGlobal);
312
332
  }
313
333
 
314
- if (bShowAgreement)
334
+ if (logoutType != "COMPLIANCE_EXIT" && logoutType != GlobalComplianceExit)
335
+ {
336
+ XDCompliance.Stop();
337
+ }
338
+
339
+ if (bShowAgreement && !preserveAgreement)
315
340
  {
316
341
  _ = AgreementModule.ConfirmAgreement().ContinueWith(t =>
317
342
  {
@@ -331,11 +356,14 @@ namespace XD.SDK.Account.Internal.Standalone
331
356
  }
332
357
  }
333
358
 
334
- private static void ClearUserCache()
359
+ private static void ClearUserCache(bool preserveAgreement = false)
335
360
  {
336
361
  AccessTokenModule.ClearToken();
337
362
  UserModule.ClearUserData();
338
- AgreementModule.ClearLocalSignedAgreements();
363
+ if (!preserveAgreement)
364
+ {
365
+ AgreementModule.ClearLocalSignedAgreements();
366
+ }
339
367
  }
340
368
 
341
369
  private async Task CancelAccount()
@@ -490,4 +518,4 @@ namespace XD.SDK.Account.Internal.Standalone
490
518
  }
491
519
  }
492
520
  }
493
- #endif
521
+ #endif
@@ -0,0 +1,129 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using System.Collections.Generic;
4
+ using System.Threading.Tasks;
5
+ using XD.SDK.Common;
6
+ using XD.SDK.Common.Internal;
7
+ using XD.SDK.Common.Internal.Standalone;
8
+
9
+ namespace XD.SDK.Account.Internal.Standalone
10
+ {
11
+ internal static class XDCompliance
12
+ {
13
+ private const int RequiredKr = 40313;
14
+ private const int RequiredGlobal = 40314;
15
+ internal static Action<bool> LogoutHandler;
16
+
17
+ private static bool _isTimeLimitDialogVisible;
18
+ private static int _timeLimitDialogVersion;
19
+
20
+ internal static bool IsRequired(int code)
21
+ {
22
+ return code == RequiredKr || code == RequiredGlobal;
23
+ }
24
+
25
+ internal static bool IsRequired(XDHttpException exception)
26
+ {
27
+ return exception != null && IsRequired(exception.Code);
28
+ }
29
+
30
+ internal static async Task RunOnLogin(string url)
31
+ {
32
+ if (!ConfigModule.IsGlobal)
33
+ {
34
+ XDGLogger.Warn("[Compliance] Compliance required code received in non-Global region. The server should only issue 40313/40314 to Global compliance clients.",
35
+ XDGLoggerTag.Account);
36
+ throw new XDComplianceException("Compliance triggered in non-Global region");
37
+ }
38
+
39
+ if (string.IsNullOrEmpty(url))
40
+ {
41
+ throw new XDComplianceException("Compliance url is empty");
42
+ }
43
+
44
+ var result = await XDComplianceWebOpener.OpenAsync(url);
45
+ if (!result.IsPassed)
46
+ {
47
+ throw new XDComplianceException(result.Reason ?? "Compliance cancelled");
48
+ }
49
+
50
+ // Web close payload only indicates whether the compliance flow passed.
51
+ // The retried /account/v2/info response is the authoritative countdown source.
52
+ }
53
+
54
+ internal static void ApplyRemainingSeconds(long? remainingSeconds)
55
+ {
56
+ XDComplianceCountdownService.Cancel();
57
+ var remaining = remainingSeconds.GetValueOrDefault(0);
58
+ if (remaining <= 0)
59
+ {
60
+ return;
61
+ }
62
+
63
+ XDComplianceCountdownService.Schedule(remaining, ShowTimeLimitDialog);
64
+ }
65
+
66
+ internal static void Stop()
67
+ {
68
+ XDComplianceCountdownService.Cancel();
69
+ _isTimeLimitDialogVisible = false;
70
+ _timeLimitDialogVersion++;
71
+ XDComplianceWebOpener.TryClose();
72
+ }
73
+
74
+ private static void ShowTimeLimitDialog()
75
+ {
76
+ if (_isTimeLimitDialogVisible)
77
+ {
78
+ return;
79
+ }
80
+
81
+ _isTimeLimitDialogVisible = true;
82
+ var dialogVersion = ++_timeLimitDialogVersion;
83
+ var localizable = XDLocalization.GetCurrentLocalizableString();
84
+ var config = new Dictionary<string, object>
85
+ {
86
+ { ConfirmDialog.TITLE_KEY, FirstNonEmpty(localizable?.CompliancePlayTimeLimitTitle, "Play Time Ended") },
87
+ { ConfirmDialog.CONTENT_KEY, FirstNonEmpty(localizable?.CompliancePlayTimeLimitContent, "This account has used up today's available play time and cannot continue playing for now.") },
88
+ { ConfirmDialog.CONFIRM_TEXT_KEY, FirstNonEmpty(localizable?.CompliancePlayTimeLimitConfirm, localizable?.IUnderstand, "OK") }
89
+ };
90
+
91
+ try
92
+ {
93
+ UIManager.ShowUI<ConfirmDialog>(config, (code, data) =>
94
+ {
95
+ var isCurrentDialog = dialogVersion == _timeLimitDialogVersion;
96
+ _isTimeLimitDialogVisible = false;
97
+ UIManager.Dismiss();
98
+ if (isCurrentDialog)
99
+ {
100
+ LogoutHandler?.Invoke(true);
101
+ }
102
+ });
103
+ }
104
+ catch (Exception e)
105
+ {
106
+ XDGLogger.Warn($"[Compliance] Show time limit dialog failed: {e.Message}", XDGLoggerTag.Account);
107
+ _isTimeLimitDialogVisible = false;
108
+ if (dialogVersion == _timeLimitDialogVersion)
109
+ {
110
+ LogoutHandler?.Invoke(true);
111
+ }
112
+ }
113
+ }
114
+
115
+ private static string FirstNonEmpty(params string[] values)
116
+ {
117
+ foreach (var value in values)
118
+ {
119
+ if (!string.IsNullOrEmpty(value))
120
+ {
121
+ return value;
122
+ }
123
+ }
124
+
125
+ return string.Empty;
126
+ }
127
+ }
128
+ }
129
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 93cd5172f2404e398f74e057d1d44007
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,43 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System.Collections.Generic;
3
+
4
+ namespace XD.SDK.Account.Internal.Standalone
5
+ {
6
+ internal class XDComplianceCloseResult
7
+ {
8
+ internal int Code = 1;
9
+ internal string Reason;
10
+ internal long? RemainingSeconds;
11
+
12
+ internal bool IsPassed => Code == 0;
13
+
14
+ internal static XDComplianceCloseResult Parse(Dictionary<string, object> data)
15
+ {
16
+ var result = new XDComplianceCloseResult();
17
+ if (data == null)
18
+ {
19
+ return result;
20
+ }
21
+
22
+ if (data.TryGetValue("code", out var code) && code != null && int.TryParse(code.ToString(), out var parsedCode))
23
+ {
24
+ result.Code = parsedCode;
25
+ }
26
+
27
+ if (data.TryGetValue("reason", out var reason) && reason is string reasonString)
28
+ {
29
+ result.Reason = reasonString;
30
+ }
31
+
32
+ if (data.TryGetValue("remainingSeconds", out var remainingSeconds)
33
+ && remainingSeconds != null
34
+ && long.TryParse(remainingSeconds.ToString(), out var parsedRemainingSeconds))
35
+ {
36
+ result.RemainingSeconds = parsedRemainingSeconds;
37
+ }
38
+
39
+ return result;
40
+ }
41
+ }
42
+ }
43
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 7a0823956056460da928c003951c0f84
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,83 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using System.Diagnostics;
4
+ using System.Threading;
5
+ using UnityEngine;
6
+ using XD.SDK.Common;
7
+
8
+ namespace XD.SDK.Account.Internal.Standalone
9
+ {
10
+ internal class XDComplianceCountdownService : MonoBehaviour
11
+ {
12
+ private sealed class Entry
13
+ {
14
+ internal long DeadlineStopwatchTicks;
15
+ internal Action OnElapsed;
16
+ }
17
+
18
+ private static XDComplianceCountdownService _instance;
19
+ private static Entry _schedule;
20
+
21
+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
22
+ private static void Bootstrap()
23
+ {
24
+ if (_instance != null)
25
+ {
26
+ return;
27
+ }
28
+
29
+ var go = new GameObject("XDComplianceCountdown") { hideFlags = HideFlags.HideAndDontSave };
30
+ DontDestroyOnLoad(go);
31
+ _instance = go.AddComponent<XDComplianceCountdownService>();
32
+ }
33
+
34
+ internal static void Schedule(long seconds, Action onElapsed)
35
+ {
36
+ if (seconds <= 0 || onElapsed == null)
37
+ {
38
+ return;
39
+ }
40
+
41
+ var schedule = new Entry
42
+ {
43
+ DeadlineStopwatchTicks = Stopwatch.GetTimestamp() + seconds * Stopwatch.Frequency,
44
+ OnElapsed = onElapsed
45
+ };
46
+ Interlocked.Exchange(ref _schedule, schedule);
47
+ }
48
+
49
+ internal static void Cancel()
50
+ {
51
+ Interlocked.Exchange(ref _schedule, null);
52
+ }
53
+
54
+ private void Update()
55
+ {
56
+ var schedule = _schedule;
57
+ if (schedule == null)
58
+ {
59
+ return;
60
+ }
61
+
62
+ if (Stopwatch.GetTimestamp() < schedule.DeadlineStopwatchTicks)
63
+ {
64
+ return;
65
+ }
66
+
67
+ if (Interlocked.CompareExchange(ref _schedule, null, schedule) != schedule)
68
+ {
69
+ return;
70
+ }
71
+
72
+ try
73
+ {
74
+ schedule.OnElapsed();
75
+ }
76
+ catch (Exception e)
77
+ {
78
+ XDGLogger.Warn($"[Compliance] Countdown callback failed: {e.Message}", XDGLoggerTag.Account);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 1d0c20acb781416e91db9f03f4ccb553
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,29 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using XD.SDK.Common;
4
+
5
+ namespace XD.SDK.Account.Internal.Standalone
6
+ {
7
+ internal class XDComplianceException : XDGError
8
+ {
9
+ internal Exception OriginalException { get; }
10
+
11
+ internal XDComplianceException(string message)
12
+ : base(ResponseCode.Common.Cancelled, message)
13
+ {
14
+ }
15
+
16
+ internal XDComplianceException(XDGError exception)
17
+ : base(exception.Code, exception.ErrorMsg, exception.Detail, exception.ExtraData)
18
+ {
19
+ OriginalException = exception;
20
+ }
21
+
22
+ internal XDComplianceException(Exception exception)
23
+ : base(ResponseCode.Common.Failed, exception.Message)
24
+ {
25
+ OriginalException = exception;
26
+ }
27
+ }
28
+ }
29
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: aa95d3b4be1d45579e68fc24b47a69ab
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,88 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using System.Threading.Tasks;
4
+ using XD.SDK.Common;
5
+ using XD.SDK.Common.Internal.Standalone;
6
+
7
+ namespace XD.SDK.Account.Internal.Standalone
8
+ {
9
+ internal static class XDComplianceWebOpener
10
+ {
11
+ private static TaskCompletionSource<XDComplianceCloseResult> _currentTcs;
12
+
13
+ internal static bool IsActive => _currentTcs != null;
14
+
15
+ internal static Task<XDComplianceCloseResult> OpenAsync(string url)
16
+ {
17
+ var tcs = new TaskCompletionSource<XDComplianceCloseResult>();
18
+
19
+ if (string.IsNullOrEmpty(url))
20
+ {
21
+ XDGLogger.Warn("[Compliance] complianceUrl is empty, treat as cancelled.", XDGLoggerTag.Account);
22
+ tcs.SetResult(new XDComplianceCloseResult());
23
+ return tcs.Task;
24
+ }
25
+
26
+ _currentTcs = tcs;
27
+ XDGLogger.Debug($"[Compliance] Open compliance web: {url}", XDGLoggerTag.Account);
28
+
29
+ #if (UNITY_STANDALONE || (UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS)) && !XDSDK_DISABLE_VUPLEX
30
+ try
31
+ {
32
+ XDGCommon.OpenWebPage(url, (action, data) =>
33
+ {
34
+ if (action != WebActionEnum.CLOSE)
35
+ {
36
+ return;
37
+ }
38
+
39
+ Complete(tcs, XDComplianceCloseResult.Parse(data));
40
+ });
41
+ }
42
+ catch (Exception e)
43
+ {
44
+ XDGLogger.Warn($"[Compliance] Open compliance web failed: {e.Message}", XDGLoggerTag.Account);
45
+ Complete(tcs, new XDComplianceCloseResult { Reason = "webview_open_failed" });
46
+ }
47
+ #else
48
+ XDGLogger.Warn("[Compliance] WebView is unavailable, compliance web cannot be opened.",
49
+ XDGLoggerTag.Account);
50
+ Complete(tcs, new XDComplianceCloseResult { Reason = "webview_unavailable" });
51
+ #endif
52
+
53
+ return tcs.Task;
54
+ }
55
+
56
+ internal static void TryClose()
57
+ {
58
+ var tcs = _currentTcs;
59
+ if (tcs == null)
60
+ {
61
+ return;
62
+ }
63
+
64
+ try
65
+ {
66
+ UIManager.Dismiss();
67
+ }
68
+ catch (Exception e)
69
+ {
70
+ XDGLogger.Warn($"[Compliance] Close compliance web failed: {e.Message}", XDGLoggerTag.Account);
71
+ }
72
+
73
+ Complete(tcs, new XDComplianceCloseResult { Reason = "user_canceled" });
74
+ }
75
+
76
+ private static void Complete(TaskCompletionSource<XDComplianceCloseResult> tcs, XDComplianceCloseResult result)
77
+ {
78
+ if (_currentTcs != tcs)
79
+ {
80
+ return;
81
+ }
82
+
83
+ _currentTcs = null;
84
+ tcs.TrySetResult(result);
85
+ }
86
+ }
87
+ }
88
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 0cad8e1cd5a44ab3bd5c0e93b504da40
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -4,6 +4,8 @@ using System.IO;
4
4
  using System.Threading.Tasks;
5
5
  using System.Collections.Generic;
6
6
  using System.Linq;
7
+ using Newtonsoft.Json;
8
+ using Newtonsoft.Json.Linq;
7
9
  using UnityEngine;
8
10
  using XD.SDK.Common;
9
11
  using XD.SDK.Common.Internal;
@@ -261,11 +263,15 @@ namespace XD.SDK.Account.Internal.Standalone
261
263
  }
262
264
  catch (XDHttpException e)
263
265
  {
264
- if (e.HttpStatusCode == 401 || e.Code == 40311 || e.Code == 40312)
266
+ if (e.HttpStatusCode == 401 || e.Code == 40311 || e.Code == 40312 || XDCompliance.IsRequired(e))
265
267
  {
266
268
  throw;
267
269
  }
268
270
  }
271
+ catch (XDComplianceException)
272
+ {
273
+ throw;
274
+ }
269
275
  catch (Exception e)
270
276
  {
271
277
  XDGLogger.Warn(e.Message, XDGLoggerTag.Account);
@@ -420,6 +426,10 @@ namespace XD.SDK.Account.Internal.Standalone
420
426
  // 同自动登录一样,触发刷新 token
421
427
  _ = AccessTokenModule.Refresh();
422
428
  }
429
+ catch (XDComplianceException)
430
+ {
431
+ throw;
432
+ }
423
433
  catch (XDGError e)
424
434
  {
425
435
  if (e.Code == ResponseCode.Account.TokenExpired)
@@ -519,7 +529,12 @@ namespace XD.SDK.Account.Internal.Standalone
519
529
  }
520
530
  }
521
531
 
522
- public static async Task<XDGUser> FetchUserInfo()
532
+ public static Task<XDGUser> FetchUserInfo()
533
+ {
534
+ return FetchUserInfo(true);
535
+ }
536
+
537
+ private static async Task<XDGUser> FetchUserInfo(bool allowComplianceRetry)
523
538
  {
524
539
  try
525
540
  {
@@ -535,11 +550,54 @@ namespace XD.SDK.Account.Internal.Standalone
535
550
  }
536
551
 
537
552
  await persistence.Save(current, SystemInfo.deviceUniqueIdentifier);
553
+ XDCompliance.ApplyRemainingSeconds(response.RemainingSeconds);
538
554
  AliyunTrack.LoginPreSuccess();
539
555
  return current;
540
556
  }
541
557
  catch (XDHttpException xdException)
542
558
  {
559
+ var isComplianceRequired = XDCompliance.IsRequired(xdException);
560
+ var complianceUrl = GetComplianceUrl(xdException.ExtraData);
561
+ if (allowComplianceRetry
562
+ && isComplianceRequired
563
+ && !XDComplianceWebOpener.IsActive
564
+ && !string.IsNullOrEmpty(complianceUrl))
565
+ {
566
+ XDGLogger.Debug($"[Compliance] Trigger login web. code={xdException.Code}, message={xdException.ErrorMsg}, detail={xdException.Detail}, global={ConfigModule.IsGlobal}, active={XDComplianceWebOpener.IsActive}, url={complianceUrl}", XDGLoggerTag.Account);
567
+ try
568
+ {
569
+ await XDCompliance.RunOnLogin(complianceUrl);
570
+ }
571
+ catch (Exception e)
572
+ {
573
+ AliyunTrack.LoginPreFail(e.Message);
574
+ throw;
575
+ }
576
+
577
+ try
578
+ {
579
+ return await FetchUserInfo(false);
580
+ }
581
+ // IL2CPP: keep explicit catch order; do not use catch filters.
582
+ catch (XDComplianceException)
583
+ {
584
+ throw;
585
+ }
586
+ catch (XDGError e)
587
+ {
588
+ throw new XDComplianceException(e);
589
+ }
590
+ catch (Exception e)
591
+ {
592
+ throw new XDComplianceException(e);
593
+ }
594
+ }
595
+
596
+ if (isComplianceRequired)
597
+ {
598
+ XDGLogger.Warn($"[Compliance] Login web not opened. code={xdException.Code}, message={xdException.ErrorMsg}, detail={xdException.Detail}, global={ConfigModule.IsGlobal}, allowRetry={allowComplianceRetry}, active={XDComplianceWebOpener.IsActive}, hasExtraData={xdException.ExtraData != null}, url={complianceUrl}, extraData={SerializeComplianceExtraData(xdException.ExtraData)}", XDGLoggerTag.Account);
599
+ }
600
+
543
601
  if (xdException.Code == 40312 && xdException.ExtraData != null)
544
602
  {
545
603
  var extra = xdException.ExtraData["extra"] as Dictionary<string, object>;
@@ -644,6 +702,69 @@ namespace XD.SDK.Account.Internal.Standalone
644
702
  throw e;
645
703
  }
646
704
  }
705
+
706
+ private static string SerializeComplianceExtraData(Dictionary<string, object> extraData)
707
+ {
708
+ if (extraData == null)
709
+ {
710
+ return string.Empty;
711
+ }
712
+
713
+ try
714
+ {
715
+ return JsonConvert.SerializeObject(extraData);
716
+ }
717
+ catch (Exception e)
718
+ {
719
+ return $"<serialize failed: {e.Message}>";
720
+ }
721
+ }
722
+
723
+ private static string GetComplianceUrl(Dictionary<string, object> extraData)
724
+ {
725
+ if (extraData == null)
726
+ {
727
+ return null;
728
+ }
729
+
730
+ if (TryGetString(extraData, "url", out var url))
731
+ {
732
+ return url;
733
+ }
734
+
735
+ if (extraData.TryGetValue("extra", out var extraObj) && TryGetString(extraObj, "url", out url))
736
+ {
737
+ return url;
738
+ }
739
+
740
+ return null;
741
+ }
742
+
743
+ private static bool TryGetString(object source, string key, out string value)
744
+ {
745
+ value = null;
746
+
747
+ if (source is Dictionary<string, object> dictionary
748
+ && dictionary.TryGetValue(key, out var dictionaryValue)
749
+ && dictionaryValue != null)
750
+ {
751
+ value = dictionaryValue as string ?? dictionaryValue.ToString();
752
+ return !string.IsNullOrEmpty(value);
753
+ }
754
+
755
+ if (source is JObject jObject)
756
+ {
757
+ var token = jObject[key];
758
+ if (token != null && token.Type != JTokenType.Null)
759
+ {
760
+ value = token.ToString();
761
+ return !string.IsNullOrEmpty(value);
762
+ }
763
+ }
764
+
765
+ return false;
766
+ }
767
+
647
768
  }
648
769
  }
649
- #endif
770
+ #endif
@@ -19,43 +19,61 @@ namespace XD.SDK.Account.Internal.Standalone
19
19
  {
20
20
  XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}", XDGLoggerTag.Web);
21
21
 
22
- var user = await UserModule.GetLocalUser();
23
- if (user == null || string.IsNullOrEmpty(user.UserId))
22
+ try
24
23
  {
25
- callbackFunction(new WebBridgeResponse.Failed
24
+ var localUser = await UserModule.GetLocalUser();
25
+ if (localUser == null || string.IsNullOrEmpty(localUser.UserId))
26
26
  {
27
- Msg = "current user is null"
28
- });
29
- return;
30
- }
27
+ callbackFunction(new WebBridgeResponse.Failed
28
+ {
29
+ Msg = XDGErrorExtensions.NotLoginError().ErrorMsg
30
+ });
31
+ return;
32
+ }
31
33
 
32
- var result = new Dictionary<string, object>
33
- {
34
- { "userId", user.UserId },
35
- { "username", user.UserName },
36
- { "loginTypeEntryName", user.LoginTypeName },
37
- { "loginList", user.BoundAccounts ?? new List<string>() },
38
- { "nickName", user.NickName },
39
- { "avatar", user.Avatar }
40
- };
34
+ var user = await UserModule.FetchUserInfo();
35
+ var result = new Dictionary<string, object>
36
+ {
37
+ { "userId", user.UserId },
38
+ { "username", user.UserName },
39
+ { "loginTypeEntryName", user.LoginTypeName },
40
+ { "loginList", user.BoundAccounts ?? new List<string>() },
41
+ { "nickName", user.NickName },
42
+ { "avatar", user.Avatar }
43
+ };
44
+
45
+ var token = await AccessTokenModule.GetLocalAccessToken();
46
+ if (token != null)
47
+ {
48
+ result["accessToken"] = new Dictionary<string, object>
49
+ {
50
+ { "kid", token.Kid },
51
+ { "macKey", token.MacKey },
52
+ { "macAlgorithm", token.MacAlgorithm },
53
+ { "tokenType", token.TokenType },
54
+ { "expireIn", token.ExpireIn }
55
+ };
56
+ }
41
57
 
42
- var token = await AccessTokenModule.GetLocalAccessToken();
43
- if (token != null)
58
+ callbackFunction(new WebBridgeResponse.Success
59
+ {
60
+ Data = result
61
+ });
62
+ }
63
+ catch (XDGError e)
44
64
  {
45
- result["accessToken"] = new Dictionary<string, object>
65
+ callbackFunction(new WebBridgeResponse.Failed
46
66
  {
47
- { "kid", token.Kid },
48
- { "macKey", token.MacKey },
49
- { "macAlgorithm", token.MacAlgorithm },
50
- { "tokenType", token.TokenType },
51
- { "expireIn", token.ExpireIn }
52
- };
67
+ Msg = e.ErrorMsg
68
+ });
53
69
  }
54
-
55
- callbackFunction(new WebBridgeResponse.Success
70
+ catch (Exception e)
56
71
  {
57
- Data = result
58
- });
72
+ callbackFunction(new WebBridgeResponse.Failed
73
+ {
74
+ Msg = e.Message
75
+ });
76
+ }
59
77
  }
60
78
  }
61
79
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "com.xd.sdk.account",
3
3
  "displayName": "XDGSDK Account",
4
- "version": "7.7.3",
4
+ "version": "7.8.0",
5
5
  "description": "XDGSDK",
6
6
  "unity": "2019.3",
7
7
  "license": "MIT",
8
8
  "dependencies": {
9
- "com.xd.sdk.common": "7.7.3"
9
+ "com.xd.sdk.common": "7.8.0"
10
10
  }
11
11
  }