77 lines
2.8 KiB
C#
77 lines
2.8 KiB
C#
using cfg.BI;
|
||
using PhxhSDK;
|
||
using Framework.BI;
|
||
using Framework.Event;
|
||
using Event = cfg.BI.Event;
|
||
using Constants = Framework.Constants.Constants;
|
||
|
||
namespace Gameplay.Login
|
||
{
|
||
public class LoginStatusFaceBook : LoginStatus
|
||
{
|
||
public override LoginStatusID ID
|
||
{
|
||
get { return LoginStatusID.Facebook; }
|
||
}
|
||
|
||
public override void Login()
|
||
{
|
||
DebugUtil.LogWarning("Facebook登录");
|
||
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
|
||
var loginService = sdkHelper as ILoginService;
|
||
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
|
||
loginService?.Login(OnLoginSuccess, OnLoginFail);
|
||
}
|
||
|
||
public override void Logout()
|
||
{
|
||
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
|
||
var loginService = sdkHelper as ILoginService;
|
||
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
|
||
loginService?.Logout();
|
||
}
|
||
|
||
public override string GetProfileName()
|
||
{
|
||
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
|
||
var loginService = sdkHelper as ILoginService;
|
||
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
|
||
string profileName = loginService?.GetProfileName();
|
||
DebugUtil.LogWarning("Facebook Get UserName: {0}", profileName);
|
||
return string.IsNullOrEmpty(profileName) ? Constants.EmptyUser : profileName;
|
||
}
|
||
|
||
private void OnLoginSuccess(string userID, string facebookUserID, string idToken)
|
||
{
|
||
LoginManager.Instance.IsLogin = true;
|
||
LoginManager.Instance.ShowLogin = true;
|
||
|
||
//第三方ID设置为Firebase验证后的唯一id 并存至本地
|
||
AppInfoManager.Instance.ThirdLoginSuccess(userID, LoginStatusID.Facebook);
|
||
|
||
BIManager.Instance.ThirdID = userID;
|
||
BIManager.Instance.TrackEvent(Event.login_success);
|
||
BIManager.Instance.TrackEventOnce(EventFirst.fte_login_success);
|
||
|
||
//从服务器获取数据
|
||
GetDataFromSever();
|
||
|
||
EventManager.Instance.Send(EventManager.EventName.LoginSuccess);
|
||
DebugUtil.LogWarning("FaceBook登录成功:userID: {0}", userID);
|
||
}
|
||
|
||
private void GetDataFromSever()
|
||
{
|
||
AppInfoManager.Instance.CurLoginState = AppInfoManager.NetConfigID.ThirdID;
|
||
AppNetConfig.State = NetRequestStatus.Start;
|
||
}
|
||
|
||
private void OnLoginFail(int code, string msg)
|
||
{
|
||
LoginManager.Instance.IsLogin = false;
|
||
BIManager.Instance.TrackEvent(Event.login_fail, msg);
|
||
DebugUtil.LogError("FaceBook Login Fail: {0}", msg);
|
||
EventManager.Instance.Send(EventManager.EventName.LoginFail);
|
||
}
|
||
}
|
||
} |