[M] change sns link function
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ bin_BurstDebugInformation_DoNotShip
|
|||||||
sdk-intergration/.vscode
|
sdk-intergration/.vscode
|
||||||
sdk-intergration/'
|
sdk-intergration/'
|
||||||
sdk-intergration/Assets/.claude/settings.json
|
sdk-intergration/Assets/.claude/settings.json
|
||||||
|
sdk-intergration/.idea
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
package com.unity3d.player;
|
package com.unity3d.player;
|
||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ dependencies {
|
|||||||
|
|
||||||
// Android Resolver Exclusions Start
|
// Android Resolver Exclusions Start
|
||||||
android {
|
android {
|
||||||
namespace "com.unity3d.player"
|
|
||||||
packagingOptions {
|
packagingOptions {
|
||||||
exclude ('/lib/armeabi/*' + '*')
|
exclude ('/lib/armeabi/*' + '*')
|
||||||
exclude ('/lib/mips/*' + '*')
|
exclude ('/lib/mips/*' + '*')
|
||||||
|
|||||||
@@ -59,10 +59,8 @@ public class UnbindTest : MonoBehaviour
|
|||||||
checkSnsBtn.onClick.AddListener(OnCheckSns);
|
checkSnsBtn.onClick.AddListener(OnCheckSns);
|
||||||
bindBtn.onClick.AddListener(OnBind);
|
bindBtn.onClick.AddListener(OnBind);
|
||||||
unbindBtn.onClick.AddListener(OnUnbind);
|
unbindBtn.onClick.AddListener(OnUnbind);
|
||||||
|
|
||||||
Debug.Log("========== Init =============");
|
Debug.Log("========== Init =============");
|
||||||
TYSdkFacade.Instance.Init();
|
TYSdkFacade.Instance.Init();
|
||||||
|
|
||||||
Debug.Log($"AccoutType {accoutType}");
|
Debug.Log($"AccoutType {accoutType}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +107,11 @@ public class UnbindTest : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBind()
|
private async void OnBind()
|
||||||
{
|
{
|
||||||
Debug.Log("========== Bind =============");
|
Debug.Log("========== Bind =============");
|
||||||
using (var t = new AndroidJavaClass(Cls))
|
var linkResult = await TYSdkFacade.Instance.LinkAccount(accoutType);
|
||||||
{
|
Debug.Log($"Bind Result Code:{linkResult.code}, UserId:{linkResult.userId}, bindInfo:{linkResult.bindInfo}");
|
||||||
t.CallStatic("Bind", accoutType.ToString(), loginInfo.StrUserId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void BindCallback(string message)
|
public void BindCallback(string message)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public class ConfigManager {
|
|||||||
|
|
||||||
public static final String UNITY_FACADE_NAME = "TYSdkFacade";
|
public static final String UNITY_FACADE_NAME = "TYSdkFacade";
|
||||||
public static final String LOGIN_CALLBACK_FUNCTION_NAME = "LoginResult";
|
public static final String LOGIN_CALLBACK_FUNCTION_NAME = "LoginResult";
|
||||||
|
public static final String LINKACCOUT_CALLBACK_FUNCTION_NAME = "LinkAccoutResult";
|
||||||
public static final String CHECKLINK_CALLBACK_FUNCTION_NAME = "CheckLinkResult";
|
public static final String CHECKLINK_CALLBACK_FUNCTION_NAME = "CheckLinkResult";
|
||||||
public static final String PAY_CALLBACK_FUNCTION_NAME = "PayResult";
|
public static final String PAY_CALLBACK_FUNCTION_NAME = "PayResult";
|
||||||
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
|
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
|
||||||
|
|||||||
@@ -161,12 +161,87 @@ public class SDKManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void LinkAccount(String type, String userId)
|
public static void LinkAccount(String type, String userId)
|
||||||
{
|
{
|
||||||
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
|
SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) ->{
|
||||||
if(code == SDKCallBack.CODE_SUCCESS && snsInfo != null){
|
if(snscode == SDKCallBack.CODE_SUCCESS && snsInfo !=null)
|
||||||
SDKAPI.getIns().bindBySnsId(snsInfo, userId, mLogin);
|
{
|
||||||
}else {
|
SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg)->{
|
||||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}}");
|
if(bindcode == SDKCallBack.CODE_SUCCESS)
|
||||||
|
{
|
||||||
|
String msg = "{\"code\":0, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
}
|
||||||
|
else if(bindcode == 1)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JSONObject bindMsgObj = new JSONObject(bindmsg);
|
||||||
|
JSONObject bindMsgResult = bindMsgObj.getJSONObject("result");
|
||||||
|
int bindMsgResultCode = bindMsgResult.getInt("code");
|
||||||
|
if(bindMsgResultCode == 4)
|
||||||
|
{
|
||||||
|
SDKAPI.getIns().checkSnsInfo(snsInfo, (checkcode, checkMsg ) -> {
|
||||||
|
if(checkcode != SDKCallBack.CODE_SUCCESS)
|
||||||
|
{
|
||||||
|
Log.w(TAG, checkMsg);
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
//{
|
||||||
|
// "track":"128:10:28654792:1766569516",
|
||||||
|
// "result":{
|
||||||
|
// "bindInfo":"{ // \"guest\": \"guest:devidmap3:bf12a8a28b663548e368ebe8742368b7\", // \"google\": \"google:118182347502471840780\" // }",
|
||||||
|
// "code":0,
|
||||||
|
// "info":"user exist",
|
||||||
|
// "exist":1,
|
||||||
|
// "userId":10030
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
JSONObject checkMsgObj = new JSONObject(checkMsg);
|
||||||
|
JSONObject checkResult = checkMsgObj.getJSONObject("result");
|
||||||
|
String bindInfo = checkResult.getString("bindInfo");
|
||||||
|
int bindUserId = checkResult.getInt("userId");
|
||||||
|
JSONObject callbackMsg = new JSONObject();
|
||||||
|
callbackMsg.put("code", -1);
|
||||||
|
callbackMsg.put("userId", bindUserId);
|
||||||
|
callbackMsg.put("bindInfo", bindInfo);
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, callbackMsg.toString());
|
||||||
|
} catch (JSONException e) {
|
||||||
|
Log.i(TAG, e.toString());
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.w(TAG, bindmsg);
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException e)
|
||||||
|
{
|
||||||
|
Log.i(TAG, e.toString());
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.w(TAG, bindmsg);
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.w(TAG, snsmsg);
|
||||||
|
String msg = "{\"code\":1, \"userId\": 0}";
|
||||||
|
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LINKACCOUT_CALLBACK_FUNCTION_NAME, msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,16 +273,16 @@ namespace tysdk
|
|||||||
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
public async Task<bool> LinkAccount(EAccoutType accoutType)
|
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||||
{
|
{
|
||||||
await Task.Delay(300);
|
await Task.Delay(300);
|
||||||
return true;
|
return new LinkResult(){code = 1};
|
||||||
}
|
}
|
||||||
#elif UNITY_IOS || UNITY_ANDROID
|
#elif UNITY_IOS || UNITY_ANDROID
|
||||||
public async Task<bool> LinkAccount(EAccoutType accoutType)
|
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||||
{
|
{
|
||||||
if (_accountInfo == null) return false;
|
if (_accountInfo == null) return new LinkResult(){ code = 1};
|
||||||
if (_accountInfo.linkedAccout.Contains(accoutType)) return true;
|
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult(){ code = 0};
|
||||||
|
|
||||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LinkResult>();
|
var task = TYSDKCallbackManager.Instance.RegisterCallback<LinkResult>();
|
||||||
UnityBridgeFunc.LinkAccount(accoutType);
|
UnityBridgeFunc.LinkAccount(accoutType);
|
||||||
@@ -290,7 +290,7 @@ namespace tysdk
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = await task;
|
var result = await task;
|
||||||
if (result.isSuccess)
|
if (result.code == 0)
|
||||||
{
|
{
|
||||||
if (_accountInfo == null)
|
if (_accountInfo == null)
|
||||||
_accountInfo = AccountInfo.GetSavedAccoutInfo();
|
_accountInfo = AccountInfo.GetSavedAccoutInfo();
|
||||||
@@ -301,20 +301,22 @@ namespace tysdk
|
|||||||
_accountInfo.Save();
|
_accountInfo.Save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.isSuccess;
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"[TYSdkFacade] Link account failed: {e}");
|
Debug.LogWarning($"[TYSdkFacade] Link account failed: {e}");
|
||||||
return false;
|
return new LinkResult() { code = 1 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LinkAccoutResult(string codestr)
|
public void LinkAccoutResult(string message)
|
||||||
{
|
{
|
||||||
|
JObject data = new JObject(message);
|
||||||
var result = new LinkResult()
|
var result = new LinkResult()
|
||||||
{
|
{
|
||||||
isSuccess = codestr == "1"
|
code = data["code"].Value<int>(),
|
||||||
|
userId = data["userId"].Value<int>()
|
||||||
};
|
};
|
||||||
|
|
||||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace tysdk
|
|||||||
none
|
none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class LoginInfo
|
public class LoginInfo
|
||||||
{
|
{
|
||||||
public bool isSuccess;
|
public bool isSuccess;
|
||||||
@@ -25,7 +24,13 @@ namespace tysdk
|
|||||||
|
|
||||||
public class LinkResult
|
public class LinkResult
|
||||||
{
|
{
|
||||||
public bool isSuccess;
|
// 0: success, 1: fail, -1 exists
|
||||||
|
public int code;
|
||||||
|
// when success and fail userId is current user
|
||||||
|
// when exists userId is 0
|
||||||
|
public int userId;
|
||||||
|
// not none when exists
|
||||||
|
public string bindInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LinkCheckInfo
|
public class LinkCheckInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user