enhance ChangeLinkAccount functionality
- Added LoginTypeToBindType function to map login types to binding types. - Updated ChangeLinkAccount method to handle account linking and unbinding with appropriate error handling. - Ensured proper messaging for success and failure cases during account changes. - Cleaned temporary SNS information after account change attempts.
This commit is contained in:
@@ -22,10 +22,10 @@ public class ConfigManager {
|
||||
public static final String UNITY_FACADE_NAME = "TYSdkFacade";
|
||||
public static final String LOGIN_CALLBACK_FUNCTION_NAME = "LoginResult";
|
||||
public static final String LINKACCOUT_CALLBACK_FUNCTION_NAME = "LinkAccoutResult";
|
||||
public static final String CHANGELINK_CALLBACK_FUNCTION_NAME = "ChangeLinkAccountResult";
|
||||
public static final String CHECKLINK_CALLBACK_FUNCTION_NAME = "CheckLinkResult";
|
||||
public static final String PAY_CALLBACK_FUNCTION_NAME = "PayResult";
|
||||
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
|
||||
public static final String FCM_NOTICE_FUNCTION_NAME = "FCMCallback";
|
||||
public static final String FCM_REALNAME_CALLBACK_FUNCTION_NAME = "RealNameCallback";
|
||||
|
||||
}
|
||||
|
||||
@@ -266,6 +266,41 @@ public class SDKManager {
|
||||
tmpSnsInfo = null;
|
||||
}
|
||||
|
||||
public static void ChangeLinkAccount(String type, int oldUserId, int newUserId)
|
||||
{
|
||||
if(tmpSnsInfo == null)
|
||||
{
|
||||
String msg = "{\"code\":1, \"userId\": 0, \"msg\": \"tmpSnsInfo is null\"}";
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
|
||||
return;
|
||||
}
|
||||
|
||||
SDKAPI.getIns().unbindBySnsId(tmpSnsInfo, String.valueOf(oldUserId), (unbindCode, unbindMsg) -> {
|
||||
Log.i(TAG, "unbindBySnsId code: " + unbindCode + " msg: " + unbindMsg);
|
||||
if(unbindCode == SDKCallBack.CODE_SUCCESS)
|
||||
{
|
||||
SDKAPI.getIns().bindBySnsId(tmpSnsInfo, String.valueOf(newUserId), (bindCode, bindMsg) -> {
|
||||
Log.i(TAG, "bindBySnsId code: " + bindCode + " msg: " + bindMsg);
|
||||
if(bindCode == SDKCallBack.CODE_SUCCESS)
|
||||
{
|
||||
String msg = "{\"code\":0, \"userId\": " + newUserId + ", \"msg\": \"success\"}";
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = String.format("{\"code\":-1, \"userId\": 0, \"msg\": \"%s\"}", bindMsg);
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
String msg = String.format("{\"code\":1, \"userId\": 0, \"msg\": \"%s\"}", unbindMsg);
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.CHANGELINK_CALLBACK_FUNCTION_NAME, msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void LinkCheck(String type)
|
||||
{
|
||||
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
|
||||
|
||||
@@ -147,6 +147,20 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
NSInteger LoginTypeToBindType(NSInteger loginType)
|
||||
{
|
||||
switch (loginType) {
|
||||
case XYLoginWithApple:
|
||||
return XYBindApple;
|
||||
case XYLoginWithFB:
|
||||
return XYBindFB;
|
||||
case XYLoginWithGoogle:
|
||||
return XYBindGoodle;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const char* UnityLoginBySnsInfo()
|
||||
{
|
||||
NSLog(@"TYSdkInterface UnityLoginBySnsInfo");
|
||||
@@ -387,10 +401,6 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkGoogle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LinkFacebook(const int userId)
|
||||
{
|
||||
@@ -412,10 +422,6 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkFacebook()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LinkApple(const int userId)
|
||||
{
|
||||
@@ -437,11 +443,60 @@ extern "C" {
|
||||
}];
|
||||
}
|
||||
|
||||
void UnlinkApple()
|
||||
void ChangeLinkAccount(const int accoutType, const int oldUserId, const int newUserId)
|
||||
{
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount accoutType:%d oldUserId:%d newUserId:%d", accoutType, oldUserId, newUserId);
|
||||
|
||||
if (g_snsLoginType == -1)
|
||||
{
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult",
|
||||
"{\"code\":1, \"userId\": 0, \"msg\": \"g_snsLoginType is invalid\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
NSInteger bindTypeValue = LoginTypeToBindType(g_snsLoginType);
|
||||
if (bindTypeValue == -1)
|
||||
{
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult",
|
||||
"{\"code\":1, \"userId\": 0, \"msg\": \"unsupported account type\"}");
|
||||
return;
|
||||
}
|
||||
|
||||
XYBindType bindType = (XYBindType)bindTypeValue;
|
||||
|
||||
XYBindReq *unbindReq = [XYBindReq initUnBindWithPlatform:bindType UserId:(NSUInteger)oldUserId];
|
||||
[XYApi XYUnBindByBindReq:unbindReq completionHandler:^(XYResp * _Nonnull unbindResp) {
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount unbind code:%ld msg:%@", (long)unbindResp.errCode, unbindResp.errStr);
|
||||
|
||||
if (unbindResp.errCode == XYSuccess)
|
||||
{
|
||||
XYBindReq *bindReq = [XYBindReq initBindWithPlatform:bindType UserId:(NSUInteger)newUserId];
|
||||
[XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull bindResp) {
|
||||
NSLog(@"TYSdkInterface ChangeLinkAccount bind code:%ld msg:%@", (long)bindResp.errCode, bindResp.errStr);
|
||||
|
||||
if (bindResp.errCode == XYSuccess)
|
||||
{
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":0, \"userId\": %d, \"msg\": \"success\"}", newUserId];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *errStr = bindResp.errStr ? bindResp.errStr : @"bind failed";
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":-1, \"userId\": 0, \"msg\": \"%@\"}", errStr];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
}];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *errStr = unbindResp.errStr ? unbindResp.errStr : @"unbind failed";
|
||||
NSString *msg = [NSString stringWithFormat:@"{\"code\":1, \"userId\": 0, \"msg\": \"%@\"}", errStr];
|
||||
UnitySendMessage("TYSdkFacade", "ChangeLinkAccountResult", AllocCString(msg));
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
void FBShareLink(const char* title, const char* content, const char* url)
|
||||
{
|
||||
NSLog(@"TYSdkInterface FBShareLink");
|
||||
|
||||
@@ -364,6 +364,43 @@ namespace tysdk
|
||||
UnityBridgeFunc.CleanLinkTmpSnsInfo();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
var result = await task;
|
||||
if (result.code == 0)
|
||||
{
|
||||
_accountInfo.AddLinkedAccount(accoutType);
|
||||
_accountInfo.Save();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] Change link account failed: {e}");
|
||||
return new ChangeLinkResult() { code = 1 };
|
||||
}
|
||||
finally
|
||||
{
|
||||
CleanLinkTempSnSInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeLinkAccountResult(string message)
|
||||
{
|
||||
JObject data = JObject.Parse(message);
|
||||
var result = new ChangeLinkResult()
|
||||
{
|
||||
code = (int)data["code"],
|
||||
userId = (int)data["userId"],
|
||||
msg = (string)data["msg"]
|
||||
};
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否已经绑定
|
||||
/// <returns>
|
||||
|
||||
@@ -34,6 +34,13 @@ namespace tysdk
|
||||
public Dictionary<string, string> bindInfo;
|
||||
}
|
||||
|
||||
public class ChangeLinkResult
|
||||
{
|
||||
public int code;
|
||||
public int userId;
|
||||
public string msg;
|
||||
}
|
||||
|
||||
public class LinkCheckInfo
|
||||
{
|
||||
public int code;
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace tysdk
|
||||
|
||||
|
||||
public static void LinkAccount(EAccoutType accoutType){}
|
||||
public static void UnlinkAccount(EAccoutType accoutType){}
|
||||
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId){}
|
||||
public static void LinkCheck(EAccoutType accoutType){}
|
||||
|
||||
public static void UnityGetIdentityFun(string type){}
|
||||
@@ -149,11 +149,11 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnlinkAccount(EAccoutType accoutType)
|
||||
public static void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId)
|
||||
{
|
||||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
sdkManager.CallStatic("UnlinkAccount", accoutType.ToString());
|
||||
sdkManager.CallStatic("ChangeLinkAccount", accoutType.ToString(), oldUserId, newUserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,16 +298,16 @@ namespace tysdk
|
||||
}
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoginByGuest();
|
||||
private static extern void UnityLoginByGuest();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoginByGoogle();
|
||||
private static extern void UnityLoginByGoogle();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoginByFacebook();
|
||||
private static extern void UnityLoginByFacebook();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityLoginByApple();
|
||||
private static extern void UnityLoginByApple();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void UnityGetIdentityFun(string type);
|
||||
@@ -364,25 +364,13 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnlinkAccount(EAccoutType accoutType)
|
||||
{
|
||||
switch (accoutType)
|
||||
{
|
||||
case EAccoutType.hwGoogle:
|
||||
UnlinkGoogle();
|
||||
break;
|
||||
case EAccoutType.hwFacebook:
|
||||
UnlinkFacebook();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("__Internal")] private static extern void LinkGoogle(int userId);
|
||||
[DllImport("__Internal")] private static extern void UnlinkGoogle();
|
||||
[DllImport("__Internal")] private static extern void LinkFacebook(int userId);
|
||||
[DllImport("__Internal")] private static extern void UnlinkFacebook();
|
||||
[DllImport("__Internal")] private static extern void LinkApple(int userId);
|
||||
[DllImport("__Internal")] private static extern void UnlinkApple();
|
||||
|
||||
[DllImport("__Internal")]
|
||||
public static extern void ChangeLinkAccount(EAccoutType accoutType, int oldUserId, int newUserId);
|
||||
|
||||
public static void LinkCheck(EAccoutType accoutType)
|
||||
{
|
||||
@@ -401,6 +389,7 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DllImport("__Internal")] public static extern void CleanLinkTmpSnsInfo();
|
||||
|
||||
[DllImport("__Internal")] private static extern void IsLinkedGoogle();
|
||||
|
||||
Reference in New Issue
Block a user