update:更新flexion 以及sdk 接入
This commit is contained in:
@@ -34,14 +34,20 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>(){
|
||||
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>()
|
||||
{
|
||||
{"google", EAccoutType.hwGoogle},
|
||||
{"fb", EAccoutType.hwFacebook},
|
||||
{"tyGuest", EAccoutType.hwGuest},
|
||||
{"ios13", EAccoutType.Apple},
|
||||
{AccountString.hwVkid, EAccoutType.hwVkid}
|
||||
{"vk.global.app", EAccoutType.hwVkid},
|
||||
};
|
||||
|
||||
public static void AddAccoutType(string key, EAccoutType value)
|
||||
{
|
||||
accoutTypeMap[key] = value;
|
||||
}
|
||||
|
||||
private static EAccoutType ConvertAccoutType(string accountType)
|
||||
{
|
||||
if (accoutTypeMap.ContainsKey(accountType))
|
||||
@@ -102,10 +108,11 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
private static AccountInfo _accountInfo;
|
||||
public static AccountInfo TYAccountInfo => _accountInfo;
|
||||
|
||||
// ================== Singleton ==================
|
||||
private static TYSdkFacade _instance;
|
||||
public static AccountInfo TYAccountInfo => _accountInfo;
|
||||
protected static AccountInfo _accountInfo;
|
||||
|
||||
public static TYSdkFacade Instance
|
||||
{
|
||||
get
|
||||
@@ -118,26 +125,27 @@ namespace tysdk
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Channel => ChannelConfig.Channel;
|
||||
|
||||
private int LoginTimeoutSeconds => ChannelConfig.LoginTimeoutSeconds;
|
||||
|
||||
// ================== Init ==================
|
||||
public void Init()
|
||||
{
|
||||
#if UNITY_ANDROID
|
||||
UnityBridgeFunc.InitSDK();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*================================================
|
||||
|
||||
_ _
|
||||
/ \ ___ ___ ___ _ _ _ __ | |_
|
||||
/ _ \ / __/ __/ _ \| | | | '_ \| __|
|
||||
/ ___ \ (_| (_| (_) | |_| | | | | |_
|
||||
/_/ \_\___\___\___/ \__,_|_| |_|\__|
|
||||
|
||||
=================================================*/
|
||||
|
||||
|
||||
public static bool IsLoggedIn => _accountInfo != null;
|
||||
|
||||
public void Logout()
|
||||
@@ -154,7 +162,7 @@ namespace tysdk
|
||||
|
||||
public async Task<LoginInfo> Login(EAccoutType accoutType)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
#if UNITY_EDITOR
|
||||
await Task.Yield();
|
||||
var deviceId = UnityEngine.Device.SystemInfo.deviceUniqueIdentifier.Split('-')[0].Substring(0, 8);
|
||||
|
||||
@@ -172,25 +180,25 @@ namespace tysdk
|
||||
};
|
||||
|
||||
#elif UNITY_ANDROID || UNITY_IOS
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(30));
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(LoginTimeoutSeconds));
|
||||
|
||||
UnityBridgeFunc.UnityLogin(accoutType);
|
||||
|
||||
try
|
||||
{
|
||||
var loginInfo = await task;
|
||||
if(loginInfo.isSuccess)
|
||||
{
|
||||
_accountInfo.channel = accoutType;
|
||||
_accountInfo.AddLinkedAccount(accoutType);
|
||||
_accountInfo.Save();
|
||||
}
|
||||
return loginInfo;
|
||||
var loginInfo = await task;
|
||||
if (loginInfo.isSuccess)
|
||||
{
|
||||
_accountInfo.channel = accoutType;
|
||||
_accountInfo.AddLinkedAccount(accoutType);
|
||||
_accountInfo.Save();
|
||||
}
|
||||
return loginInfo;
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] Login failed: {e}");
|
||||
return new LoginInfo(){isSuccess = false};
|
||||
Debug.LogWarning($"[TYSdkFacade] Login failed: {e}");
|
||||
return new LoginInfo() { isSuccess = false };
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -219,7 +227,7 @@ namespace tysdk
|
||||
return new LoginInfo() { isSuccess = false };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<LoginInfo> LoginBySns()
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] LoginBySns");
|
||||
@@ -304,18 +312,17 @@ namespace tysdk
|
||||
UnityBridgeFunc.SetGaUserInfo(strUserId);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||
{
|
||||
await Task.Delay(300);
|
||||
return new LinkResult(){code = 1};
|
||||
return new LinkResult() { code = 1 };
|
||||
}
|
||||
#elif UNITY_IOS || UNITY_ANDROID
|
||||
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||
{
|
||||
if (_accountInfo == null) return new LinkResult(){ code = 1};
|
||||
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult(){ code = 0};
|
||||
if (_accountInfo == null) return new LinkResult() { code = 1 };
|
||||
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult() { code = 0 };
|
||||
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LinkResult>(TimeSpan.FromMinutes(1));
|
||||
UnityBridgeFunc.LinkAccount(accoutType);
|
||||
@@ -337,6 +344,7 @@ namespace tysdk
|
||||
return new LinkResult() { code = 1 };
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void LinkAccoutResult(string message)
|
||||
{
|
||||
@@ -359,7 +367,7 @@ namespace tysdk
|
||||
}
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
}
|
||||
#endif
|
||||
|
||||
public void CleanLinkTempSnSInfo()
|
||||
{
|
||||
UnityBridgeFunc.CleanLinkTmpSnsInfo();
|
||||
@@ -367,6 +375,10 @@ namespace tysdk
|
||||
|
||||
public async Task<ChangeLinkResult> ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
await Task.Delay(300);
|
||||
return new ChangeLinkResult() { code = 1 };
|
||||
#else
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<ChangeLinkResult>(TimeSpan.FromSeconds(30));
|
||||
UnityBridgeFunc.ChangeLinkAccount(accoutType, oldUserId, newUserId);
|
||||
try
|
||||
@@ -388,6 +400,7 @@ namespace tysdk
|
||||
{
|
||||
CleanLinkTempSnSInfo();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void ChangeLinkAccountResult(string message)
|
||||
@@ -402,14 +415,6 @@ namespace tysdk
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否已经绑定
|
||||
/// <returns>
|
||||
/// 1 已经绑定
|
||||
/// 0 未绑定
|
||||
/// -1 失败
|
||||
/// </returns>
|
||||
/// </summary>
|
||||
public async Task<bool> LinkCheck(EAccoutType accoutType)
|
||||
{
|
||||
if (_accountInfo == null) return false;
|
||||
@@ -435,7 +440,7 @@ namespace tysdk
|
||||
|
||||
return result.code == 1;
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] CheckLinkResult error: {e}");
|
||||
return false;
|
||||
@@ -457,7 +462,6 @@ namespace tysdk
|
||||
IConfig config = GContext.container.Resolve<IConfig>();
|
||||
var tyurl = config.Get<string>("AGG_SERVER", defaultTyurl);
|
||||
|
||||
|
||||
string tycs = tyurl == defaultTyurl ?
|
||||
"https://hwcsh.tygameworld.com/template/appCancel/note.html"
|
||||
:
|
||||
@@ -479,23 +483,12 @@ namespace tysdk
|
||||
string uid = $"uid={_accountInfo.userId}";
|
||||
list.Add(uid);
|
||||
|
||||
string roleid = "roleid=0";
|
||||
list.Add(roleid);
|
||||
|
||||
string gameid = "gameid=20587";
|
||||
list.Add(gameid);
|
||||
|
||||
string cloudid = "cloudid=128";
|
||||
list.Add(cloudid);
|
||||
|
||||
string gamename = "gamename=FishingTravel";
|
||||
list.Add(gamename);
|
||||
|
||||
string certification = "certification=0";
|
||||
list.Add(certification);
|
||||
|
||||
string ischannel = "ischannel=1";
|
||||
list.Add(ischannel);
|
||||
list.Add("roleid=0");
|
||||
list.Add("gameid=20587");
|
||||
list.Add("cloudid=128");
|
||||
list.Add("gamename=FishingTravel");
|
||||
list.Add("certification=0");
|
||||
list.Add("ischannel=1");
|
||||
|
||||
string tysdktoken = $"tysdktoken={_accountInfo.token}";
|
||||
list.Add(tysdktoken);
|
||||
@@ -505,7 +498,6 @@ namespace tysdk
|
||||
string listStr = string.Join("&", list.ToArray());
|
||||
string sign = listStr +
|
||||
"csh-api-6dfa879490a249be9fbc92e97e4d898d-api-csh";
|
||||
//对sign进行MD5加密
|
||||
string signMd5 = CalculateMD5Hash(sign);
|
||||
string url = $"{tycs}?{listStr}&sign={signMd5}&isAbroad=1&lan=en";
|
||||
Debug.Log($"[TYSdkFacade:Signout] url \n{url}");
|
||||
@@ -514,25 +506,16 @@ namespace tysdk
|
||||
|
||||
private string CalculateMD5Hash(string input)
|
||||
{
|
||||
// Create a new instance of the MD5CryptoServiceProvider object.
|
||||
MD5 md5Hasher = MD5.Create();
|
||||
|
||||
// Convert the input string to a byte array and compute the hash.
|
||||
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
|
||||
|
||||
// Create a new Stringbuilder to collect the bytes
|
||||
// and create a string.
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
|
||||
// Loop through each byte of the hashed data
|
||||
// and format each one as a hexadecimal string.
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
|
||||
// Return the hexadecimal string.
|
||||
return sBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user