[F] Link [A] signout

This commit is contained in:
2024-08-24 19:23:39 +08:00
parent da367097c8
commit 728af3cfd7
11 changed files with 928 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using asap.core;
using Newtonsoft.Json.Linq;
@@ -24,7 +26,8 @@ namespace tysdk
private static Dictionary<string, EAccoutType> accoutTypeMap = new Dictionary<string, EAccoutType>(){
{"google", EAccoutType.hwGoogle},
{"fb", EAccoutType.hwFacebook},
{"tyGuest", EAccoutType.hwGuest}
{"tyGuest", EAccoutType.hwGuest},
{"ios13", EAccoutType.Apple}
};
#endif
@@ -262,6 +265,59 @@ namespace tysdk
UnityBridgeFunc.SetGaUserInfo(strUserId);
}
#if UNITY_EDITOR
public async Task<bool> LinkAccount(EAccoutType accoutType)
{
await Task.Delay(300);
return true;
}
#elif UNITY_IOS
public async Task<bool> LinkAccount(EAccoutType accoutType)
{
if (_accountInfo == null) return false;
if( _accountInfo.linkedAccout.Contains(accoutType)) return true;
var taskSource = new TaskCompletionSource<LinkResult>();
callbacks.Add("LinkAccoutResult", (ITYSdkCallback callback) =>
{
taskSource.SetResult((LinkResult)callback);
});
UnityBridgeFunc.LinkAccount(accoutType);
var result = await taskSource.Task;
if (result.isSuccess)
{
var savedInfo = AccountInfo.GetSavedAccoutInfo();
if(savedInfo != null)
{
savedInfo.AddLinkedAccount(accoutType);
savedInfo.Save();
_accountInfo = savedInfo;
}
}
return result.isSuccess;
}
public void LinkAccoutResult(string codestr)
{
var result = new LinkResult()
{
isSuccess = codestr == "1"
};
if (callbacks.TryGetValue("LinkAccoutResult", out var action))
{
action.Invoke(result);
callbacks.Remove("LoginResult");
}
}
#elif UNITY_ANDROID
public async Task<bool> LinkAccount(EAccoutType accoutType)
{
if (_accountInfo == null) return false;
@@ -280,6 +336,8 @@ namespace tysdk
return result.isSuccess;
}
#endif
/// <summary>
/// 检查是否已经绑定
/// <returns>
@@ -327,5 +385,91 @@ namespace tysdk
callbacks.Remove("CheckLinkResult");
}
}
public void Signout()
{
List<string> list = new List<string>();
string defaultTyurl = "https://128-hwsfsdk-sdk-online01.qijihdhk.com";
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"
:
"https://customermanage-feature-test-web-test.tuyougame.cn/appCancel/note.html";
string sdkurl = $"sdkurl={tyurl}";
list.Add(sdkurl);
string appid = "appid=20587";
list.Add(appid);
#if UNITY_ANDROID
string clientid = "Android_5.00_tyGuest,facebook.googleplay.0-hall20587.googleplay.FishingMaster";
#elif UNITY_IOS
string clientid = "IOS_5.00_tyGuest,facebook,appStore.appStore.0-hall20587.appStore.FishingMaster";
#endif
list.Add($"clientid={clientid}");
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);
string tysdktoken = $"tysdktoken={_accountInfo.token}";
list.Add(tysdktoken);
list.Sort();
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";
Debug.Log($"[TYSdkFacade:Signout] url \n{url}");
Application.OpenURL(url);
}
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();
}
}
}