com.taptap.sdk.login 4.3.0-aplha.13

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.
Files changed (202) hide show
  1. package/Mobile/Editor/NativeDependencies.xml +20 -0
  2. package/Mobile/Editor/NativeDependencies.xml.meta +7 -0
  3. package/Mobile/Editor/TapLoginIOSProcessor.cs +91 -0
  4. package/Mobile/Editor/TapLoginIOSProcessor.cs.meta +11 -0
  5. package/Mobile/Editor/TapLoginMobileProcessBuild.cs +20 -0
  6. package/Mobile/Editor/TapLoginMobileProcessBuild.cs.meta +11 -0
  7. package/Mobile/Editor/TapSDK.Login.Mobile.Editor.asmdef +17 -0
  8. package/Mobile/Editor/TapSDK.Login.Mobile.Editor.asmdef.meta +7 -0
  9. package/Mobile/Editor.meta +8 -0
  10. package/Mobile/Runtime/AccountWrapper.cs +32 -0
  11. package/Mobile/Runtime/AccountWrapper.cs.meta +3 -0
  12. package/Mobile/Runtime/TapSDK.Login.Mobile.Runtime.asmdef +20 -0
  13. package/Mobile/Runtime/TapSDK.Login.Mobile.Runtime.asmdef.meta +7 -0
  14. package/Mobile/Runtime/TapTapLoginImpl.cs +81 -0
  15. package/Mobile/Runtime/TapTapLoginImpl.cs.meta +3 -0
  16. package/Mobile/Runtime.meta +8 -0
  17. package/Mobile.meta +8 -0
  18. package/Plugins/iOS/TapTapSDKLoginAppDelegate.mm +40 -0
  19. package/Plugins/iOS/TapTapSDKLoginAppDelegate.mm.meta +37 -0
  20. package/Plugins/iOS.meta +8 -0
  21. package/Plugins/zxing.unity.dll +0 -0
  22. package/Plugins/zxing.unity.dll.meta +33 -0
  23. package/Plugins.meta +8 -0
  24. package/Runtime/Internal/ITapTapLoginPlatform.cs +15 -0
  25. package/Runtime/Internal/ITapTapLoginPlatform.cs.meta +3 -0
  26. package/Runtime/Internal/Init/LoginInitTask.cs +20 -0
  27. package/Runtime/Internal/Init/LoginInitTask.cs.meta +11 -0
  28. package/Runtime/Internal/Init.meta +8 -0
  29. package/Runtime/Internal/Region.cs +98 -0
  30. package/Runtime/Internal/Region.cs.meta +11 -0
  31. package/Runtime/Internal/TapTapLoginManager.cs +38 -0
  32. package/Runtime/Internal/TapTapLoginManager.cs.meta +3 -0
  33. package/Runtime/Internal.meta +8 -0
  34. package/Runtime/Public/AccessToken.cs +83 -0
  35. package/Runtime/Public/AccessToken.cs.meta +11 -0
  36. package/Runtime/Public/Profile.cs +51 -0
  37. package/Runtime/Public/Profile.cs.meta +11 -0
  38. package/Runtime/Public/TapTapAccount.cs +70 -0
  39. package/Runtime/Public/TapTapAccount.cs.meta +3 -0
  40. package/Runtime/Public/TapTapLogin.cs +39 -0
  41. package/Runtime/Public/TapTapLogin.cs.meta +3 -0
  42. package/Runtime/Public/TapTapSdk.cs +26 -0
  43. package/Runtime/Public/TapTapSdk.cs.meta +11 -0
  44. package/Runtime/Public.meta +8 -0
  45. package/Runtime/TapSDK.Login.Runtime.asmdef +15 -0
  46. package/Runtime/TapSDK.Login.Runtime.asmdef.meta +7 -0
  47. package/Runtime.meta +8 -0
  48. package/Standalone/Editor/TapLoginStandaloneProcessBuild.cs +22 -0
  49. package/Standalone/Editor/TapLoginStandaloneProcessBuild.cs.meta +11 -0
  50. package/Standalone/Editor/TapSDK.Login.Standalone.Editor.asmdef +17 -0
  51. package/Standalone/Editor/TapSDK.Login.Standalone.Editor.asmdef.meta +7 -0
  52. package/Standalone/Editor.meta +8 -0
  53. package/Standalone/Resources/Prefabs/TapLogin/LoginPanel.prefab +811 -0
  54. package/Standalone/Resources/Prefabs/TapLogin/LoginPanel.prefab.meta +8 -0
  55. package/Standalone/Resources/Prefabs/TapLogin/LoginWithPermissionPanel.prefab +820 -0
  56. package/Standalone/Resources/Prefabs/TapLogin/LoginWithPermissionPanel.prefab.meta +8 -0
  57. package/Standalone/Resources/Prefabs/TapLogin/PermissionItem.prefab +314 -0
  58. package/Standalone/Resources/Prefabs/TapLogin/PermissionItem.prefab.meta +7 -0
  59. package/Standalone/Resources/Prefabs/TapLogin/QRCodeContainer.prefab +1501 -0
  60. package/Standalone/Resources/Prefabs/TapLogin/QRCodeContainer.prefab.meta +7 -0
  61. package/Standalone/Resources/Prefabs/TapLogin/Tips.prefab +286 -0
  62. package/Standalone/Resources/Prefabs/TapLogin/Tips.prefab.meta +7 -0
  63. package/Standalone/Resources/Prefabs/TapLogin/TopBar.prefab +485 -0
  64. package/Standalone/Resources/Prefabs/TapLogin/TopBar.prefab.meta +7 -0
  65. package/Standalone/Resources/Prefabs/TapLogin/WebContainer.prefab +514 -0
  66. package/Standalone/Resources/Prefabs/TapLogin/WebContainer.prefab.meta +7 -0
  67. package/Standalone/Resources/Prefabs/TapLogin/WebWithPermissionContainer.prefab +988 -0
  68. package/Standalone/Resources/Prefabs/TapLogin/WebWithPermissionContainer.prefab.meta +7 -0
  69. package/Standalone/Resources/Prefabs/TapLogin.meta +8 -0
  70. package/Standalone/Resources/Prefabs/TapTapSdkWindow.prefab +175 -0
  71. package/Standalone/Resources/Prefabs/TapTapSdkWindow.prefab.meta +8 -0
  72. package/Standalone/Resources/Prefabs.meta +8 -0
  73. package/Standalone/Resources/Sprites/taptap-client-bg.png +0 -0
  74. package/Standalone/Resources/Sprites/taptap-client-bg.png.meta +92 -0
  75. package/Standalone/Resources/Sprites/taptap-divider.png +0 -0
  76. package/Standalone/Resources/Sprites/taptap-divider.png.meta +146 -0
  77. package/Standalone/Resources/Sprites/taptap-login-android-client.png +0 -0
  78. package/Standalone/Resources/Sprites/taptap-login-android-client.png.meta +128 -0
  79. package/Standalone/Resources/Sprites/taptap-login-auth-bg.png +0 -0
  80. package/Standalone/Resources/Sprites/taptap-login-auth-bg.png.meta +128 -0
  81. package/Standalone/Resources/Sprites/taptap-login-auth-checked-v2.png +0 -0
  82. package/Standalone/Resources/Sprites/taptap-login-auth-checked-v2.png.meta +128 -0
  83. package/Standalone/Resources/Sprites/taptap-login-auth-checked.png +0 -0
  84. package/Standalone/Resources/Sprites/taptap-login-auth-checked.png.meta +128 -0
  85. package/Standalone/Resources/Sprites/taptap-login-auth-unchecked.png +0 -0
  86. package/Standalone/Resources/Sprites/taptap-login-auth-unchecked.png.meta +128 -0
  87. package/Standalone/Resources/Sprites/taptap-login-button-bg.png +0 -0
  88. package/Standalone/Resources/Sprites/taptap-login-button-bg.png.meta +128 -0
  89. package/Standalone/Resources/Sprites/taptap-login-confirm-triangle.png +0 -0
  90. package/Standalone/Resources/Sprites/taptap-login-confirm-triangle.png.meta +128 -0
  91. package/Standalone/Resources/Sprites/taptap-login-ios-client.png +0 -0
  92. package/Standalone/Resources/Sprites/taptap-login-ios-client.png.meta +128 -0
  93. package/Standalone/Resources/Sprites/taptap-login-tips-bg.png +0 -0
  94. package/Standalone/Resources/Sprites/taptap-login-tips-bg.png.meta +128 -0
  95. package/Standalone/Resources/Sprites/taptap-logo.png +0 -0
  96. package/Standalone/Resources/Sprites/taptap-logo.png.meta +130 -0
  97. package/Standalone/Resources/Sprites/taptap-scan-tips-bg.png +0 -0
  98. package/Standalone/Resources/Sprites/taptap-scan-tips-bg.png.meta +128 -0
  99. package/Standalone/Resources/Sprites/taptap-scan-tips-error.png +0 -0
  100. package/Standalone/Resources/Sprites/taptap-scan-tips-error.png.meta +128 -0
  101. package/Standalone/Resources/Sprites/taptap-scan-tips-info.png +0 -0
  102. package/Standalone/Resources/Sprites/taptap-scan-tips-info.png.meta +128 -0
  103. package/Standalone/Resources/Sprites/taptap-scan-tips-success.png +0 -0
  104. package/Standalone/Resources/Sprites/taptap-scan-tips-success.png.meta +128 -0
  105. package/Standalone/Resources/Sprites/taptap-scan-tips-warning.png +0 -0
  106. package/Standalone/Resources/Sprites/taptap-scan-tips-warning.png.meta +128 -0
  107. package/Standalone/Resources/Sprites/taptap-sdk-bg.png +0 -0
  108. package/Standalone/Resources/Sprites/taptap-sdk-bg.png.meta +128 -0
  109. package/Standalone/Resources/Sprites/taptap-sdk-cancel.png +0 -0
  110. package/Standalone/Resources/Sprites/taptap-sdk-cancel.png.meta +128 -0
  111. package/Standalone/Resources/Sprites/taptap-sdk-guide.png +0 -0
  112. package/Standalone/Resources/Sprites/taptap-sdk-guide.png.meta +128 -0
  113. package/Standalone/Resources/Sprites/taptap-sdk-logo.png +0 -0
  114. package/Standalone/Resources/Sprites/taptap-sdk-logo.png.meta +128 -0
  115. package/Standalone/Resources/Sprites/taptap-sdk-qrcode-bg-grey.png +0 -0
  116. package/Standalone/Resources/Sprites/taptap-sdk-qrcode-bg-grey.png.meta +128 -0
  117. package/Standalone/Resources/Sprites/taptap-sdk-qrcode-bg.png +0 -0
  118. package/Standalone/Resources/Sprites/taptap-sdk-qrcode-bg.png.meta +128 -0
  119. package/Standalone/Resources/Sprites/taptap-sdk-refresh-btn-bg.png +0 -0
  120. package/Standalone/Resources/Sprites/taptap-sdk-refresh-btn-bg.png.meta +128 -0
  121. package/Standalone/Resources/Sprites/taptap-sdk-refresh.png +0 -0
  122. package/Standalone/Resources/Sprites/taptap-sdk-refresh.png.meta +128 -0
  123. package/Standalone/Resources/Sprites/taptap-tap-log-v2.png +0 -0
  124. package/Standalone/Resources/Sprites/taptap-tap-log-v2.png.meta +128 -0
  125. package/Standalone/Resources/Sprites/taptap-tap-logo.png +0 -0
  126. package/Standalone/Resources/Sprites/taptap-tap-logo.png.meta +128 -0
  127. package/Standalone/Resources/Sprites/taptap-web-login-icon-v2.png +0 -0
  128. package/Standalone/Resources/Sprites/taptap-web-login-icon-v2.png.meta +128 -0
  129. package/Standalone/Resources/Sprites/taptap-web-login-icon.png +0 -0
  130. package/Standalone/Resources/Sprites/taptap-web-login-icon.png.meta +128 -0
  131. package/Standalone/Resources/Sprites/taptap-web-login.png +0 -0
  132. package/Standalone/Resources/Sprites/taptap-web-login.png.meta +146 -0
  133. package/Standalone/Resources/Sprites.meta +8 -0
  134. package/Standalone/Resources.meta +8 -0
  135. package/Standalone/Runtime/Internal/ContainerWindow.cs +67 -0
  136. package/Standalone/Runtime/Internal/ContainerWindow.cs.meta +11 -0
  137. package/Standalone/Runtime/Internal/LoginLanguage.cs +1117 -0
  138. package/Standalone/Runtime/Internal/LoginLanguage.cs.meta +11 -0
  139. package/Standalone/Runtime/Internal/Net.cs +291 -0
  140. package/Standalone/Runtime/Internal/Net.cs.meta +11 -0
  141. package/Standalone/Runtime/Internal/QRCodeWindow.cs +776 -0
  142. package/Standalone/Runtime/Internal/QRCodeWindow.cs.meta +11 -0
  143. package/Standalone/Runtime/Internal/UI.cs +22 -0
  144. package/Standalone/Runtime/Internal/UI.cs.meta +11 -0
  145. package/Standalone/Runtime/Internal/UIAnimator.cs +77 -0
  146. package/Standalone/Runtime/Internal/UIAnimator.cs.meta +11 -0
  147. package/Standalone/Runtime/Internal/UIBase.cs +27 -0
  148. package/Standalone/Runtime/Internal/UIBase.cs.meta +11 -0
  149. package/Standalone/Runtime/Internal/UIElement.cs +185 -0
  150. package/Standalone/Runtime/Internal/UIElement.cs.meta +11 -0
  151. package/Standalone/Runtime/Internal/UIManager.cs +100 -0
  152. package/Standalone/Runtime/Internal/UIManager.cs.meta +11 -0
  153. package/Standalone/Runtime/Internal/WebLoginRequestManager.cs +185 -0
  154. package/Standalone/Runtime/Internal/WebLoginRequestManager.cs.meta +11 -0
  155. package/Standalone/Runtime/Internal.meta +8 -0
  156. package/Standalone/Runtime/Internal2/AccountManager.cs +87 -0
  157. package/Standalone/Runtime/Internal2/AccountManager.cs.meta +3 -0
  158. package/Standalone/Runtime/Internal2/AuthorizationProviderImpl.cs +13 -0
  159. package/Standalone/Runtime/Internal2/AuthorizationProviderImpl.cs.meta +3 -0
  160. package/Standalone/Runtime/Internal2/Http/LoginHttpClient.cs +139 -0
  161. package/Standalone/Runtime/Internal2/Http/LoginHttpClient.cs.meta +11 -0
  162. package/Standalone/Runtime/Internal2/Http/Response/ErrorResponse.cs +16 -0
  163. package/Standalone/Runtime/Internal2/Http/Response/ErrorResponse.cs.meta +11 -0
  164. package/Standalone/Runtime/Internal2/Http/Response/ProfileResponse.cs +28 -0
  165. package/Standalone/Runtime/Internal2/Http/Response/ProfileResponse.cs.meta +11 -0
  166. package/Standalone/Runtime/Internal2/Http/Response/QRCodeResponse.cs +22 -0
  167. package/Standalone/Runtime/Internal2/Http/Response/QRCodeResponse.cs.meta +11 -0
  168. package/Standalone/Runtime/Internal2/Http/Response/TokenResponse.cs +33 -0
  169. package/Standalone/Runtime/Internal2/Http/Response/TokenResponse.cs.meta +11 -0
  170. package/Standalone/Runtime/Internal2/Http/Response.meta +8 -0
  171. package/Standalone/Runtime/Internal2/Http.meta +8 -0
  172. package/Standalone/Runtime/Internal2/LoginService.cs +127 -0
  173. package/Standalone/Runtime/Internal2/LoginService.cs.meta +11 -0
  174. package/Standalone/Runtime/Internal2/QRCodeUtils.cs +50 -0
  175. package/Standalone/Runtime/Internal2/QRCodeUtils.cs.meta +11 -0
  176. package/Standalone/Runtime/Internal2/TapLoginStandaloneImpl.cs +181 -0
  177. package/Standalone/Runtime/Internal2/TapLoginStandaloneImpl.cs.meta +3 -0
  178. package/Standalone/Runtime/Internal2/UI/ClientButtonListener.cs +20 -0
  179. package/Standalone/Runtime/Internal2/UI/ClientButtonListener.cs.meta +11 -0
  180. package/Standalone/Runtime/Internal2/UI/LoginPanelController.cs +72 -0
  181. package/Standalone/Runtime/Internal2/UI/LoginPanelController.cs.meta +11 -0
  182. package/Standalone/Runtime/Internal2/UI/QRCodeController.cs +180 -0
  183. package/Standalone/Runtime/Internal2/UI/QRCodeController.cs.meta +11 -0
  184. package/Standalone/Runtime/Internal2/UI/TitleController.cs +20 -0
  185. package/Standalone/Runtime/Internal2/UI/TitleController.cs.meta +11 -0
  186. package/Standalone/Runtime/Internal2/UI/WebController.cs +125 -0
  187. package/Standalone/Runtime/Internal2/UI/WebController.cs.meta +11 -0
  188. package/Standalone/Runtime/Internal2/UI.meta +8 -0
  189. package/Standalone/Runtime/Internal2.meta +8 -0
  190. package/Standalone/Runtime/Public/IAuthorizationProvider.cs +9 -0
  191. package/Standalone/Runtime/Public/IAuthorizationProvider.cs.meta +3 -0
  192. package/Standalone/Runtime/Public/IComplianceProvider.cs +7 -0
  193. package/Standalone/Runtime/Public/IComplianceProvider.cs.meta +3 -0
  194. package/Standalone/Runtime/Public/TapTapLoginStandalone.cs +38 -0
  195. package/Standalone/Runtime/Public/TapTapLoginStandalone.cs.meta +3 -0
  196. package/Standalone/Runtime/Public.meta +8 -0
  197. package/Standalone/Runtime/TapSDK.Login.Standalone.Runtime.asmdef +24 -0
  198. package/Standalone/Runtime/TapSDK.Login.Standalone.Runtime.asmdef.meta +7 -0
  199. package/Standalone/Runtime.meta +8 -0
  200. package/Standalone.meta +8 -0
  201. package/package.json +11 -0
  202. package/package.json.meta +7 -0
