update:逻辑更新
This commit is contained in:
@@ -34,20 +34,13 @@ 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},
|
||||
{"vk.global.app", EAccoutType.hwVkid},
|
||||
{"ios13", EAccoutType.Apple}
|
||||
};
|
||||
|
||||
public static void AddAccoutType(string key, EAccoutType value)
|
||||
{
|
||||
accoutTypeMap[key] = value;
|
||||
}
|
||||
|
||||
private static EAccoutType ConvertAccoutType(string accountType)
|
||||
{
|
||||
if (accoutTypeMap.ContainsKey(accountType))
|
||||
@@ -108,10 +101,12 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
// ================== Singleton ==================
|
||||
private static TYSdkFacade _instance;
|
||||
private static AccountInfo _accountInfo;
|
||||
public static AccountInfo TYAccountInfo => _accountInfo;
|
||||
protected static AccountInfo _accountInfo;
|
||||
|
||||
private static TYSdkFacade _instance;
|
||||
public static bool IsSdkInited { get; private set; }
|
||||
public static event System.Action<bool, string> OnInitComplete;
|
||||
|
||||
public static TYSdkFacade Instance
|
||||
{
|
||||
@@ -125,47 +120,55 @@ namespace tysdk
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Channel => ChannelConfig.Channel;
|
||||
|
||||
private int LoginTimeoutSeconds => ChannelConfig.LoginTimeoutSeconds;
|
||||
|
||||
public static bool IsSdkInited { get; private set; }
|
||||
public static event System.Action<bool, string> OnInitComplete;
|
||||
|
||||
// ================== Init ==================
|
||||
public void Init()
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] Init()");
|
||||
#if UNITY_ANDROID
|
||||
UnityBridgeFunc.InitSDK();
|
||||
UnityBridgeFunc.InitSDK(ChannelConfig.Channel);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
public void SetChannelFromNative(string channel)
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] SetChannelFromNative: {channel}");
|
||||
ChannelConfig.SetChannel(channel);
|
||||
}
|
||||
|
||||
public void InitResult(string json)
|
||||
{
|
||||
var data = Newtonsoft.Json.Linq.JObject.Parse(json);
|
||||
var code = (int)data["code"];
|
||||
var msg = (string)data["msg"];
|
||||
IsSdkInited = code == 0;
|
||||
UnityEngine.Debug.Log($"[TYSdkFacade] InitResult: code={code} msg={msg}");
|
||||
OnInitComplete?.Invoke(IsSdkInited, msg);
|
||||
Debug.Log($"[TYSdkFacade] InitResult: {json}");
|
||||
var success = false;
|
||||
var msg = string.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
var data = JObject.Parse(json);
|
||||
success = (int)data["code"] == 0;
|
||||
msg = (string)data["msg"];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg = e.Message;
|
||||
Debug.LogWarning($"[TYSdkFacade] InitResult parse failed: {e}");
|
||||
}
|
||||
|
||||
IsSdkInited = success;
|
||||
OnInitComplete?.Invoke(success, msg);
|
||||
}
|
||||
|
||||
// Called from Java SDKManager.InitSDK to sync channel
|
||||
public void SetChannelFromNative(string ch)
|
||||
{
|
||||
ChannelConfig.SetChannel(ch);
|
||||
UnityEngine.Debug.Log($"[CHANNEL-VERIFY] C# SetChannelFromNative → channel={ch}, payType={ChannelConfig.PayType}, loginTimeout={ChannelConfig.LoginTimeoutSeconds}");
|
||||
}
|
||||
|
||||
/*================================================
|
||||
|
||||
_ _
|
||||
/ \ ___ ___ ___ _ _ _ __ | |_
|
||||
/ _ \ / __/ __/ _ \| | | | '_ \| __|
|
||||
/ ___ \ (_| (_| (_) | |_| | | | | |_
|
||||
/_/ \_\___\___\___/ \__,_|_| |_|\__|
|
||||
|
||||
=================================================*/
|
||||
|
||||
|
||||
public static bool IsLoggedIn => _accountInfo != null;
|
||||
|
||||
public void Logout()
|
||||
@@ -182,7 +185,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);
|
||||
|
||||
@@ -200,25 +203,25 @@ namespace tysdk
|
||||
};
|
||||
|
||||
#elif UNITY_ANDROID || UNITY_IOS
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(LoginTimeoutSeconds));
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(30));
|
||||
|
||||
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
|
||||
}
|
||||
@@ -247,7 +250,7 @@ namespace tysdk
|
||||
return new LoginInfo() { isSuccess = false };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<LoginInfo> LoginBySns()
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] LoginBySns");
|
||||
@@ -332,17 +335,18 @@ 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);
|
||||
@@ -364,7 +368,6 @@ namespace tysdk
|
||||
return new LinkResult() { code = 1 };
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public void LinkAccoutResult(string message)
|
||||
{
|
||||
@@ -387,18 +390,21 @@ namespace tysdk
|
||||
}
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
}
|
||||
|
||||
#endif
|
||||
public void CleanLinkTempSnSInfo()
|
||||
{
|
||||
UnityBridgeFunc.CleanLinkTmpSnsInfo();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public async Task<ChangeLinkResult> ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
await Task.Delay(300);
|
||||
return new ChangeLinkResult() { code = 1 };
|
||||
#else
|
||||
return new ChangeLinkResult(){code = 1};
|
||||
}
|
||||
#elif UNITY_IOS || UNITY_ANDROID
|
||||
public async Task<ChangeLinkResult> ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
||||
{
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<ChangeLinkResult>(TimeSpan.FromSeconds(30));
|
||||
UnityBridgeFunc.ChangeLinkAccount(accoutType, oldUserId, newUserId);
|
||||
try
|
||||
@@ -420,8 +426,8 @@ namespace tysdk
|
||||
{
|
||||
CleanLinkTempSnSInfo();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
public void ChangeLinkAccountResult(string message)
|
||||
{
|
||||
@@ -435,6 +441,14 @@ 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;
|
||||
@@ -460,7 +474,7 @@ namespace tysdk
|
||||
|
||||
return result.code == 1;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch(Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] CheckLinkResult error: {e}");
|
||||
return false;
|
||||
@@ -482,6 +496,7 @@ 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"
|
||||
:
|
||||
@@ -503,12 +518,23 @@ namespace tysdk
|
||||
string uid = $"uid={_accountInfo.userId}";
|
||||
list.Add(uid);
|
||||
|
||||
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 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);
|
||||
|
||||
string tysdktoken = $"tysdktoken={_accountInfo.token}";
|
||||
list.Add(tysdktoken);
|
||||
@@ -518,6 +544,7 @@ 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}");
|
||||
@@ -526,16 +553,25 @@ 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