com.xd.sdk.account 0.0.1 → 0.0.10-alpha

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 (191) hide show
  1. package/Plugins/Android/libs/XDGAccount_7.0.0.aar +0 -0
  2. package/{Mobile/Plugins/Android/com/xd/account/bridge/XDGAccountBridge.java.meta → Plugins/Android/libs/XDGAccount_7.0.0.aar.meta} +2 -2
  3. package/Plugins/Android/libs/XDGSupport_7.0.0.aar +0 -0
  4. package/Plugins/Android/libs/{XDGAccount_6.21.1.aar.meta → XDGSupport_7.0.0.aar.meta} +2 -2
  5. package/Plugins/Android/libs.meta +1 -1
  6. package/Plugins/Android.meta +1 -1
  7. package/Plugins/iOS/XDAccountSDK.framework/Headers/TDSGlobalThirdPartyLoginHelper.h +4 -9
  8. package/Plugins/iOS/XDAccountSDK.framework/Headers/TDSGlobalThirdPartyLoginHelper.h.meta +1 -1
  9. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDAccountSDK-Swift.h +329 -0
  10. package/Plugins/iOS/XDAccountSDK.framework/Headers/{TDSGlobalThirdPartyLoginManager.h.meta → XDAccountSDK-Swift.h.meta} +1 -1
  11. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDAccountSDK.h +2 -2
  12. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDAccountSDK.h.meta +1 -1
  13. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGAccount.h +36 -44
  14. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGAccount.h.meta +1 -1
  15. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGAccountDefines.h +43 -0
  16. package/Plugins/iOS/XDAccountSDK.framework/Headers/{XDGPhoneAuthManager.h.meta → XDGAccountDefines.h.meta} +1 -1
  17. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGAccountVersion.h +3 -2
  18. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGAccountVersion.h.meta +1 -1
  19. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGLogger+Account.h +3 -0
  20. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGLogger+Account.h.meta +1 -1
  21. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGLoginEntriesConfig.h.meta +1 -1
  22. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGLoginService.h.meta +1 -1
  23. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGTapLoginPermissionDialog.h.meta +1 -1
  24. package/Plugins/iOS/XDAccountSDK.framework/Headers.meta +1 -1
  25. package/Plugins/iOS/XDAccountSDK.framework/Info.plist +0 -0
  26. package/Plugins/iOS/XDAccountSDK.framework/Info.plist.meta +1 -1
  27. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  28. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo.meta +7 -0
  29. package/{Mobile/Http.meta → Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/Project.meta} +1 -1
  30. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.abi.json +9 -0
  31. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.abi.json.meta +7 -0
  32. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  33. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.swiftdoc.meta +7 -0
  34. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.swiftmodule +0 -0
  35. package/Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule/arm64-apple-ios.swiftmodule.meta +7 -0
  36. package/{Mobile/Editor.meta → Plugins/iOS/XDAccountSDK.framework/Modules/XDAccountSDK.swiftmodule.meta} +1 -1
  37. package/Plugins/iOS/XDAccountSDK.framework/Modules/module.modulemap.meta +1 -1
  38. package/Plugins/iOS/XDAccountSDK.framework/Modules.meta +1 -1
  39. package/Plugins/iOS/XDAccountSDK.framework/XDAccountSDK +0 -0
  40. package/Plugins/iOS/XDAccountSDK.framework/XDAccountSDK.meta +1 -1
  41. package/Plugins/iOS/XDAccountSDK.framework.meta +57 -4
  42. package/Plugins/iOS.meta +1 -1
  43. package/Plugins.meta +1 -1
  44. package/Runtime/Internal/IXDGAccount.Extended.cs +11 -0
  45. package/{Mobile/Http/XDGAccountHttpConfigMobile.cs.meta → Runtime/Internal/IXDGAccount.Extended.cs.meta} +1 -1
  46. package/Runtime/Internal/Mobile/AccountFeaturesImpl.cs +341 -0
  47. package/{Mobile/XDGAccountMobile.cs.meta → Runtime/Internal/Mobile/AccountFeaturesImpl.cs.meta} +1 -1
  48. package/Runtime/Internal/Mobile/Http/LoginSyncResponse.cs +14 -0
  49. package/Runtime/Internal/Mobile/Http/LoginSyncResponse.cs.meta +3 -0
  50. package/Runtime/Internal/Mobile/Http/MacAuthenticationInterceptor.cs +37 -0
  51. package/Runtime/Internal/Mobile/Http/MacAuthenticationInterceptor.cs.meta +3 -0
  52. package/Runtime/Internal/Mobile/Http.meta +3 -0
  53. package/{Mobile.meta → Runtime/Internal/Mobile.meta} +1 -1
  54. package/Runtime/Internal/Standalone/AccessToken/AccessTokenModule.cs +168 -0
  55. package/{Mobile/Editor/XDAccountMobileProcessBuild.cs.meta → Runtime/Internal/Standalone/AccessToken/AccessTokenModule.cs.meta} +1 -1
  56. package/Runtime/Internal/Standalone/AccessToken.meta +8 -0
  57. package/Runtime/Internal/Standalone/AccountCell.cs +143 -0
  58. package/{Mobile/XDGAccountMobileImpl.cs.meta → Runtime/Internal/Standalone/AccountCell.cs.meta} +1 -1
  59. package/Runtime/Internal/Standalone/AccountFeaturesImpl.cs +452 -0
  60. package/Runtime/Internal/Standalone/AccountFeaturesImpl.cs.meta +11 -0
  61. package/Runtime/Internal/Standalone/Auth/AppleAuth.cs +27 -0
  62. package/Runtime/Internal/Standalone/Auth/AppleAuth.cs.meta +11 -0
  63. package/Runtime/Internal/Standalone/Auth/FacebookAuth.cs +27 -0
  64. package/Runtime/Internal/Standalone/Auth/FacebookAuth.cs.meta +11 -0
  65. package/Runtime/Internal/Standalone/Auth/GoogleAuth.cs +27 -0
  66. package/Runtime/Internal/Standalone/Auth/GoogleAuth.cs.meta +11 -0
  67. package/Runtime/Internal/Standalone/Auth/GuestAuth.cs +22 -0
  68. package/Runtime/Internal/Standalone/Auth/GuestAuth.cs.meta +11 -0
  69. package/Runtime/Internal/Standalone/Auth/PhoneAuth.cs +43 -0
  70. package/Runtime/Internal/Standalone/Auth/PhoneAuth.cs.meta +11 -0
  71. package/Runtime/Internal/Standalone/Auth/SteamAuth.cs +90 -0
  72. package/Runtime/Internal/Standalone/Auth/SteamAuth.cs.meta +11 -0
  73. package/Runtime/Internal/Standalone/Auth/TapAuth.cs +72 -0
  74. package/Runtime/Internal/Standalone/Auth/TapAuth.cs.meta +11 -0
  75. package/Runtime/Internal/Standalone/Auth/WebAuth.cs +144 -0
  76. package/Runtime/Internal/Standalone/Auth/WebAuth.cs.meta +11 -0
  77. package/Runtime/Internal/Standalone/Auth.meta +8 -0
  78. package/Runtime/Internal/Standalone/LoginModule/Email/EmailModule.cs +374 -0
  79. package/Runtime/Internal/Standalone/LoginModule/Email/EmailModule.cs.meta +11 -0
  80. package/Runtime/Internal/Standalone/LoginModule/Email.meta +8 -0
  81. package/Runtime/Internal/Standalone/LoginModule/Phone/PhoneModule.cs +245 -0
  82. package/Runtime/Internal/Standalone/LoginModule/Phone/PhoneModule.cs.meta +11 -0
  83. package/Runtime/Internal/Standalone/LoginModule/Phone/PhoneModuleIO.cs +392 -0
  84. package/Runtime/Internal/Standalone/LoginModule/Phone/PhoneModuleIO.cs.meta +11 -0
  85. package/Runtime/Internal/Standalone/LoginModule/Phone.meta +8 -0
  86. package/Runtime/Internal/Standalone/LoginModule.meta +8 -0
  87. package/Runtime/Internal/Standalone/SupportModule/SupportModule.cs +200 -0
  88. package/Runtime/Internal/Standalone/SupportModule/SupportModule.cs.meta +3 -0
  89. package/Runtime/Internal/Standalone/SupportModule/SupportResponse.cs +27 -0
  90. package/Runtime/Internal/Standalone/SupportModule/SupportResponse.cs.meta +3 -0
  91. package/Runtime/Internal/Standalone/SupportModule.meta +3 -0
  92. package/Runtime/Internal/Standalone/Track/AliyunTrack.Login.cs +479 -0
  93. package/Runtime/Internal/Standalone/Track/AliyunTrack.Login.cs.meta +11 -0
  94. package/Runtime/Internal/Standalone/Track.meta +8 -0
  95. package/Runtime/Internal/Standalone/UI/CodeUnbindAlert.cs +156 -0
  96. package/Runtime/Internal/Standalone/UI/CodeUnbindAlert.cs.meta +11 -0
  97. package/Runtime/Internal/Standalone/UI/Email/EmailAlert.cs +295 -0
  98. package/Runtime/Internal/Standalone/UI/Email/EmailAlert.cs.meta +11 -0
  99. package/Runtime/Internal/Standalone/UI/Email.meta +8 -0
  100. package/Runtime/Internal/Standalone/UI/PhoneIO/AreaCodeCell.cs +46 -0
  101. package/Runtime/Internal/Standalone/UI/PhoneIO/AreaCodeCell.cs.meta +11 -0
  102. package/Runtime/Internal/Standalone/UI/PhoneIO/PhoneAlertIO.cs +522 -0
  103. package/Runtime/Internal/Standalone/UI/PhoneIO/PhoneAlertIO.cs.meta +11 -0
  104. package/Runtime/Internal/Standalone/UI/PhoneIO.meta +8 -0
  105. package/Runtime/Internal/Standalone/UI/PhoneVerification/PhoneNumberInputAlert.cs +84 -0
  106. package/Runtime/Internal/Standalone/UI/PhoneVerification/PhoneNumberInputAlert.cs.meta +11 -0
  107. package/Runtime/Internal/Standalone/UI/PhoneVerification/RiskControlAlert.cs +190 -0
  108. package/Runtime/Internal/Standalone/UI/PhoneVerification/RiskControlAlert.cs.meta +11 -0
  109. package/Runtime/Internal/Standalone/UI/PhoneVerification/VerifyCodeInputAlert.cs +164 -0
  110. package/Runtime/Internal/Standalone/UI/PhoneVerification/VerifyCodeInputAlert.cs.meta +11 -0
  111. package/Runtime/Internal/Standalone/UI/PhoneVerification.meta +8 -0
  112. package/Runtime/Internal/Standalone/UI.meta +8 -0
  113. package/Runtime/Internal/Standalone/UserCenterAlert.cs +405 -0
  114. package/Runtime/Internal/Standalone/UserCenterAlert.cs.meta +11 -0
  115. package/Runtime/Internal/Standalone/UserModule.cs +597 -0
  116. package/Runtime/Internal/Standalone/UserModule.cs.meta +11 -0
  117. package/Runtime/Internal/Standalone/WebFunction/AccessTokenWebFunction.cs +47 -0
  118. package/Runtime/Internal/Standalone/WebFunction/AccessTokenWebFunction.cs.meta +3 -0
  119. package/Runtime/Internal/Standalone/WebFunction.meta +3 -0
  120. package/{Mobile/Plugins.meta → Runtime/Internal/Standalone.meta} +1 -1
  121. package/Runtime/Internal/XDGAccountEventHandler.cs +21 -0
  122. package/Runtime/Internal/XDGAccountEventHandler.cs.meta +3 -0
  123. package/Runtime/Internal/XDGAccountInternal.cs +87 -0
  124. package/Runtime/Internal/XDGAccountInternal.cs.meta +11 -0
  125. package/Runtime/Internal.meta +1 -1
  126. package/Runtime/Public/XDGAccount.Deprecated.cs +37 -0
  127. package/Runtime/Public/XDGAccount.Deprecated.cs.meta +11 -0
  128. package/Runtime/Public/XDGAccount.cs +107 -0
  129. package/Runtime/Public/XDGAccount.cs.meta +11 -0
  130. package/Runtime/Public.meta +8 -0
  131. package/Runtime/XD.SDK.Account.asmdef +7 -2
  132. package/Runtime/XD.SDK.Account.asmdef.meta +1 -1
  133. package/Runtime.meta +7 -2
  134. package/package.json +5 -5
  135. package/package.json.meta +2 -2
  136. package/Mobile/Editor/XD.SDK.Account.Mobile.Editor.asmdef +0 -20
  137. package/Mobile/Editor/XD.SDK.Account.Mobile.Editor.asmdef.meta +0 -7
  138. package/Mobile/Editor/XDAccountMobileProcessBuild.cs +0 -20
  139. package/Mobile/Http/XDGAccountHttpConfigMobile.cs +0 -36
  140. package/Mobile/Plugins/Android/com/xd/account/bridge/XDGAccountBridge.java +0 -15
  141. package/Mobile/Plugins/Android/com/xd/account/bridge.meta +0 -8
  142. package/Mobile/Plugins/Android/com/xd/account.meta +0 -8
  143. package/Mobile/Plugins/Android/com/xd.meta +0 -8
  144. package/Mobile/Plugins/Android/com.meta +0 -8
  145. package/Mobile/Plugins/Android.meta +0 -8
  146. package/Mobile/Plugins/iOS/XDAccountBridge.m +0 -26
  147. package/Mobile/Plugins/iOS/XDAccountBridge.m.meta +0 -37
  148. package/Mobile/Plugins/iOS.meta +0 -8
  149. package/Mobile/User/UserManagerMobile.cs +0 -45
  150. package/Mobile/User/UserManagerMobile.cs.meta +0 -3
  151. package/Mobile/User.meta +0 -3
  152. package/Mobile/XD.SDK.Account.Mobile.asmdef +0 -23
  153. package/Mobile/XD.SDK.Account.Mobile.asmdef.meta +0 -7
  154. package/Mobile/XDGAccountMobile.cs +0 -132
  155. package/Mobile/XDGAccountMobileImpl.cs +0 -421
  156. package/Mobile/XDGTokenManager.cs +0 -116
  157. package/Mobile/XDGTokenManager.cs.meta +0 -3
  158. package/Mobile/XDGUserWrapper.cs +0 -167
  159. package/Mobile/XDGUserWrapper.cs.meta +0 -11
  160. package/Plugins/Android/libs/XDGAccount_6.21.1.aar +0 -0
  161. package/Plugins/iOS/XDAccountSDK.framework/Headers/TDSGlobalThirdPartyLoginManager.h +0 -47
  162. package/Plugins/iOS/XDAccountSDK.framework/Headers/XDGPhoneAuthManager.h +0 -33
  163. package/README.md +0 -0
  164. package/README.md.meta +0 -7
  165. package/Runtime/Editor/XD.SDK.Account.Editor.asmdef +0 -19
  166. package/Runtime/Editor/XD.SDK.Account.Editor.asmdef.meta +0 -7
  167. package/Runtime/Editor/XDAccountProcessBuild.cs +0 -18
  168. package/Runtime/Editor/XDAccountProcessBuild.cs.meta +0 -11
  169. package/Runtime/Editor.meta +0 -8
  170. package/Runtime/IXDGAccount.cs +0 -42
  171. package/Runtime/IXDGAccount.cs.meta +0 -3
  172. package/Runtime/Internal/Http/IXDAccountHttpConfig.cs +0 -9
  173. package/Runtime/Internal/Http/IXDAccountHttpConfig.cs.meta +0 -11
  174. package/Runtime/Internal/Http/XDAccountHttpConfig.cs +0 -32
  175. package/Runtime/Internal/Http/XDAccountHttpConfig.cs.meta +0 -11
  176. package/Runtime/Internal/Http.meta +0 -8
  177. package/Runtime/Internal/User/IUserManagerPlatformWrapper.cs +0 -7
  178. package/Runtime/Internal/User/IUserManagerPlatformWrapper.cs.meta +0 -3
  179. package/Runtime/Internal/User.meta +0 -3
  180. package/Runtime/UserManager.cs +0 -35
  181. package/Runtime/UserManager.cs.meta +0 -3
  182. package/Runtime/XDGAccessToken.cs +0 -18
  183. package/Runtime/XDGAccessToken.cs.meta +0 -3
  184. package/Runtime/XDGAccount.cs +0 -123
  185. package/Runtime/XDGAccount.cs.meta +0 -3
  186. package/Runtime/XDGLoginType.cs +0 -28
  187. package/Runtime/XDGLoginType.cs.meta +0 -3
  188. package/Runtime/XDGUser.cs +0 -30
  189. package/Runtime/XDGUser.cs.meta +0 -3
  190. package/Runtime/XDGUserStatusCode.cs +0 -16
  191. package/Runtime/XDGUserStatusCode.cs.meta +0 -3
