[M] login & logout & payment

- login by token
- save account info
- logout remove accout info
- iOS SKU list parser
- iOS Pay
This commit is contained in:
2024-08-13 23:53:35 +08:00
parent 7f576df319
commit c355784122
10 changed files with 663 additions and 112 deletions

View File

@@ -11,10 +11,54 @@ namespace tysdk
{
public class AccountInfo
{
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>(){
{"google", EAccoutType.hwGoogle},
{"fb", EAccoutType.hwFacebook},
{"tyGuest", EAccoutType.hwGuest}
};
public int userId;
public string token;
public string jwtToken;
public string strUserId => userId.ToString();
public string channelstr;
public EAccoutType channel => accoutTypeMap[channelstr];
private const string KEY_ACCOUNT_INFO = "KEY_ACCOUNT_INFO";
public void Save()
{
JObject jInfo = new JObject();
jInfo["channel"] = channelstr;
jInfo["token"] = token;
jInfo["userId"] = userId;
jInfo["jwtToken"] = jwtToken;
PlayerPrefs.SetString(KEY_ACCOUNT_INFO, jInfo.ToString());
}
public static void Remove()
{
PlayerPrefs.DeleteKey(KEY_ACCOUNT_INFO);
}
public static AccountInfo GetSavedAccoutInfo()
{
if (PlayerPrefs.HasKey(KEY_ACCOUNT_INFO))
{
var jInfo = JObject.Parse(PlayerPrefs.GetString(KEY_ACCOUNT_INFO));
return new AccountInfo()
{
userId = (int)jInfo["userId"],
token = (string)jInfo["token"],
channelstr = (string)jInfo["channel"],
jwtToken = (string)jInfo["jwtToken"],
};
}
else
{
return null;
}
}
}
private static AccountInfo _accountInfo;
@@ -45,31 +89,29 @@ namespace tysdk
}
/*================================================
/*================================================
_ _
/ \ ___ ___ ___ _ _ _ __ | |_
/ _ \ / __/ __/ _ \| | | | '_ \| __|
/ ___ \ (_| (_| (_) | |_| | | | | |_
/_/ \_\___\___\___/ \__,_|_| |_|\__|
_ _
/ \ ___ ___ ___ _ _ _ __ | |_
/ _ \ / __/ __/ _ \| | | | '_ \| __|
/ ___ \ (_| (_| (_) | |_| | | | | |_
/_/ \_\___\___\___/ \__,_|_| |_|\__|
=================================================*/
=================================================*/
public bool IsLoggedIn => _accountInfo != null;
public bool IsLoggedIn => _accountInfo != null;
public void Logout()
{
UnityEngine.Debug.Log("Logout");
UnityBridgeFunc.UnityLoginOut();
_accountInfo = null;
}
public void LogoutByChannel()
public void Logout()
{
UnityEngine.Debug.Log("LogoutByChannel");
UnityBridgeFunc.UnityLoginOut();
UnityEngine.Debug.Log("Logout");
if(_accountInfo != null) return;
{
UnityBridgeFunc.UnityLogOutByChannel(_accountInfo.channel);
}
_accountInfo = null;
AccountInfo.Remove();
}
public async Task<LoginInfo> Login(EAccoutType accoutType)
@@ -107,6 +149,22 @@ namespace tysdk
}
public async Task<LoginInfo> LoginByToken()
{
var accoutInfo = AccountInfo.GetSavedAccoutInfo();
if(accoutInfo == null) new LoginInfo();
var taskSource = new TaskCompletionSource<LoginInfo>();
callbacks.Add("LoginResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((LoginInfo)callback);
});
UnityBridgeFunc.UnityLoginByTokenFun(accoutInfo.token);
return await taskSource.Task;
}
public void LoginResult(string json)
{
Debug.Log("[TYSdkFacade] Login callback:");
@@ -124,8 +182,11 @@ namespace tysdk
userId = (int)loginData["userId"],
token = (string)loginData["token"],
jwtToken = (string)loginData["jwttoken"],
channelstr = (string)loginData["loginChannelTypeC"]
};
_accountInfo.Save();
result.isSuccess = true;
result.userId = _accountInfo.userId;
@@ -145,8 +206,6 @@ namespace tysdk
var strUserId = _accountInfo.strUserId;
UnityBridgeFunc.SetGaUserInfo(strUserId);
UnityBridgeFunc.UnitySetAdBoxUserInfo(strUserId);
UnityBridgeFunc.UnityInitADSConfig();
}
}
}