@@ -0,0 +1,87 @@
1
+ using System.Collections.Generic;
2
+ using JetBrains.Annotations;
3
+ using Newtonsoft.Json;
4
+ using TapSDK.Core;
5
+
6
+ namespace TapSDK.Login.Internal
7
+ {
8
+ public class AccountManager
9
+ {
10
+ private static readonly string _accessToken = "taptapsdk_accesstoken";
11
+ private static readonly string _profile = "taptapsdk_profile";
12
+ private static readonly string _account = "taptapsdk_account";
13
+
14
+ private static AccountManager _instance;
15
+
16
+ private AccountManager()
17
+ {
18
+ }
19
+
20
+ public static AccountManager Instance
21
+ {
22
+ get
23
+ {
24
+ if (_instance == null)
25
+ {
26
+ _instance = new AccountManager();
27
+ // 自动初始化
28
+ _instance.Init();
29
+ }
30
+ return _instance;
31
+ }
32
+ }
33
+
34
+ private TapTapAccount _tapAccount;
35
+ [CanBeNull]
36
+ public TapTapAccount Account
37
+ {
38
+ get
39
+ {
40
+ return _tapAccount;
41
+ }
42
+ set
43
+ {
44
+ _tapAccount = value;
45
+ if (value == null)
46
+ {
47
+ DataStorage.SaveString(_account, null);
48
+ }
49
+ else
50
+ {
51
+ DataStorage.SaveString(_account, value.ToJson());
52
+ }
53
+ }
54
+ }
55
+
56
+ public void Init()
57
+ {
58
+ var accountStr = DataStorage.LoadString(_account);
59
+ if (!string.IsNullOrEmpty(accountStr))
60
+ {
61
+ Account = new TapTapAccount(Json.Deserialize(accountStr) as Dictionary<string, object>);
62
+ }
63
+ else
64
+ {
65
+ var accessTokenStr = DataStorage.LoadString(_accessToken);
66
+ if (string.IsNullOrEmpty(accessTokenStr))
67
+ {
68
+ return;
69
+ }
70
+
71
+ var profileStr = DataStorage.LoadString(_profile);
72
+ if (string.IsNullOrEmpty(profileStr))
73
+ {
74
+ return;
75
+ }
76
+ var accessToken = JsonConvert.DeserializeObject<AccessToken>(accessTokenStr);
77
+ var profile = JsonConvert.DeserializeObject<Profile>(profileStr);
78
+ Account = new TapTapAccount(accessToken, profile.openid, profile.unionid, profile.name, profile.avatar, profile.email);
79
+ }
80
+ }
81
+
82
+ public void ClearCache()
83
+ {
84
+ Account = null;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 000f0a993f0348ffb92533caedcdcce3
3
+ timeCreated: 1716541112
@@ -0,0 +1,13 @@
1
+ using System.Threading.Tasks;
2
+ using TapSDK.Login.Standalone;
3
+
4
+ namespace TapSDK.Login.Internal
5
+ {
6
+ public class AuthorizationProviderImpl : IAuthorizationProvider
7
+ {
8
+ public Task<AccessToken> Authorize(string[] scopes = null)
9
+ {
10
+ return TapLoginStandaloneImpl.Instance.Authorize(scopes);
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 4afa00fbfdd84703a615d052000a9888
3
+ timeCreated: 1717472965
@@ -0,0 +1,139 @@
1
+ using System;
2
+ using System.Net;
3
+ using System.Text;
4
+ using System.Linq;
5
+ using System.Collections.Generic;
6
+ using System.Net.Http;
7
+ using System.Net.Http.Headers;
8
+ using System.Threading.Tasks;
9
+ using System.Security.Cryptography;
10
+ using Newtonsoft.Json;
11
+ using TapSDK.Core;
12
+ using TapSDK.Core.Internal.Json;
13
+ using TapSDK.Core.Internal.Http;
14
+
15
+ namespace TapSDK.Login.Internal.Http {
16
+ public class LoginHttpClient {
17
+ private readonly HttpClient client;
18
+
19
+ public LoginHttpClient() {
20
+ client = new HttpClient();
21
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
22
+ }
23
+
24
+ public Task<T> Get<T>(string url,
25
+ Dictionary<string, object> headers = null,
26
+ Dictionary<string, object> queryParams = null) {
27
+ return Request<T>(url, HttpMethod.Get, headers, null, queryParams);
28
+ }
29
+
30
+ public Task<T> Post<T>(string url,
31
+ Dictionary<string, object> headers = null,
32
+ object data = null,
33
+ Dictionary<string, object> queryParams = null) {
34
+ return Request<T>(url, HttpMethod.Post, headers, data, queryParams);
35
+ }
36
+
37
+ public Task<T> Put<T>(string url,
38
+ Dictionary<string, object> headers = null,
39
+ object data = null,
40
+ Dictionary<string, object> queryParams = null) {
41
+ return Request<T>(url, HttpMethod.Put, headers, data, queryParams);
42
+ }
43
+
44
+ public Task Delete(string url,
45
+ Dictionary<string, object> headers = null,
46
+ object data = null,
47
+ Dictionary<string, object> queryParams = null) {
48
+ return Request<Dictionary<string, object>>(url, HttpMethod.Delete, headers, data, queryParams);
49
+ }
50
+
51
+ async Task<T> Request<T>(string url,
52
+ HttpMethod method,
53
+ Dictionary<string, object> headers = null,
54
+ object data = null,
55
+ Dictionary<string, object> queryParams = null) {
56
+ url = BuildUrl(url, queryParams);
57
+ HttpRequestMessage request = new HttpRequestMessage {
58
+ RequestUri = new Uri(url),
59
+ Method = method,
60
+ };
61
+ FillHeaders(request.Headers, headers);
62
+
63
+ string content = null;
64
+ if (data != null) {
65
+ content = JsonConvert.SerializeObject(data);
66
+ Dictionary<string, string> formData = JsonConvert.DeserializeObject<Dictionary<string, object>>(content)
67
+ .ToDictionary(item => item.Key, item => item.Value.ToString());
68
+ FormUrlEncodedContent requestContent = new FormUrlEncodedContent(formData);
69
+ request.Content = requestContent;
70
+ }
71
+ TapHttpUtils.PrintRequest(client, request, content);
72
+ HttpResponseMessage response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
73
+ request.Dispose();
74
+
75
+ string resultString = await response.Content.ReadAsStringAsync();
76
+ response.Dispose();
77
+ TapHttpUtils.PrintResponse(response, resultString);
78
+
79
+ if (response.IsSuccessStatusCode) {
80
+ T ret = JsonConvert.DeserializeObject<T>(resultString,
81
+ TapJsonConverter.Default);
82
+ return ret;
83
+ }
84
+ throw HandleErrorResponse(response.StatusCode, resultString);
85
+ }
86
+
87
+ TapException HandleErrorResponse(HttpStatusCode statusCode, string responseContent) {
88
+ int code = (int)statusCode;
89
+ string message = responseContent;
90
+ try {
91
+ ErrorResponse response = JsonConvert.DeserializeObject<ErrorResponse>(responseContent,
92
+ TapJsonConverter.Default);
93
+ code = response.Data.Code;
94
+ message = response.Data.Error;
95
+ } catch (Exception e) {
96
+ TapLogger.Error(e);
97
+ }
98
+ return new TapException(code, message);
99
+ }
100
+
101
+ string BuildUrl(string url, Dictionary<string, object> queryParams) {
102
+ if (queryParams != null) {
103
+ IEnumerable<string> queryPairs = queryParams.Select(kv => $"{kv.Key}={kv.Value}");
104
+ string queries = string.Join("&", queryPairs);
105
+ url = $"{url}?{queries}";
106
+ }
107
+ return url;
108
+ }
109
+
110
+ void FillHeaders(HttpRequestHeaders headers, Dictionary<string, object> reqHeaders = null) {
111
+ // 额外 headers
112
+ if (reqHeaders != null) {
113
+ foreach (KeyValuePair<string, object> kv in reqHeaders) {
114
+ headers.Add(kv.Key, kv.Value.ToString());
115
+ }
116
+ }
117
+
118
+ // 签名
119
+ long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
120
+ string hash = GetMd5Hash($"{timestamp}");
121
+ string sign = $"{hash},{timestamp}";
122
+ headers.Add("X-LC-Sign", sign);
123
+ }
124
+
125
+ static string GetMd5Hash(string input) {
126
+ MD5 md5 = MD5.Create();
127
+ byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
128
+ return ToHex(data);
129
+ }
130
+
131
+ static string ToHex(byte[] bytes) {
132
+ StringBuilder sb = new StringBuilder();
133
+ for (int i = 0; i < bytes.Length; i++) {
134
+ sb.Append(bytes[i].ToString("x2"));
135
+ }
136
+ return sb.ToString();
137
+ }
138
+ }
139
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: e3ed262175bd04db487ef5c3f3b5953d
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,16 @@
1
+ using Newtonsoft.Json;
2
+
3
+ namespace TapSDK.Login.Internal.Http {
4
+ public class ErrorData {
5
+ [JsonProperty("code")]
6
+ public int Code { get; set; }
7
+
8
+ [JsonProperty("error")]
9
+ public string Error { get; set; }
10
+ }
11
+
12
+ public class ErrorResponse {
13
+ [JsonProperty("data")]
14
+ public ErrorData Data { get; set; }
15
+ }
16
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: bf3ced9270c8442a4a7c2158841ccad8
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,28 @@
1
+ using Newtonsoft.Json;
2
+
3
+ namespace TapSDK.Login.Internal.Http {
4
+ public class ProfileData {
5
+ [JsonProperty("openid")]
6
+ public string OpenId { get; set; }
7
+
8
+ [JsonProperty("unionid")]
9
+ public string UnionId { get; set; }
10
+
11
+ [JsonProperty("name")]
12
+ public string Name { get; set; }
13
+
14
+ [JsonProperty("gender")]
15
+ public string Gender { get; set; }
16
+
17
+ [JsonProperty("avatar")]
18
+ public string Avatar { get; set; }
19
+
20
+ [JsonProperty("email")]
21
+ public string Email { get; set; }
22
+ }
23
+
24
+ public class ProfileResponse {
25
+ [JsonProperty("data")]
26
+ public ProfileData Data { get; set; }
27
+ }
28
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 16259047d4b9747abaa4b18eb025c892
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,22 @@
1
+ using Newtonsoft.Json;
2
+
3
+ namespace TapSDK.Login.Internal.Http {
4
+ public class QRCodeData {
5
+ [JsonProperty("device_code")]
6
+ public string DeviceCode { get; set; }
7
+
8
+ [JsonProperty("expires_in")]
9
+ public int ExpiresIn { get; set; }
10
+
11
+ [JsonProperty("qrcode_url")]
12
+ public string Url { get; set; }
13
+
14
+ [JsonProperty("interval")]
15
+ public int Interval { get; set; }
16
+ }
17
+
18
+ public class QRCodeResponse {
19
+ [JsonProperty("data")]
20
+ public QRCodeData Data { get; set; }
21
+ }
22
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 81871766831eb47929aefc635473d845
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,33 @@
1
+ using System.Collections.Generic;
2
+ using Newtonsoft.Json;
3
+
4
+ namespace TapSDK.Login.Internal.Http {
5
+ public class TokenData {
6
+ [JsonProperty("kid")]
7
+ public string Kid { get; set; }
8
+
9
+ [JsonProperty("access_token")]
10
+ public string Token { get; set; }
11
+
12
+ [JsonProperty("token_type")]
13
+ public string TokenType { get; set; }
14
+
15
+ [JsonProperty("mac_key")]
16
+ public string MacKey { get; set; }
17
+
18
+ [JsonProperty("mac_algorithm")]
19
+ public string MacAlgorithm { get; set; }
20
+
21
+ [JsonProperty("scope")]
22
+ public string Scope { get; set; }
23
+
24
+ [JsonIgnore]
25
+ public HashSet<string> Scopes => !string.IsNullOrEmpty(Scope) ?
26
+ new HashSet<string>(Scope.Split(' ')) : new HashSet<string>();
27
+ }
28
+
29
+ public class TokenResponse {
30
+ [JsonProperty("data")]
31
+ public TokenData Data { get; set; }
32
+ }
33
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 02cfc0b8c410e4527b7b4e08132c5ce1
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,8 @@
1
+ fileFormatVersion: 2
2
+ guid: c7cfaec1f91674907b9e60848f8985a6
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: cf54312312aa74a45898b86903cf0115
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,127 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Threading.Tasks;
4
+ using System.Security.Cryptography;
5
+ using System.Text;
6
+ using UnityEngine;
7
+ using TapSDK.Login.Internal.Http;
8
+
9
+ namespace TapSDK.Login.Internal {
10
+ public static class LoginService {
11
+ private static readonly LoginHttpClient httpClient = new LoginHttpClient();
12
+
13
+ public static LoginHttpClient HttpClient => httpClient;
14
+
15
+ public static async Task<QRCodeData> GetQRCodeUrl(string clientId, string[] scopes) {
16
+ Dictionary<string, object> data = new Dictionary<string, object> {
17
+ { "client_id", clientId },
18
+ { "response_type", "device_code" },
19
+ { "scope", string.Join(",", scopes) },
20
+ { "version", TapTapSdk.Version },
21
+ { "platform", "unity" },
22
+ { "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
23
+ };
24
+ QRCodeResponse response = await httpClient.Post<QRCodeResponse>(TapTapSdk.CurrentRegion.CodeUrl(),
25
+ data: data);
26
+ return response.Data;
27
+ }
28
+
29
+ public static async Task<TokenData> Authorize(string clientId, string code) {
30
+ Dictionary<string, string> data = new Dictionary<string, string> {
31
+ { "client_id", clientId },
32
+ { "grant_type", "authorization_code" },
33
+ { "secret_type", "hmac-sha-1" },
34
+ { "code", code },
35
+ { "redirect_uri", WebLoginRequestManager.Instance.GetCurrentRequest().GetRedirectUri() },
36
+ { "code_verifier", WebLoginRequestManager.Instance.GetCodeVerifier() }
37
+ };
38
+ TokenResponse response = await httpClient.Post<TokenResponse>(TapTapSdk.CurrentRegion.TokenUrl(),
39
+ data: data);
40
+ return response.Data;
41
+ }
42
+
43
+ public static async Task<TokenData> RequestScanQRCodeResult(string clientId, string deviceCode) {
44
+ Dictionary<string, string> data = new Dictionary<string, string> {
45
+ { "grant_type", "device_token" },
46
+ { "client_id", clientId },
47
+ { "secret_type", "hmac-sha-1" },
48
+ { "code", deviceCode },
49
+ { "version", "1.0" },
50
+ { "platform", "unity" },
51
+ { "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
52
+ };
53
+ TokenResponse response = await httpClient.Post<TokenResponse>(TapTapSdk.CurrentRegion.TokenUrl(),
54
+ data: data);
55
+ return response.Data;
56
+ }
57
+
58
+ public static async Task<ProfileData> GetProfile(string clientId, AccessToken token, int timestamp = 0) {
59
+ string url = TapTapSdk.CurrentRegion.ProfileUrl(token.scopeSet.Contains(TapTapLogin.TAP_LOGIN_SCOPE_PUBLIC_PROFILE)) + clientId;
60
+ var uri = new Uri(url);
61
+ var ts = timestamp;
62
+ if (ts == 0) {
63
+ var dt = DateTime.UtcNow - new DateTime(1970, 1, 1);
64
+ ts = (int)dt.TotalSeconds;
65
+ }
66
+ var sign = "MAC " + GetAuthorizationHeader(token.kid,
67
+ token.macKey,
68
+ token.macAlgorithm,
69
+ "GET",
70
+ uri.PathAndQuery,
71
+ uri.Host,
72
+ "443", ts);
73
+ Dictionary<string, object> headers = new Dictionary<string, object> {
74
+ { "Authorization", sign }
75
+ };
76
+ ProfileResponse response = await httpClient.Get<ProfileResponse>(url, headers: headers);
77
+ return response.Data;
78
+ }
79
+
80
+ public static string GetAuthorizationHeader(string kid,
81
+ string macKey,
82
+ string macAlgorithm,
83
+ string method,
84
+ string uri,
85
+ string host,
86
+ string port,
87
+ int timestamp) {
88
+ var nonce = new System.Random().Next().ToString();
89
+
90
+ var normalizedString = $"{timestamp}\n{nonce}\n{method}\n{uri}\n{host}\n{port}\n\n";
91
+
92
+ HashAlgorithm hashGenerator;
93
+ switch (macAlgorithm) {
94
+ case "hmac-sha-256":
95
+ hashGenerator = new HMACSHA256(Encoding.ASCII.GetBytes(macKey));
96
+ break;
97
+ case "hmac-sha-1":
98
+ hashGenerator = new HMACSHA1(Encoding.ASCII.GetBytes(macKey));
99
+ break;
100
+ default:
101
+ throw new InvalidOperationException("Unsupported MAC algorithm");
102
+ }
103
+
104
+ var hash = Convert.ToBase64String(hashGenerator.ComputeHash(Encoding.ASCII.GetBytes(normalizedString)));
105
+
106
+ var authorizationHeader = new StringBuilder();
107
+ authorizationHeader.AppendFormat(@"id=""{0}"",ts=""{1}"",nonce=""{2}"",mac=""{3}""",
108
+ kid, timestamp, nonce, hash);
109
+
110
+ return authorizationHeader.ToString();
111
+ }
112
+
113
+ public static async Task<TokenData> RefreshToken(string clientId, string accessToken) {
114
+ Dictionary<string, object> data = new Dictionary<string, object> {
115
+ { "client_id", clientId },
116
+ { "grant_type", "refresh_token" },
117
+ { "token", accessToken },
118
+ { "token_type_hint", "access_token" },
119
+ { "platform", "unity" },
120
+ { "info", "{\"device_id\":\"" + SystemInfo.deviceModel + "\"}" }
121
+ };
122
+ TokenResponse response = await httpClient.Post<TokenResponse>(TapTapSdk.CurrentRegion.TokenUrl(),
123
+ data: data);
124
+ return response.Data;
125
+ }
126
+ }
127
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: e5e1eebabeb1f4001885b94c35d317f2
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,50 @@
1
+ using System.Collections.Generic;
2
+ using ZXing;
3
+ using ZXing.Common;
4
+ using ZXing.QrCode.Internal;
5
+ using UnityEngine;
6
+
7
+ namespace TapSDK.Login.Internal {
8
+ public class QRCodeUtils {
9
+ public static Texture2D EncodeQrImage(string content, int width, int height) {
10
+ var writer = new MultiFormatWriter();
11
+ var hints = new Dictionary<EncodeHintType, object> {
12
+ { EncodeHintType.CHARACTER_SET, "UTF-8" },
13
+ //hints.Add(EncodeHintType.MARGIN, 0);
14
+ { EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M }
15
+ };
16
+ var bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
17
+ bitMatrix = DeleteWhite(bitMatrix);
18
+ var w = bitMatrix.Width;
19
+ var h = bitMatrix.Height;
20
+ var texture = new Texture2D(w, h);
21
+ for (var x = 0; x < h; x++) {
22
+ for (var y = 0; y < w; y++) {
23
+ texture.SetPixel(y, x, bitMatrix[x, y] ? Color.black : Color.white);
24
+ }
25
+ }
26
+
27
+ texture.Apply();
28
+ texture.filterMode = FilterMode.Point;
29
+ return texture;
30
+ }
31
+
32
+ private static BitMatrix DeleteWhite(BitMatrix matrix) {
33
+ var rec = matrix.getEnclosingRectangle();
34
+ var resWidth = rec[2];
35
+ var resHeight = rec[3];
36
+
37
+ var resMatrix = new BitMatrix(resWidth, resHeight);
38
+ resMatrix.clear();
39
+ for (var i = 0; i < resWidth; i++) {
40
+ for (var j = 0; j < resHeight; j++){
41
+ if (matrix[i + rec[0], j + rec[1]]) {
42
+ resMatrix.flip(i, j);
43
+ }
44
+ }
45
+ }
46
+
47
+ return resMatrix;
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 5e9daa576463f46d49306d4cd1bb163f
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: