diff --git a/sdk-intergration/Assets/Editor/BuildTool.cs b/sdk-intergration/Assets/Editor/BuildTool.cs index 54648d3..de28c55 100644 --- a/sdk-intergration/Assets/Editor/BuildTool.cs +++ b/sdk-intergration/Assets/Editor/BuildTool.cs @@ -133,13 +133,27 @@ public class BuildTool BuildParams bparams = new BuildParams() { - outPath = "../Bin" + outPath = "../Bin/tysdkTest.ipa" }; BuildiOS(bparams); } - private static void BuildiOS(BuildParams buildParams) + [MenuItem("Tools/Build iOS With Debug")] + public static void BuildiOSWithDebug() + { + + BuildParams bparams = new BuildParams() + { + outPath = "../Bin/tysdkTest_debug.ipa", + }; + + var buildOptions = BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.WaitForPlayerConnection; + + BuildiOS(bparams, buildOptions); + } + + private static void BuildiOS(BuildParams buildParams, BuildOptions buildOptions = BuildOptions.None) { var buildPlayerOptions = new BuildPlayerOptions @@ -148,7 +162,7 @@ public class BuildTool locationPathName = buildParams.outPath, target = BuildTarget.iOS, - options = BuildOptions.None, + options = buildOptions, }; var build_report = BuildPipeline.BuildPlayer(buildPlayerOptions); diff --git a/sdk-intergration/Assets/Scripts/UnbindTest.cs b/sdk-intergration/Assets/Scripts/UnbindTest.cs index 9c610ff..af5d466 100644 --- a/sdk-intergration/Assets/Scripts/UnbindTest.cs +++ b/sdk-intergration/Assets/Scripts/UnbindTest.cs @@ -67,6 +67,7 @@ public class UnbindTest : MonoBehaviour private void Init() { UnityBridgeFunc.UnityResetServerUrl("https://128-hwsfsdk-sdk-test01.qijihdhk.com"); + TYSdkFacade.Instance.CleanLinkTempSnSInfo(); } private void OnLogout() diff --git a/sdk-intergration/Packages/tysdk/Plugins/Android/SDKManager.java b/sdk-intergration/Packages/tysdk/Plugins/Android/SDKManager.java index d8b90ff..326708c 100644 --- a/sdk-intergration/Packages/tysdk/Plugins/Android/SDKManager.java +++ b/sdk-intergration/Packages/tysdk/Plugins/Android/SDKManager.java @@ -167,7 +167,6 @@ public class SDKManager { SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) ->{ if(snscode == SDKCallBack.CODE_SUCCESS && snsInfo !=null) { - tmpSnsInfo = snsInfo; SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg)->{ if(bindcode == SDKCallBack.CODE_SUCCESS) { @@ -214,6 +213,7 @@ public class SDKManager { // "userId":10030 // } // } + tmpSnsInfo = snsInfo; JSONObject checkMsgObj = new JSONObject(checkMsg); JSONObject checkResult = checkMsgObj.getJSONObject("result"); String bindInfo = checkResult.getString("bindInfo"); @@ -260,6 +260,11 @@ public class SDKManager { } }); } + + public static void CleanLinkTmpSnsInfo() + { + tmpSnsInfo = null; + } public static void LinkCheck(String type) { diff --git a/sdk-intergration/Packages/tysdk/Plugins/iOS/TYSDKInterface.mm b/sdk-intergration/Packages/tysdk/Plugins/iOS/TYSDKInterface.mm index 40bfb8a..58cce1f 100644 --- a/sdk-intergration/Packages/tysdk/Plugins/iOS/TYSDKInterface.mm +++ b/sdk-intergration/Packages/tysdk/Plugins/iOS/TYSDKInterface.mm @@ -9,6 +9,9 @@ #define TOKEN_ERROR @"-8" extern "C" { + // Store last login type for SNS re-login + static NSInteger g_snsLoginType = -1; + NSString* DicTojsonString(NSDictionary *dict) { try { @@ -33,11 +36,15 @@ extern "C" { [resultDict setValue:[NSString stringWithFormat:@"%ld", (long)resp.errCode] forKey:@"code"]; [resultDict setValue:resp.errStr ? resp.errStr : @"" forKey:@"errStr"]; if(resp.errCode == XYSuccess){ - [resultDict setValue:resp.respObj forKey:@"respObj"]; + NSDictionary *respObjDict = (NSDictionary*)resp.respObj; + NSDictionary *resultDictData = (NSDictionary*)[respObjDict objectForKey:@"result"]; + NSMutableDictionary *loginData = [resultDictData mutableCopy]; + [resultDict setValue:loginData forKey:@"loginData"]; } NSString *result = DicTojsonString(resultDict); const char* param = AllocCString(result); UnitySendMessage("TYSdkFacade","LoginResult", param); + g_snsLoginType = -1; } //更新登录支付域名 @@ -85,7 +92,6 @@ extern "C" { { XYLoginReq *req = [XYLoginReq initWithLoginType:XYLoginWithGoogle]; [XYApi XYLoginWith:req completionHandler:^(XYResp * _Nonnull resp) { - NSLog(@"TYSdkInterface UnityLoginByGoogle: %@", resp); ProcessLoginResult(resp); }]; } @@ -113,9 +119,64 @@ extern "C" { } + char* LoginTypeToStr(XYLoginType loginType) + { + switch (loginType) { + case XYLoginWithFB: + return AllocCString(@"hwFacebook"); + case XYLoginWithApple: + return AllocCString(@"Apple"); + case XYLoginWithGoogle: + return AllocCString(@"hwGoogle"); + default: + return nil; + } + } + + NSInteger BindTypeToLoginType(XYBindType bType) + { + switch (bType) { + case XYBindApple: + return XYLoginWithApple; + case XYBindFB: + return XYLoginWithFB; + case XYBindGoodle: + return XYLoginWithGoogle; + default: + return -1; + } + } + + const char* UnityLoginBySnsInfo() + { + NSLog(@"TYSdkInterface UnityLoginBySnsInfo"); + + if(g_snsLoginType == -1) + { + NSLog(@"TYSdkInterface UnityLoginBySnsInfo - No stored login type"); + UnitySendMessage("TYSdkFacade","LoginResult", "{\"code\":1}"); + + // Return empty string + return ""; + } + + NSLog(@"TYSdkInterface UnityLoginBySnsInfo - Re-login with type: %s", LoginTypeToStr((XYLoginType)g_snsLoginType)); + + // Re-login using the stored type + XYLoginReq *req = [XYLoginReq initWithLoginType:(XYLoginType)g_snsLoginType]; + [XYApi XYLoginWith:req completionHandler:^(XYResp * _Nonnull resp) { + NSLog(@"TYSdkInterface UnityLoginBySnsInfo result: %@", resp); + ProcessLoginResult(resp); + }]; + + // Return the login type as C string + return LoginTypeToStr((XYLoginType)g_snsLoginType); + } + void UnityLoginOut() { NSLog(@"TYSdkInterface UnityLoginOut"); + [XYApi XYLogoutWithCompletion:^(XYResp * _Nonnull resp) { if(resp.errCode == XYSuccess) { @@ -127,7 +188,7 @@ extern "C" { NSLog(@"TYSdkInterface UnityLoginOut Faild"); NSLog(@"Error Code:%ld msg:%@", resp.errCode, resp.errStr); } - + }]; } @@ -234,27 +295,85 @@ extern "C" { [gaSDK track:dic type:GAEventType(type) event:nsEvent]; } } - - void LinkGoogle(const int userId) + + void CleanLinkTmpSnsInfo() { - NSLog(@"TYSdkInterface LinkGoogle"); - NSDictionary * userDic = [XYApi XYGetCurrentUserDict]; - XYBindReq *bindReq = [XYBindReq initBindWithPlatform:XYBindGoodle UserId: [ [userDic objectForKey:@"userId"] unsignedIntegerValue]]; + g_snsLoginType = -1; + } + + // Helper function to handle account linking + typedef void(^LogoutCallback)(void); + + void LinkAccountWithPlatform(NSString *platformName, XYBindType bindType, const int userId, LogoutCallback logoutCallback) + { + NSLog(@"TYSdkInterface Link%@ userId:%d", platformName, userId); + + XYBindReq *bindReq = [XYBindReq initBindWithPlatform:bindType UserId:(NSUInteger)userId]; + [XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull resp) { + NSMutableDictionary *resultDict = [@{} mutableCopy]; + if(resp.errCode == XYSuccess) { - NSLog(@"TYSdkInterface LinkGoogle Success"); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "1"); + NSLog(@"TYSdkInterface Link%@ Success", platformName); + NSDictionary *respObjDict = (NSDictionary*)resp.respObj; + NSDictionary *resultDictData = (NSDictionary*)[respObjDict objectForKey:@"result"]; + NSMutableDictionary *loginData = [resultDictData mutableCopy]; + + [resultDict setValue:[NSString stringWithFormat:@"%ld", (long)resp.errCode] forKey:@"code"]; + [resultDict setValue:[NSString stringWithFormat:@"%d", userId] forKey:@"userId"]; + [resultDict setValue:loginData forKey:@"loginData"]; + + NSString *result = DicTojsonString(resultDict); + const char* param = AllocCString(result); + UnitySendMessage("TYSdkFacade","LinkAccoutResult", param); + } + else if(resp.errCode == XYErrCodeHadBind) + { + [XYApi CheckUserExist:bindType completion:^(XYResp * _Nonnull snscheckResp) { + if(snscheckResp.errCode != 0) + { + [resultDict setValue:@"1" forKey:@"code"]; + [resultDict setValue:@"0" forKey:@"userId"]; + NSString *result = DicTojsonString(resultDict); + const char* param = AllocCString(result); + UnitySendMessage("TYSdkFacade","LinkAccoutResult", param); + } + else + { + g_snsLoginType = BindTypeToLoginType(bindType); + NSDictionary *respObjDict = (NSDictionary*)snscheckResp.respObj; + [resultDict setValue:@"-1" forKey:@"code"]; + [resultDict setValue:[respObjDict objectForKey:@"bindInfo"] forKey:@"bindInfo"]; + [resultDict setValue:[respObjDict objectForKey:@"userId"] forKey:@"userId"]; + NSString *result = DicTojsonString(resultDict); + const char* param = AllocCString(result); + UnitySendMessage("TYSdkFacade","LinkAccoutResult", param); + } + }]; } else { - NSLog(@"TYSdkInterface LinkGoogle Faild"); - UnityLogoutGoogle(); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "0"); + NSLog(@"TYSdkInterface Link%@ Failed errCode:%ld", platformName, (long)resp.errCode); + if (logoutCallback) { + logoutCallback(); + } + [resultDict setValue:@"1" forKey:@"code"]; + [resultDict setValue:@"0" forKey:@"userId"]; + NSString *result = DicTojsonString(resultDict); + const char* param = AllocCString(result); + UnitySendMessage("TYSdkFacade","LinkAccoutResult", param); } }]; } + void LinkGoogle(const int userId) + { + LinkAccountWithPlatform(@"Google", XYBindGoodle, userId, ^{ + UnityLogoutGoogle(); + }); + } + void IsLinkedGoogle() { [XYApi CheckUserExist:XYBindGoodle completion:^(XYResp * _Nonnull resp) { @@ -275,23 +394,9 @@ extern "C" { void LinkFacebook(const int userId) { - NSLog(@"TYSdkInterface LinkFacebook"); - NSDictionary * userDic = [XYApi XYGetCurrentUserDict]; - XYBindReq *bindReq = [XYBindReq initBindWithPlatform:XYBindFB UserId: [ [userDic objectForKey:@"userId"] unsignedIntegerValue]]; - [XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull resp) { - if(resp.errCode == XYSuccess) - { - NSLog(@"TYSdkInterface LinkFacebook Success"); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "1"); - } - else - { - NSLog(@"TYSdkInterface LinkFacebook Faild"); - UnityLogoutFacebook(); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "0"); - - } - }]; + LinkAccountWithPlatform(@"Facebook", XYBindFB, userId, ^{ + UnityLogoutFacebook(); + }); } void IsLinkedFacebook() @@ -312,26 +417,11 @@ extern "C" { } - void LinkApple() + void LinkApple(const int userId) { - - NSLog(@"TYSdkInterface LinkApple"); - NSDictionary * userDic = [XYApi XYGetCurrentUserDict]; - XYBindReq *bindReq = [XYBindReq initBindWithPlatform:XYBindApple UserId: [ [userDic objectForKey:@"userId"] unsignedIntegerValue]]; - [XYApi XYBindByBindReq:bindReq isUnbindGuest:@"false" completionHandler:^(XYResp * _Nonnull resp) { - if(resp.errCode == XYSuccess) - { - NSLog(@"TYSdkInterface LinkApple Success"); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "1"); - } - else - { - NSLog(@"TYSdkInterface LinkApple Faild"); - UnityLogoutApple(); - UnitySendMessage("TYSdkFacade","LinkAccoutResult", "0"); - - } - }]; + LinkAccountWithPlatform(@"Apple", XYBindApple, userId, ^{ + UnityLogoutApple(); + }); } void IsLinkedApple() diff --git a/sdk-intergration/Packages/tysdk/Runtime/TYSdkFacade.cs b/sdk-intergration/Packages/tysdk/Runtime/TYSdkFacade.cs index b304e49..82821c6 100644 --- a/sdk-intergration/Packages/tysdk/Runtime/TYSdkFacade.cs +++ b/sdk-intergration/Packages/tysdk/Runtime/TYSdkFacade.cs @@ -387,6 +387,10 @@ namespace tysdk TYSDKCallbackManager.Instance.TryTriggerCallback(result); } #endif + public void CleanLinkTempSnSInfo() + { + UnityBridgeFunc.CleanLinkTmpSnsInfo(); + } /// /// 检查是否已经绑定 diff --git a/sdk-intergration/Packages/tysdk/Runtime/UnityBridgeFunc.cs b/sdk-intergration/Packages/tysdk/Runtime/UnityBridgeFunc.cs index f28ddc4..b4d883d 100644 --- a/sdk-intergration/Packages/tysdk/Runtime/UnityBridgeFunc.cs +++ b/sdk-intergration/Packages/tysdk/Runtime/UnityBridgeFunc.cs @@ -21,6 +21,10 @@ namespace tysdk public static string UnityLoginBySnsInfoFun() => null; public static void UnityLogin(EAccoutType accoutType){} + + public static void CleanLinkTmpSnsInfo() { } + + public static void LinkAccount(EAccoutType accoutType){} public static void UnlinkAccount(EAccoutType accoutType){} public static void LinkCheck(EAccoutType accoutType){} @@ -135,6 +139,16 @@ namespace tysdk } } + public static void CleanLinkTmpSnsInfo(){ + using(var sdkManager = new AndroidJavaClass(SDK_CLASS)) + { + using(var activityCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) + { + sdkManager.CallStatic("CleanLinkTmpSnsInfo"); + } + } + } + public static void UnlinkAccount(EAccoutType accoutType) { using(var sdkManager = new AndroidJavaClass(SDK_CLASS)) @@ -247,6 +261,23 @@ namespace tysdk [DllImport("__Internal")] public static extern void UnityLoginByTokenFun(string token); + [DllImport("__Internal")] + private static extern IntPtr UnityLoginBySnsInfo(); + + public static string UnityLoginBySnsInfoFun() + { + IntPtr ptr = UnityLoginBySnsInfo(); + + if (ptr == IntPtr.Zero) + { + return string.Empty; + } + + // Convert C string to C# string + string result = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr); + return result ?? string.Empty; + } + public static void UnityLogin(EAccoutType accoutType) { switch (accoutType) @@ -317,16 +348,18 @@ namespace tysdk public static void LinkAccount(EAccoutType accoutType) { + var userId = TYSdkFacade.TYAccountInfo.userId; + switch (accoutType) { case EAccoutType.hwGoogle: - LinkGoogle(); + LinkGoogle(userId); break; case EAccoutType.hwFacebook: - LinkFacebook(); + LinkFacebook(userId); break; case EAccoutType.Apple: - LinkApple(); + LinkApple(userId); break; } } @@ -344,11 +377,11 @@ namespace tysdk } } - [DllImport("__Internal")] private static extern void LinkGoogle(); + [DllImport("__Internal")] private static extern void LinkGoogle(int userId); [DllImport("__Internal")] private static extern void UnlinkGoogle(); - [DllImport("__Internal")] private static extern void LinkFacebook(); + [DllImport("__Internal")] private static extern void LinkFacebook(int userId); [DllImport("__Internal")] private static extern void UnlinkFacebook(); - [DllImport("__Internal")] private static extern void LinkApple(); + [DllImport("__Internal")] private static extern void LinkApple(int userId); [DllImport("__Internal")] private static extern void UnlinkApple(); public static void LinkCheck(EAccoutType accoutType) @@ -368,6 +401,8 @@ namespace tysdk } } + [DllImport("__Internal")] public static extern void CleanLinkTmpSnsInfo(); + [DllImport("__Internal")] private static extern void IsLinkedGoogle(); [DllImport("__Internal")] private static extern void IsLinkedFacebook(); [DllImport("__Internal")] private static extern void IsLinkedApple();