@@ -0,0 +1,597 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+ using System;
3
+ using System.IO;
4
+ using System.Threading.Tasks;
5
+ using System.Collections.Generic;
6
+ using System.Linq;
7
+ using UnityEngine;
8
+ using XD.SDK.Common;
9
+ using XD.SDK.Common.Internal;
10
+ using XD.SDK.Common.Internal.Events;
11
+ using XD.SDK.Common.Internal.Standalone;
12
+
13
+ namespace XD.SDK.Account.Internal.Standalone
14
+ {
15
+ public class UserModule
16
+ {
17
+ public class CodeScope
18
+ {
19
+ // Code Scope 个人信息页
20
+ public static readonly string USER_INFO = "userinfo";
21
+ }
22
+
23
+ // 获取用户信息
24
+ private static readonly string XDG_USER_PROFILE = "api/account/v2/info";
25
+
26
+ // 与leanCloud同步
27
+ private static readonly string XDG_LOGIN_SYN = "api/login/v1/syn";
28
+
29
+ // 获取用户绑定信息
30
+ private static readonly string XDG_BIND_LIST = "api/account/v1/bind/list";
31
+
32
+ // 绑定接口
33
+ public static readonly string XDG_BIND_INTERFACE = "api/account/v1/bind";
34
+
35
+ // 解绑接口
36
+ public static readonly string XDG_UNBIND_INTERFACE = "api/account/v1/unbind";
37
+
38
+ // 取消注销申请
39
+ public static readonly string XDG_CANCEL_DELETE = "api/account/v1/cancel-delete";
40
+
41
+ // 获取授权Code
42
+ public static readonly string XDG_AUTH_CODE = "/api/account/v1/apply/code";
43
+
44
+ // 个人信息页
45
+ public static readonly string XDG_PERSONAL_INFO = "/personal-info";
46
+
47
+ private static readonly Persistence persistence = new Persistence(Path.Combine(Application.persistentDataPath,
48
+ XDGConstants.XD_PERSISTENCE_NAME,
49
+ "user_v2"));
50
+
51
+ public static XDGUser current = null;
52
+
53
+ static UserModule()
54
+ {
55
+ // 迁移旧数据
56
+ string v1Path = Path.Combine(Application.persistentDataPath,
57
+ XDGConstants.XD_PERSISTENCE_NAME,
58
+ "user");
59
+ if (File.Exists(v1Path))
60
+ {
61
+ // 迁移
62
+ try
63
+ {
64
+ string v2Path = Path.Combine(Application.persistentDataPath,
65
+ XDGConstants.XD_PERSISTENCE_NAME,
66
+ "user_v2");
67
+ string encryptedData = EncryptionUtils.Encrypt(File.ReadAllText(v1Path), SystemInfo.deviceUniqueIdentifier);
68
+ File.WriteAllText(v2Path, encryptedData);
69
+
70
+ File.Delete(v1Path);
71
+ }
72
+ catch (Exception e)
73
+ {
74
+ XDGLogger.Warn(e.Message);
75
+ }
76
+ }
77
+ }
78
+
79
+ public static XDGUser GetCurrentUser()
80
+ {
81
+ return current;
82
+ }
83
+
84
+ public static async Task<XDGUser> GetLocalUser()
85
+ {
86
+ if (current == null)
87
+ {
88
+ current = await persistence.Load<XDGUser>(SystemInfo.deviceUniqueIdentifier);
89
+ }
90
+
91
+ return current;
92
+ }
93
+
94
+ public static void ClearUserData()
95
+ {
96
+ persistence.Delete();
97
+ current = null;
98
+ }
99
+
100
+ public static async Task<List<Bind>> GetBindList()
101
+ {
102
+ BindResponse response = await XDHttpClient.Client.GetAsync<BindResponse>(XDG_BIND_LIST);
103
+ return response.Binds;
104
+ }
105
+
106
+ public static async Task Bind(LoginType loginType)
107
+ {
108
+ if (loginType == LoginType.Phone)
109
+ {
110
+ AliyunTrack.ResetPhoneLoginData();
111
+ if (XDGCommonInternal.IsCn())
112
+ {
113
+ await PhoneModule.Bind();
114
+ }
115
+ else
116
+ {
117
+ await PhoneModuleIO.LoginOrBind(false);
118
+ }
119
+
120
+ return;
121
+ }
122
+ else if (loginType == LoginType.Email)
123
+ {
124
+ if (XDGCommonInternal.IsCn())
125
+ {
126
+ XDGLogger.Warn("暂不支持的登录方式");
127
+ throw new XDGError(ResponseCode.Common.UnavailableService, "暂不支持的登录方式");
128
+ }
129
+ else
130
+ {
131
+ await EmailModule.LoginOrBind(false);
132
+ }
133
+
134
+ return;
135
+ }
136
+
137
+ Dictionary<string, object> authData = await GetLoginAuthData(loginType);
138
+ await XDHttpClient.Client.PostAsync<BaseResponse>(XDG_BIND_INTERFACE, data: authData);
139
+ }
140
+
141
+ public static Task Unbind(LoginType loginType, Dictionary<string, object> extras = null)
142
+ {
143
+ if (loginType == LoginType.Phone)
144
+ {
145
+ AliyunTrack.ResetPhoneLoginData();
146
+ // 手机号解绑需要验证码
147
+ if (XDGCommonInternal.IsCn())
148
+ {
149
+ return PhoneModule.Unbind(extras);
150
+ }
151
+ else
152
+ {
153
+ return PhoneModuleIO.Unbind(extras);
154
+ }
155
+ }
156
+ else if (loginType == LoginType.Email)
157
+ {
158
+ if (XDGCommonInternal.IsCn())
159
+ {
160
+ XDGLogger.Warn("暂不支持的登录方式");
161
+ throw new XDGError(ResponseCode.Common.UnavailableService, "暂不支持的登录方式");
162
+ }
163
+ else
164
+ {
165
+ return EmailModule.Unbind(extras);
166
+ }
167
+ }
168
+
169
+ Dictionary<string, object> data = new Dictionary<string, object>()
170
+ {
171
+ { "type", (int)loginType }
172
+ };
173
+ return XDHttpClient.Client.PostAsync<BaseResponse>(XDG_UNBIND_INTERFACE, data: data);
174
+ }
175
+
176
+ public static async Task<XDGUser> Login(LoginType loginType)
177
+ {
178
+ if (XDGCommonInternal.IsCn() && loginType == LoginType.Email)
179
+ {
180
+ XDGLogger.Warn("暂不支持的登录方式");
181
+ throw new XDGError(ResponseCode.Common.UnavailableService, "暂不支持的登录方式");
182
+ }
183
+
184
+ if (loginType == LoginType.Console)
185
+ {
186
+ return await LoginByConsole();
187
+ }
188
+
189
+ var localUser = await GetLocalUser();
190
+
191
+ if (loginType == LoginType.Default)
192
+ {
193
+ if (localUser == null)
194
+ {
195
+ XDGLogger.Warn("缺少本地登录信息");
196
+ if (ConfigModule.UsingTapPC && !ConfigModule.DisableAutoLogin2Tap)
197
+ {
198
+ return await Login(LoginType.TapTap);
199
+ }
200
+ throw new XDGError(ResponseCode.Common.Failed, XDLocalization.GetCurrentLocalizableString().LoginFailed);
201
+ }
202
+
203
+ if (localUser.GetLoginType() == LoginType.TapTap)
204
+ {
205
+ try
206
+ {
207
+ var token = await XDGEventBus.PublishAsync<Dictionary<string, object>>(XDGEvents.TapSDKGetAccessToken);
208
+
209
+ if (token == null || !token.ContainsKey("token"))
210
+ {
211
+ XDGLogger.Warn("Third token expired.");
212
+ throw new XDGError(ResponseCode.Account.TokenExpired, "Third token expired.");
213
+ }
214
+ }
215
+ catch (Exception e)
216
+ {
217
+ XDGLogger.Warn(e.Message);
218
+ throw new XDGError(ResponseCode.Common.Failed, e.Message);
219
+ }
220
+ }
221
+
222
+ try
223
+ {
224
+ localUser = await FetchUserInfo();
225
+ }
226
+ catch (XDHttpException e)
227
+ {
228
+ if (e.HttpStatusCode == 401 || e.Code == 40311 || e.Code == 40312)
229
+ {
230
+ throw e;
231
+ }
232
+ }
233
+ catch (Exception e)
234
+ {
235
+ XDGLogger.Warn(e.Message);
236
+ }
237
+
238
+ _ = AccessTokenModule.Refresh();
239
+
240
+ return localUser;
241
+ }
242
+
243
+ try
244
+ {
245
+ AliyunTrack.LoginEnableAuthorizeTrack();
246
+ // 单独处理手机号登录
247
+ if (loginType == LoginType.Phone)
248
+ {
249
+ AliyunTrack.ResetPhoneLoginData();
250
+ AliyunTrack.LoginEnableSDKLoginTrack();
251
+ if (XDGCommonInternal.IsCn())
252
+ {
253
+ await PhoneModule.Login();
254
+ }
255
+ else
256
+ {
257
+ await PhoneModuleIO.LoginOrBind(true);
258
+ }
259
+
260
+ UIManager.ShowLoading();
261
+ }
262
+ else if (loginType == LoginType.Email)
263
+ {
264
+ AliyunTrack.ResetEmailLoginData();
265
+ AliyunTrack.LoginEnableSDKLoginTrack();
266
+ await EmailModule.LoginOrBind(true);
267
+ UIManager.ShowLoading();
268
+ }
269
+ else
270
+ {
271
+ Dictionary<string, object> loginParams = await GetLoginAuthData(loginType);
272
+ UIManager.ShowLoading();
273
+ Dictionary<string, object> cacheData = GetCacheData(loginType);
274
+ await AccessTokenModule.Login(loginParams, cacheData);
275
+ }
276
+
277
+ AliyunTrack.LoginEnableSDKLoginTrack();
278
+ var user = await FetchUserInfo();
279
+ try
280
+ {
281
+ await SyncTDSUser(user.UserId);
282
+ }
283
+ catch (Exception e)
284
+ {
285
+ XDGLogger.Warn(e.ToString());
286
+ }
287
+ XDGLogger.Debug(string.Format($"xd userID: {user.UserId}"));
288
+ return user;
289
+ }
290
+ catch (XDGError e)
291
+ {
292
+ UIManager.DismissLoading();
293
+ if (e.ExtraData != null)
294
+ {
295
+ LocalizableString localizableString = XDLocalization.GetCurrentLocalizableString();
296
+ if (e.Code == 40021 || e.Code == 40901 || e.Code == 40902)
297
+ {
298
+ string title = null;
299
+ string content = null;
300
+ string lt = e.ExtraData["loginType"] as string;
301
+ string email = e.ExtraData["email"] as string;
302
+ if (e.Code == 40021)
303
+ {
304
+ title = localizableString.EmailNotVerified;
305
+ content = string.Format(localizableString.LoginEmailNotVerified, lt, email, lt);
306
+ }
307
+ else if (e.Code == 40901)
308
+ {
309
+ title = localizableString.AccountAlreadyExists;
310
+ string conflicts = string.Join("/",
311
+ (e.ExtraData["conflicts"] as List<object>).Select(item => (item as Dictionary<string, object>)["loginType"]));
312
+ content = string.Format(localizableString.LoginEmailConflict, lt, email, conflicts);
313
+ }
314
+ else if (e.Code == 40902)
315
+ {
316
+ title = localizableString.AccountAlreadyExists;
317
+ string conflicts = string.Join("/",
318
+ (e.ExtraData["conflicts"] as List<object>).Select(item => (item as Dictionary<string, object>)["loginType"]));
319
+ content = string.Format(localizableString.BindEmailConflict, lt, email, lt, conflicts);
320
+ }
321
+
322
+ Dictionary<string, object> conf = new Dictionary<string, object>
323
+ {
324
+ { ConfirmDialog.TITLE_KEY, title },
325
+ { ConfirmDialog.CONTENT_KEY, content },
326
+ { ConfirmDialog.CONFIRM_TEXT_KEY, localizableString.IUnderstand }
327
+ };
328
+
329
+ TaskCompletionSource<XDGUser> tcs = new TaskCompletionSource<XDGUser>();
330
+ UIManager.ShowUI<ConfirmDialog>(conf, (code, data) =>
331
+ {
332
+ UIManager.Dismiss();
333
+ // e.ExtraData = null;
334
+ tcs.TrySetException(e);
335
+ });
336
+ return await tcs.Task;
337
+ }
338
+ else
339
+ {
340
+ throw e;
341
+ }
342
+ }
343
+ else
344
+ {
345
+ throw e;
346
+ }
347
+ }
348
+ finally
349
+ {
350
+ UIManager.DismissLoading();
351
+ }
352
+ }
353
+
354
+ public static async Task<XDGUser> LoginByConsole()
355
+ {
356
+ // 判断当前有接入哪个主机 SDK
357
+ if (SteamUtils.IsSDKSupported)
358
+ {
359
+ try
360
+ {
361
+ AliyunTrack.LoginStart("Default_Steam", "Steam");
362
+ UIManager.ShowLoading();
363
+
364
+ XDGAccessToken localToken = await AccessTokenModule.GetLocalAccessToken();
365
+ string steamId = SteamAuth.GetSteamIdFromSDK();
366
+ XDGUser user;
367
+ XDGLogger.Debug($"LoginByConsole steamId: {steamId} localToken: {localToken} steamId: {steamId}" );
368
+ if (!string.IsNullOrEmpty(localToken?.SteamId) && !string.IsNullOrEmpty(steamId) && localToken?.SteamId == steamId)
369
+ {
370
+ try
371
+ {
372
+ user = await FetchUserInfo();
373
+ // 同自动登录一样,触发刷新 token
374
+ _ = AccessTokenModule.Refresh();
375
+ }
376
+ catch (XDGError e)
377
+ {
378
+ if (e.Code == ResponseCode.Account.TokenExpired)
379
+ {
380
+ // Token 过期
381
+ AliyunTrack.LoginEnableSlientAuthorize();
382
+ user = await LoginByConsoleInternal();
383
+ }
384
+ else
385
+ {
386
+ throw e;
387
+ }
388
+ }
389
+ }
390
+ else
391
+ {
392
+ // 当前 steamId 与缓存 steamId 不一致,则使用当前 steam 信息重新授权(相当于忽略本地缓存)
393
+ user = await LoginByConsoleInternal();
394
+ }
395
+
396
+ try
397
+ {
398
+ await SyncTDSUser(user.UserId);
399
+ }
400
+ catch (Exception e)
401
+ {
402
+ XDGLogger.Warn(e.ToString());
403
+ }
404
+
405
+ XDGLogger.Debug(string.Format($"xd userID: {user.UserId}"));
406
+ return user;
407
+ }
408
+ finally
409
+ {
410
+ UIManager.DismissLoading();
411
+ }
412
+ }
413
+ // 尝试其他主机 SDK
414
+ throw new NotImplementedException("NO supported console sdk.");
415
+ }
416
+
417
+ internal static async Task<XDGUser> LoginByConsoleInternal()
418
+ {
419
+ AliyunTrack.LoginEnableAuthorizeTrack();
420
+ Dictionary<string, object> authData = await SteamAuth.GetAuthDataFromSDK();
421
+ Dictionary<string, object> cacheData = SteamAuth.GetCacheData();
422
+ AliyunTrack.LoginEnableSDKLoginTrack();
423
+ await AccessTokenModule.SignIn(authData, cacheData);
424
+ return await FetchUserInfo();
425
+ }
426
+
427
+ internal static async Task<Dictionary<string, object>> GetLoginAuthData(LoginType loginType)
428
+ {
429
+ switch (loginType)
430
+ {
431
+ case LoginType.Guest:
432
+ return GuestAuth.GetAuthData();
433
+ case LoginType.TapTap:
434
+ return await TapAuth.GetAuthData();
435
+ case LoginType.Apple:
436
+ return await AppleAuth.GetAuthData();
437
+ case LoginType.Google:
438
+ return await GoogleAuth.GetAuthData();
439
+ case LoginType.Steam:
440
+ return await SteamAuth.GetAuthData();
441
+ case LoginType.Facebook:
442
+ return await FacebookAuth.GetAuthData();
443
+ default:
444
+ return new Dictionary<string, object>();
445
+ }
446
+ }
447
+
448
+ internal static Dictionary<string, object> GetCacheData(LoginType loginType)
449
+ {
450
+ switch (loginType)
451
+ {
452
+ case LoginType.Steam:
453
+ return SteamAuth.GetCacheData();
454
+ default:
455
+ return null;
456
+ }
457
+ }
458
+
459
+ private static async Task SyncTDSUser(string userId)
460
+ {
461
+ // 效果等于 BecomeWithSessionToken,为了少一次网络请求
462
+ // SyncTokenResponse tokenResponse = await XDHttpClient.Client.PostAsync<SyncTokenResponse>(XDG_LOGIN_SYN);
463
+ // TDSUser user = TDSUser.CreateWithoutData(TDSUser.CLASS_NAME, userId) as TDSUser;
464
+ // user.SessionToken = tokenResponse.SyncToken.SessionToken;
465
+ // await user.SaveToLocal();
466
+ var token = await XDHttpClient.Client.PostAsync<SyncTokenResponse>(XDG_LOGIN_SYN);
467
+
468
+ XDGEventBus.Publish(XDGEvents.TdsSDKSyncUser, token.SyncToken.SessionToken, userId);
469
+ }
470
+
471
+ public static async Task<XDGUser> FetchUserInfo()
472
+ {
473
+ try
474
+ {
475
+ ProfileResponse response = await XDHttpClient.Client.GetAsync<ProfileResponse>(XDG_USER_PROFILE);
476
+
477
+ if (current == null)
478
+ {
479
+ current = response.User;
480
+ }
481
+ else
482
+ {
483
+ current.Update(response.User);
484
+ }
485
+
486
+ await persistence.Save(current, SystemInfo.deviceUniqueIdentifier);
487
+ AliyunTrack.LoginPreSuccess();
488
+ return current;
489
+ }
490
+ catch (XDHttpException xdException)
491
+ {
492
+ if (xdException.Code == 40312 && xdException.ExtraData != null)
493
+ {
494
+ var extra = xdException.ExtraData["extra"] as Dictionary<string, object>;
495
+ var realNameUrl = extra?["url"] as string;
496
+ if (!string.IsNullOrEmpty(realNameUrl))
497
+ {
498
+ var tcs = new TaskCompletionSource<XDGUser>();
499
+ XDGCommon.OpenWebPage(realNameUrl, async (action, data) =>
500
+ {
501
+ if (action == WebActionEnum.CLOSE)
502
+ {
503
+ if (data != null)
504
+ {
505
+ data.TryGetValue("success", out var success);
506
+ if (success is bool)
507
+ {
508
+ if ((bool)success)
509
+ {
510
+ tcs.SetResult(await FetchUserInfo());
511
+ }
512
+ return;
513
+ }
514
+ }
515
+ }
516
+
517
+ tcs.TrySetException(xdException);
518
+ });
519
+ return await tcs.Task;
520
+ }
521
+ }
522
+
523
+ if (xdException.Code == 40311 && xdException.ExtraData != null)
524
+ {
525
+ var title = xdException.ExtraData["title"] as string;
526
+ var content = xdException.ExtraData["content"] as string;
527
+ var negativeButton = xdException.ExtraData["negativeButton"] as string;
528
+ var positiveButton = xdException.ExtraData["positiveButton"] as string;
529
+
530
+ if (title != null && content != null)
531
+ {
532
+ var config = new Dictionary<string, object>
533
+ {
534
+ { Dialog.TITLE_KEY, title },
535
+ { Dialog.CONTENT_KEY, content },
536
+ { Dialog.PRIMARY_TEXT_KEY, positiveButton },
537
+ { Dialog.SECONDARY_TEXT_KEY, negativeButton }
538
+ };
539
+
540
+ var tcs = new TaskCompletionSource<XDGUser>();
541
+ UIManager.ShowUI<Dialog>("Dialog", config, async (code, data) =>
542
+ {
543
+ if (code == 1 || code == -1)
544
+ {
545
+ UIManager.Dismiss();
546
+ tcs.TrySetException(xdException);
547
+ }
548
+ else
549
+ {
550
+ await CancelDelete();
551
+ UIManager.Dismiss();
552
+ tcs.SetResult(await FetchUserInfo());
553
+ }
554
+ });
555
+ UIManager.DismissLoading();
556
+ return await tcs.Task;
557
+ }
558
+ }
559
+
560
+ var errorMsg = xdException.Message;
561
+ // 所有 40801 错误代表 401 授权失败,需要明示原因为 XD_TOKEN_EXPIRED
562
+ if (xdException.Code == ResponseCode.Account.TokenExpired || xdException.HttpStatusCode == 401)
563
+ errorMsg = "XD_TOKEN_EXPIRED";
564
+ AliyunTrack.LoginPreFail(errorMsg);
565
+ throw xdException;
566
+ }
567
+ catch (Exception e)
568
+ {
569
+ AliyunTrack.LoginPreFail(e.Message);
570
+ throw e;
571
+ }
572
+ }
573
+
574
+ private static async Task CancelDelete()
575
+ {
576
+ UIManager.ShowLoading();
577
+ try
578
+ {
579
+ await XDHttpClient.Client.PostAsync<BaseResponse>(XDG_CANCEL_DELETE);
580
+ UIManager.DismissLoading();
581
+ }
582
+ catch (Exception e)
583
+ {
584
+ UIManager.DismissLoading();
585
+ var errorMsg = XDLocalization.GetCurrentLocalizableString().NetworkErrorSafeRetry;
586
+ if (e is XDGError xdException && !string.IsNullOrEmpty(xdException.ErrorMsg))
587
+ {
588
+ errorMsg = xdException.ErrorMsg;
589
+ }
590
+
591
+ UIManager.ShowToast(errorMsg);
592
+ throw e;
593
+ }
594
+ }
595
+ }
596
+ }
597
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: c383e216b16d4fb894ee1f5d4e88400e
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,47 @@
1
+ #if UNITY_EDITOR || UNITY_STANDALONE
2
+
3
+ using System;
4
+ using System.Collections.Generic;
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
+ public class AccessTokenWebFunction : IWebFunction
12
+ {
13
+ public string GetName()
14
+ {
15
+ return "getAccessToken";
16
+ }
17
+
18
+ public async void Handler(IBridgeWebView webView, string data, Action<object> callbackFunction)
19
+ {
20
+ XDGLogger.Debug($"message from javascript by:{GetName()} with data:{data}");
21
+ var token = await AccessTokenModule.GetLocalAccessToken();
22
+ if (token == null)
23
+ {
24
+ callbackFunction(new WebBridgeResponse.Failed
25
+ {
26
+ Msg = "AccessToken is null!"
27
+ });
28
+ return;
29
+ }
30
+
31
+ var result = new Dictionary<string, object>
32
+ {
33
+ { "expireIn", token.ExpireIn },
34
+ { "macKey", token.MacKey },
35
+ { "macAlgorithm", token.MacAlgorithm },
36
+ { "tokenType", token.TokenType },
37
+ { "kid", token.Kid }
38
+ };
39
+
40
+ callbackFunction(new WebBridgeResponse.Success
41
+ {
42
+ Data = result
43
+ });
44
+ }
45
+ }
46
+ }
47
+ #endif
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 567b5e9620564fe89dc5767d53ec2393
3
+ timeCreated: 1753339498
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: df785d454b4044e8b6234b3d167a6ee3
3
+ timeCreated: 1753339610
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 5a0325abf107a43c988e1612aeddd17b
2
+ guid: 89cb1a6563bc46879d197296e3f88d58
3
3
  folderAsset: yes
4
4
  DefaultImporter:
5
5
  externalObjects: {}
@@ -0,0 +1,21 @@
1
+ using UnityEngine;
2
+ using XD.SDK.Common.Internal.Events;
3
+
4
+ #if UNITY_EDITOR || UNITY_STANDALONE
5
+ using XD.SDK.Account.Internal.Standalone;
6
+ #endif
7
+
8
+ namespace XD.SDK.Account
9
+ {
10
+ public static class XDGAccountEventHandler
11
+ {
12
+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
13
+ static void RegisterEventHandlers()
14
+ {
15
+ XDGEventBus.Subscribe(XDGEvents.AccountGetCurrentUser, _ => XDGAccount.GetCurrentUser());
16
+ #if UNITY_EDITOR || UNITY_STANDALONE
17
+ XDGEventBus.SubscribeAsync(XDGEvents.AccountGetAccessToken, async _ => await AccessTokenModule.GetLocalAccessToken());
18
+ #endif
19
+ }
20
+ }
21
+ }