com.taptap.sdk.login 4.8.4-beta.1 → 4.8.4-beta.2
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 +3 -3
- package/Mobile/Editor/TapLoginIOSProcessor.cs +107 -49
- package/Mobile/Editor/TapLoginMobileProcessBuild.cs +20 -20
- package/Runtime/Public/TapTapLogin.cs +1 -1
- package/Standalone/Editor/TapLoginStandaloneProcessBuild.cs +21 -21
- package/Standalone/Runtime/Internal2/Http/Response/ProfileResponse.cs +23 -23
- package/Standalone/Runtime/Internal2/Http/Response/QRCodeResponse.cs +16 -16
- package/Standalone/Runtime/Internal2/Http/Response/TokenResponse.cs +28 -28
- package/Standalone/Runtime/Internal2/LoginService.cs +192 -192
- package/Standalone/Runtime/Internal2/QRCodeUtils.cs +50 -50
- package/Standalone/Runtime/Internal2/UI/ClientButtonListener.cs +20 -20
- package/Standalone/Runtime/Internal2/UI/LoginPanelController.cs +71 -71
- package/Standalone/Runtime/Internal2/UI/QRCodeController.cs +180 -180
- package/Standalone/Runtime/Internal2/UI/TitleController.cs +20 -20
- package/Standalone/Runtime/Internal2/UI/WebController.cs +128 -128
- package/package.json +9 -9
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
using UnityEngine;
|
|
2
|
-
using UnityEngine.UI;
|
|
3
|
-
using TapSDK.UI;
|
|
4
|
-
using TapSDK.Login.Internal.Http;
|
|
5
|
-
using System;
|
|
6
|
-
using TapSDK.Core;
|
|
7
|
-
|
|
8
|
-
namespace TapSDK.Login.Internal {
|
|
9
|
-
public class LoginPanelController : BasePanelController {
|
|
10
|
-
public enum Type {
|
|
11
|
-
Auth,
|
|
12
|
-
Login
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public class OpenParams : AbstractOpenPanelParameter {
|
|
16
|
-
public Type Type { get; set; }
|
|
17
|
-
public string ClientId { get; set; }
|
|
18
|
-
public string[] Scopes { get; set; }
|
|
19
|
-
public Action<TokenData, String> OnAuth { get; set; }
|
|
20
|
-
public Action<TapException, String> OnError { get; set; }
|
|
21
|
-
public Action OnClose { get; set; }
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
private TitleController titleController;
|
|
25
|
-
private QRCodeController qrcodeController;
|
|
26
|
-
private WebController webController;
|
|
27
|
-
|
|
28
|
-
protected override void BindComponents() {
|
|
29
|
-
base.BindComponents();
|
|
30
|
-
|
|
31
|
-
Button closeBtn = transform.Find("TopBar/CloseButton").GetComponent<Button>();
|
|
32
|
-
closeBtn.onClick.AddListener(OnCloseClicked);
|
|
33
|
-
|
|
34
|
-
Transform titleTrans = transform.Find("TopBar/Title");
|
|
35
|
-
titleController = new TitleController(titleTrans);
|
|
36
|
-
|
|
37
|
-
Transform qrcodeTrans = transform.Find("QRCode");
|
|
38
|
-
qrcodeController = new QRCodeController(qrcodeTrans, OnAuth);
|
|
39
|
-
|
|
40
|
-
Transform webTrans = transform.Find("Web");
|
|
41
|
-
webController = new WebController(webTrans, OnAuth);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected override void OnLoadSuccess() {
|
|
45
|
-
base.OnLoadSuccess();
|
|
46
|
-
|
|
47
|
-
OpenParams openParams = openParam as OpenParams;
|
|
48
|
-
titleController.Load();
|
|
49
|
-
qrcodeController.Load(openParams.ClientId, openParams.Scopes);
|
|
50
|
-
webController.Load(openParams.ClientId, openParams.Scopes);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private void OnDestroy() {
|
|
54
|
-
qrcodeController.Unload();
|
|
55
|
-
webController.Unload();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private void OnCloseClicked() {
|
|
59
|
-
Close();
|
|
60
|
-
OpenParams openParams = openParam as OpenParams;
|
|
61
|
-
openParams.OnClose.Invoke();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
protected void OnAuth(TokenData tokenData, String loginType) {
|
|
65
|
-
if (tokenData != null) {
|
|
66
|
-
OpenParams openParams = openParam as OpenParams;
|
|
67
|
-
openParams.OnAuth.Invoke(tokenData, loginType);
|
|
68
|
-
Close();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using UnityEngine.UI;
|
|
3
|
+
using TapSDK.UI;
|
|
4
|
+
using TapSDK.Login.Internal.Http;
|
|
5
|
+
using System;
|
|
6
|
+
using TapSDK.Core;
|
|
7
|
+
|
|
8
|
+
namespace TapSDK.Login.Internal {
|
|
9
|
+
public class LoginPanelController : BasePanelController {
|
|
10
|
+
public enum Type {
|
|
11
|
+
Auth,
|
|
12
|
+
Login
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public class OpenParams : AbstractOpenPanelParameter {
|
|
16
|
+
public Type Type { get; set; }
|
|
17
|
+
public string ClientId { get; set; }
|
|
18
|
+
public string[] Scopes { get; set; }
|
|
19
|
+
public Action<TokenData, String> OnAuth { get; set; }
|
|
20
|
+
public Action<TapException, String> OnError { get; set; }
|
|
21
|
+
public Action OnClose { get; set; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
private TitleController titleController;
|
|
25
|
+
private QRCodeController qrcodeController;
|
|
26
|
+
private WebController webController;
|
|
27
|
+
|
|
28
|
+
protected override void BindComponents() {
|
|
29
|
+
base.BindComponents();
|
|
30
|
+
|
|
31
|
+
Button closeBtn = transform.Find("TopBar/CloseButton").GetComponent<Button>();
|
|
32
|
+
closeBtn.onClick.AddListener(OnCloseClicked);
|
|
33
|
+
|
|
34
|
+
Transform titleTrans = transform.Find("TopBar/Title");
|
|
35
|
+
titleController = new TitleController(titleTrans);
|
|
36
|
+
|
|
37
|
+
Transform qrcodeTrans = transform.Find("QRCode");
|
|
38
|
+
qrcodeController = new QRCodeController(qrcodeTrans, OnAuth);
|
|
39
|
+
|
|
40
|
+
Transform webTrans = transform.Find("Web");
|
|
41
|
+
webController = new WebController(webTrans, OnAuth);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected override void OnLoadSuccess() {
|
|
45
|
+
base.OnLoadSuccess();
|
|
46
|
+
|
|
47
|
+
OpenParams openParams = openParam as OpenParams;
|
|
48
|
+
titleController.Load();
|
|
49
|
+
qrcodeController.Load(openParams.ClientId, openParams.Scopes);
|
|
50
|
+
webController.Load(openParams.ClientId, openParams.Scopes);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private void OnDestroy() {
|
|
54
|
+
qrcodeController.Unload();
|
|
55
|
+
webController.Unload();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void OnCloseClicked() {
|
|
59
|
+
Close();
|
|
60
|
+
OpenParams openParams = openParam as OpenParams;
|
|
61
|
+
openParams.OnClose.Invoke();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected void OnAuth(TokenData tokenData, String loginType) {
|
|
65
|
+
if (tokenData != null) {
|
|
66
|
+
OpenParams openParams = openParam as OpenParams;
|
|
67
|
+
openParams.OnAuth.Invoke(tokenData, loginType);
|
|
68
|
+
Close();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
72
|
}
|
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
using System;
|
|
2
|
-
using System.Threading.Tasks;
|
|
3
|
-
using UnityEngine;
|
|
4
|
-
using UnityEngine.UI;
|
|
5
|
-
using TapSDK.Login.Internal.Http;
|
|
6
|
-
using TapSDK.Core;
|
|
7
|
-
using TapSDK.Core.Internal.Utils;
|
|
8
|
-
using UnityEngine.EventSystems;
|
|
9
|
-
using TapSDK.Core.Internal.Log;
|
|
10
|
-
using TapSDK.Core.Standalone.Internal.Http;
|
|
11
|
-
using TapSDK.Login.Standalone.Internal;
|
|
12
|
-
|
|
13
|
-
namespace TapSDK.Login.Internal {
|
|
14
|
-
public class QRCodeController {
|
|
15
|
-
private readonly static string DEFAULT_CLIENT_CN_IOS = "Sprites/tapsdk-login-client-cn-ios";
|
|
16
|
-
private readonly static string DEFAULT_CLIENT_CN_ANDROID = "Sprites/tapsdk-login-client-cn-android";
|
|
17
|
-
|
|
18
|
-
private readonly static string DEFAULT_CLIENT_GLOBAL_IOS = "Sprites/tapsdk-login-client-global-ios";
|
|
19
|
-
private readonly static string DEFAULT_CLIENT_GLOBAL_ANDROID = "Sprites/tapsdk-login-client-global-android";
|
|
20
|
-
|
|
21
|
-
private readonly static string AUTH_PENDING = "authorization_pending";
|
|
22
|
-
private readonly static string AUTH_WAITING = "authorization_waiting";
|
|
23
|
-
private readonly static string AUTH_DENIED = "access_denied";
|
|
24
|
-
// private readonly static string AUTH_SUCCESS = "";
|
|
25
|
-
|
|
26
|
-
private readonly Action<TokenData, String> onAuth;
|
|
27
|
-
|
|
28
|
-
private readonly Text titleText;
|
|
29
|
-
private readonly RawImage qrcodeImage;
|
|
30
|
-
private readonly Text tipsText;
|
|
31
|
-
private readonly GameObject scanTips;
|
|
32
|
-
private readonly RawImage demoImage;
|
|
33
|
-
|
|
34
|
-
private readonly Button refreshButton;
|
|
35
|
-
|
|
36
|
-
private bool isRunning;
|
|
37
|
-
private QRCodeData qrcodeData;
|
|
38
|
-
|
|
39
|
-
private string clientId;
|
|
40
|
-
private string[] scopes;
|
|
41
|
-
|
|
42
|
-
public QRCodeController(Transform transform, Action<TokenData, String> onAuth) {
|
|
43
|
-
this.onAuth = onAuth;
|
|
44
|
-
|
|
45
|
-
titleText = transform.Find("Title").GetComponent<Text>();
|
|
46
|
-
qrcodeImage = transform.Find("QRCode/Image").GetComponent<RawImage>();
|
|
47
|
-
tipsText = transform.Find("Tips").GetComponent<Text>();
|
|
48
|
-
|
|
49
|
-
ClientButtonListener iOSButtonListener = transform.Find("Clients/iOSButton").GetComponent<ClientButtonListener>();
|
|
50
|
-
iOSButtonListener.GetComponent<Button>().onClick.AddListener(() => {
|
|
51
|
-
EventSystem.current.SetSelectedGameObject(null);
|
|
52
|
-
});
|
|
53
|
-
iOSButtonListener.OnMouseEnter = OnShowIOSDemoImage;
|
|
54
|
-
iOSButtonListener.OnMouseExit = OnCloseDemoImage;
|
|
55
|
-
ClientButtonListener androidButtonListener = transform.Find("Clients/AndroidButton").GetComponent<ClientButtonListener>();
|
|
56
|
-
androidButtonListener.OnMouseEnter = OnShowAndroidDemoImage;
|
|
57
|
-
androidButtonListener.OnMouseExit = OnCloseDemoImage;
|
|
58
|
-
androidButtonListener.GetComponent<Button>().onClick.AddListener(() => {
|
|
59
|
-
EventSystem.current.SetSelectedGameObject(null);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
scanTips = transform.Find("ScanTips").gameObject;
|
|
63
|
-
demoImage = scanTips.transform.Find("DemoImage").GetComponent<RawImage>();
|
|
64
|
-
scanTips.SetActive(false);
|
|
65
|
-
|
|
66
|
-
refreshButton = transform.Find("QRCode/RefreshButton").GetComponent<Button>();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public void Load(string clientId, string[] scopes) {
|
|
70
|
-
this.clientId = clientId;
|
|
71
|
-
this.scopes = scopes;
|
|
72
|
-
|
|
73
|
-
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
74
|
-
titleText.text = lang.QrTitleLogin();
|
|
75
|
-
tipsText.text = $"{lang.QrNoticeUse()} <b>TapTap</b> {lang.QrNoticeClient()} {lang.QrNoticeScanToLogin()}";
|
|
76
|
-
|
|
77
|
-
// 加载二维码
|
|
78
|
-
_ = RefreshQRCode(clientId, scopes);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public void Unload() {
|
|
82
|
-
isRunning = false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
private async Task RefreshQRCode(string clientId, string[] scopes) {
|
|
86
|
-
try {
|
|
87
|
-
refreshButton.gameObject.SetActive(false);
|
|
88
|
-
qrcodeData = await LoginService.GetQRCodeUrl(clientId, scopes);
|
|
89
|
-
qrcodeImage.texture = QRCodeUtils.EncodeQrImage(qrcodeData.Url, 320, 320);
|
|
90
|
-
|
|
91
|
-
// 加载二维码完成后再开启监听
|
|
92
|
-
_ = ListenScanQRCode(clientId);
|
|
93
|
-
|
|
94
|
-
await Task.Delay(qrcodeData.ExpiresIn * 1000);
|
|
95
|
-
|
|
96
|
-
// 过期暂停监听
|
|
97
|
-
isRunning = false;
|
|
98
|
-
ShowRefreshQRCode();
|
|
99
|
-
} catch (Exception) {
|
|
100
|
-
// 加载失败
|
|
101
|
-
ShowRefreshQRCode();
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
private async Task ListenScanQRCode(string clientId) {
|
|
107
|
-
isRunning = true;
|
|
108
|
-
while (isRunning) {
|
|
109
|
-
if (qrcodeData == null) {
|
|
110
|
-
await Task.Delay(3 * 1000);
|
|
111
|
-
} else {
|
|
112
|
-
try {
|
|
113
|
-
TokenData tokenData = await LoginService.RequestScanQRCodeResult(clientId, qrcodeData.DeviceCode);
|
|
114
|
-
TapLog.Log("Login , QRCodeController Success");
|
|
115
|
-
onAuth.Invoke(tokenData, TapLoginTracker.LOGIN_TYPE_CODE);
|
|
116
|
-
return ;
|
|
117
|
-
} catch (TapHttpServerException e) {
|
|
118
|
-
string errorMsg = e.ErrorData?.Error ?? "";
|
|
119
|
-
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
120
|
-
if (errorMsg == AUTH_PENDING) {
|
|
121
|
-
|
|
122
|
-
} else if (errorMsg == AUTH_WAITING) {
|
|
123
|
-
UI.UIManager.Instance.OpenToast(true,
|
|
124
|
-
$"{lang.QrnNoticeSuccess()},{lang.QrnNoticeSuccess2()}",
|
|
125
|
-
icon: UI.UIManager.WhiteToastSuccessIcon);
|
|
126
|
-
} else if (errorMsg == AUTH_DENIED) {
|
|
127
|
-
UI.UIManager.Instance.OpenToast(true,
|
|
128
|
-
$"{lang.QrNoticeCancel()},{lang.QrNoticeCancel2()}",
|
|
129
|
-
icon: UI.UIManager.WhiteToastErrorIcon);
|
|
130
|
-
ShowRefreshQRCode();
|
|
131
|
-
}
|
|
132
|
-
await Task.Delay(qrcodeData.Interval * 1000);
|
|
133
|
-
} catch (Exception) {
|
|
134
|
-
await Task.Delay(qrcodeData.Interval * 1000);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private void OnShowIOSDemoImage() {
|
|
141
|
-
string url = DEFAULT_CLIENT_CN_IOS;
|
|
142
|
-
if (TapTapSDK.taptapSdkOptions != null && TapTapSDK.taptapSdkOptions.region == TapTapRegionType.Overseas) {
|
|
143
|
-
url = DEFAULT_CLIENT_GLOBAL_IOS;
|
|
144
|
-
}
|
|
145
|
-
ShowDemoImage(url);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
private void OnShowAndroidDemoImage() {
|
|
149
|
-
string url = DEFAULT_CLIENT_CN_ANDROID;
|
|
150
|
-
if (TapTapSDK.taptapSdkOptions != null && TapTapSDK.taptapSdkOptions.region == TapTapRegionType.Overseas) {
|
|
151
|
-
url = DEFAULT_CLIENT_GLOBAL_ANDROID;
|
|
152
|
-
}
|
|
153
|
-
ShowDemoImage(url);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
private async void ShowDemoImage(string url) {
|
|
157
|
-
demoImage.texture = null;
|
|
158
|
-
scanTips.SetActive(true);
|
|
159
|
-
try {
|
|
160
|
-
demoImage.texture = Resources.Load<Texture2D>(url);
|
|
161
|
-
} catch (Exception) {
|
|
162
|
-
TapLog.Log("Load demo image failed : " + url);
|
|
163
|
-
demoImage.texture = null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private void OnCloseDemoImage() {
|
|
168
|
-
scanTips.SetActive(false);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private void ShowRefreshQRCode() {
|
|
172
|
-
qrcodeImage.texture = null;
|
|
173
|
-
refreshButton.gameObject.SetActive(true);
|
|
174
|
-
refreshButton.onClick.RemoveAllListeners();
|
|
175
|
-
refreshButton.onClick.AddListener(() => {
|
|
176
|
-
_ = RefreshQRCode(clientId, scopes);
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
1
|
+
using System;
|
|
2
|
+
using System.Threading.Tasks;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
using UnityEngine.UI;
|
|
5
|
+
using TapSDK.Login.Internal.Http;
|
|
6
|
+
using TapSDK.Core;
|
|
7
|
+
using TapSDK.Core.Internal.Utils;
|
|
8
|
+
using UnityEngine.EventSystems;
|
|
9
|
+
using TapSDK.Core.Internal.Log;
|
|
10
|
+
using TapSDK.Core.Standalone.Internal.Http;
|
|
11
|
+
using TapSDK.Login.Standalone.Internal;
|
|
12
|
+
|
|
13
|
+
namespace TapSDK.Login.Internal {
|
|
14
|
+
public class QRCodeController {
|
|
15
|
+
private readonly static string DEFAULT_CLIENT_CN_IOS = "Sprites/tapsdk-login-client-cn-ios";
|
|
16
|
+
private readonly static string DEFAULT_CLIENT_CN_ANDROID = "Sprites/tapsdk-login-client-cn-android";
|
|
17
|
+
|
|
18
|
+
private readonly static string DEFAULT_CLIENT_GLOBAL_IOS = "Sprites/tapsdk-login-client-global-ios";
|
|
19
|
+
private readonly static string DEFAULT_CLIENT_GLOBAL_ANDROID = "Sprites/tapsdk-login-client-global-android";
|
|
20
|
+
|
|
21
|
+
private readonly static string AUTH_PENDING = "authorization_pending";
|
|
22
|
+
private readonly static string AUTH_WAITING = "authorization_waiting";
|
|
23
|
+
private readonly static string AUTH_DENIED = "access_denied";
|
|
24
|
+
// private readonly static string AUTH_SUCCESS = "";
|
|
25
|
+
|
|
26
|
+
private readonly Action<TokenData, String> onAuth;
|
|
27
|
+
|
|
28
|
+
private readonly Text titleText;
|
|
29
|
+
private readonly RawImage qrcodeImage;
|
|
30
|
+
private readonly Text tipsText;
|
|
31
|
+
private readonly GameObject scanTips;
|
|
32
|
+
private readonly RawImage demoImage;
|
|
33
|
+
|
|
34
|
+
private readonly Button refreshButton;
|
|
35
|
+
|
|
36
|
+
private bool isRunning;
|
|
37
|
+
private QRCodeData qrcodeData;
|
|
38
|
+
|
|
39
|
+
private string clientId;
|
|
40
|
+
private string[] scopes;
|
|
41
|
+
|
|
42
|
+
public QRCodeController(Transform transform, Action<TokenData, String> onAuth) {
|
|
43
|
+
this.onAuth = onAuth;
|
|
44
|
+
|
|
45
|
+
titleText = transform.Find("Title").GetComponent<Text>();
|
|
46
|
+
qrcodeImage = transform.Find("QRCode/Image").GetComponent<RawImage>();
|
|
47
|
+
tipsText = transform.Find("Tips").GetComponent<Text>();
|
|
48
|
+
|
|
49
|
+
ClientButtonListener iOSButtonListener = transform.Find("Clients/iOSButton").GetComponent<ClientButtonListener>();
|
|
50
|
+
iOSButtonListener.GetComponent<Button>().onClick.AddListener(() => {
|
|
51
|
+
EventSystem.current.SetSelectedGameObject(null);
|
|
52
|
+
});
|
|
53
|
+
iOSButtonListener.OnMouseEnter = OnShowIOSDemoImage;
|
|
54
|
+
iOSButtonListener.OnMouseExit = OnCloseDemoImage;
|
|
55
|
+
ClientButtonListener androidButtonListener = transform.Find("Clients/AndroidButton").GetComponent<ClientButtonListener>();
|
|
56
|
+
androidButtonListener.OnMouseEnter = OnShowAndroidDemoImage;
|
|
57
|
+
androidButtonListener.OnMouseExit = OnCloseDemoImage;
|
|
58
|
+
androidButtonListener.GetComponent<Button>().onClick.AddListener(() => {
|
|
59
|
+
EventSystem.current.SetSelectedGameObject(null);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
scanTips = transform.Find("ScanTips").gameObject;
|
|
63
|
+
demoImage = scanTips.transform.Find("DemoImage").GetComponent<RawImage>();
|
|
64
|
+
scanTips.SetActive(false);
|
|
65
|
+
|
|
66
|
+
refreshButton = transform.Find("QRCode/RefreshButton").GetComponent<Button>();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public void Load(string clientId, string[] scopes) {
|
|
70
|
+
this.clientId = clientId;
|
|
71
|
+
this.scopes = scopes;
|
|
72
|
+
|
|
73
|
+
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
74
|
+
titleText.text = lang.QrTitleLogin();
|
|
75
|
+
tipsText.text = $"{lang.QrNoticeUse()} <b>TapTap</b> {lang.QrNoticeClient()} {lang.QrNoticeScanToLogin()}";
|
|
76
|
+
|
|
77
|
+
// 加载二维码
|
|
78
|
+
_ = RefreshQRCode(clientId, scopes);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public void Unload() {
|
|
82
|
+
isRunning = false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private async Task RefreshQRCode(string clientId, string[] scopes) {
|
|
86
|
+
try {
|
|
87
|
+
refreshButton.gameObject.SetActive(false);
|
|
88
|
+
qrcodeData = await LoginService.GetQRCodeUrl(clientId, scopes);
|
|
89
|
+
qrcodeImage.texture = QRCodeUtils.EncodeQrImage(qrcodeData.Url, 320, 320);
|
|
90
|
+
|
|
91
|
+
// 加载二维码完成后再开启监听
|
|
92
|
+
_ = ListenScanQRCode(clientId);
|
|
93
|
+
|
|
94
|
+
await Task.Delay(qrcodeData.ExpiresIn * 1000);
|
|
95
|
+
|
|
96
|
+
// 过期暂停监听
|
|
97
|
+
isRunning = false;
|
|
98
|
+
ShowRefreshQRCode();
|
|
99
|
+
} catch (Exception) {
|
|
100
|
+
// 加载失败
|
|
101
|
+
ShowRefreshQRCode();
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private async Task ListenScanQRCode(string clientId) {
|
|
107
|
+
isRunning = true;
|
|
108
|
+
while (isRunning) {
|
|
109
|
+
if (qrcodeData == null) {
|
|
110
|
+
await Task.Delay(3 * 1000);
|
|
111
|
+
} else {
|
|
112
|
+
try {
|
|
113
|
+
TokenData tokenData = await LoginService.RequestScanQRCodeResult(clientId, qrcodeData.DeviceCode);
|
|
114
|
+
TapLog.Log("Login , QRCodeController Success");
|
|
115
|
+
onAuth.Invoke(tokenData, TapLoginTracker.LOGIN_TYPE_CODE);
|
|
116
|
+
return ;
|
|
117
|
+
} catch (TapHttpServerException e) {
|
|
118
|
+
string errorMsg = e.ErrorData?.Error ?? "";
|
|
119
|
+
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
120
|
+
if (errorMsg == AUTH_PENDING) {
|
|
121
|
+
|
|
122
|
+
} else if (errorMsg == AUTH_WAITING) {
|
|
123
|
+
UI.UIManager.Instance.OpenToast(true,
|
|
124
|
+
$"{lang.QrnNoticeSuccess()},{lang.QrnNoticeSuccess2()}",
|
|
125
|
+
icon: UI.UIManager.WhiteToastSuccessIcon);
|
|
126
|
+
} else if (errorMsg == AUTH_DENIED) {
|
|
127
|
+
UI.UIManager.Instance.OpenToast(true,
|
|
128
|
+
$"{lang.QrNoticeCancel()},{lang.QrNoticeCancel2()}",
|
|
129
|
+
icon: UI.UIManager.WhiteToastErrorIcon);
|
|
130
|
+
ShowRefreshQRCode();
|
|
131
|
+
}
|
|
132
|
+
await Task.Delay(qrcodeData.Interval * 1000);
|
|
133
|
+
} catch (Exception) {
|
|
134
|
+
await Task.Delay(qrcodeData.Interval * 1000);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private void OnShowIOSDemoImage() {
|
|
141
|
+
string url = DEFAULT_CLIENT_CN_IOS;
|
|
142
|
+
if (TapTapSDK.taptapSdkOptions != null && TapTapSDK.taptapSdkOptions.region == TapTapRegionType.Overseas) {
|
|
143
|
+
url = DEFAULT_CLIENT_GLOBAL_IOS;
|
|
144
|
+
}
|
|
145
|
+
ShowDemoImage(url);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private void OnShowAndroidDemoImage() {
|
|
149
|
+
string url = DEFAULT_CLIENT_CN_ANDROID;
|
|
150
|
+
if (TapTapSDK.taptapSdkOptions != null && TapTapSDK.taptapSdkOptions.region == TapTapRegionType.Overseas) {
|
|
151
|
+
url = DEFAULT_CLIENT_GLOBAL_ANDROID;
|
|
152
|
+
}
|
|
153
|
+
ShowDemoImage(url);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private async void ShowDemoImage(string url) {
|
|
157
|
+
demoImage.texture = null;
|
|
158
|
+
scanTips.SetActive(true);
|
|
159
|
+
try {
|
|
160
|
+
demoImage.texture = Resources.Load<Texture2D>(url);
|
|
161
|
+
} catch (Exception) {
|
|
162
|
+
TapLog.Log("Load demo image failed : " + url);
|
|
163
|
+
demoImage.texture = null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private void OnCloseDemoImage() {
|
|
168
|
+
scanTips.SetActive(false);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private void ShowRefreshQRCode() {
|
|
172
|
+
qrcodeImage.texture = null;
|
|
173
|
+
refreshButton.gameObject.SetActive(true);
|
|
174
|
+
refreshButton.onClick.RemoveAllListeners();
|
|
175
|
+
refreshButton.onClick.AddListener(() => {
|
|
176
|
+
_ = RefreshQRCode(clientId, scopes);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
using TapSDK.Login.Internal;
|
|
2
|
-
using UnityEngine;
|
|
3
|
-
using UnityEngine.UI;
|
|
4
|
-
|
|
5
|
-
public class TitleController {
|
|
6
|
-
private readonly Text leftText;
|
|
7
|
-
private readonly Text rightText;
|
|
8
|
-
|
|
9
|
-
public TitleController(Transform transform) {
|
|
10
|
-
leftText = transform.Find("LeftText").GetComponent<Text>();
|
|
11
|
-
rightText = transform.Find("RightText").GetComponent<Text>();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public void Load() {
|
|
15
|
-
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
16
|
-
leftText.text = lang.TitleLogin();
|
|
17
|
-
leftText.gameObject.SetActive(!string.IsNullOrEmpty(leftText.text));
|
|
18
|
-
rightText.gameObject.SetActive(false);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
1
|
+
using TapSDK.Login.Internal;
|
|
2
|
+
using UnityEngine;
|
|
3
|
+
using UnityEngine.UI;
|
|
4
|
+
|
|
5
|
+
public class TitleController {
|
|
6
|
+
private readonly Text leftText;
|
|
7
|
+
private readonly Text rightText;
|
|
8
|
+
|
|
9
|
+
public TitleController(Transform transform) {
|
|
10
|
+
leftText = transform.Find("LeftText").GetComponent<Text>();
|
|
11
|
+
rightText = transform.Find("RightText").GetComponent<Text>();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public void Load() {
|
|
15
|
+
ILoginLang lang = LoginLanguage.GetCurrentLang();
|
|
16
|
+
leftText.text = lang.TitleLogin();
|
|
17
|
+
leftText.gameObject.SetActive(!string.IsNullOrEmpty(leftText.text));
|
|
18
|
+
rightText.gameObject.SetActive(false);
|
|
19
|
+
}
|
|
20
|
+
}
|