[M] change sns link function
This commit is contained in:
@@ -21,6 +21,7 @@ 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 CHECKLINK_CALLBACK_FUNCTION_NAME = "CheckLinkResult";
|
||||
public static final String PAY_CALLBACK_FUNCTION_NAME = "PayResult";
|
||||
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)
|
||||
{
|
||||
SDKAPI.getIns().getSnsInfo(type, (code, snsInfo, msg) -> {
|
||||
if(code == SDKCallBack.CODE_SUCCESS && snsInfo != null){
|
||||
SDKAPI.getIns().bindBySnsId(snsInfo, userId, mLogin);
|
||||
}else {
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME, ConfigManager.LOGIN_CALLBACK_FUNCTION_NAME, "{\"code\":1}}");
|
||||
{
|
||||
SDKAPI.getIns().getSnsInfo(type, (snscode, snsInfo, snsmsg) ->{
|
||||
if(snscode == SDKCallBack.CODE_SUCCESS && snsInfo !=null)
|
||||
{
|
||||
SDKAPI.getIns().bindBySnsId(snsInfo, userId, (bindcode, bindmsg)->{
|
||||
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
|
||||
public async Task<bool> LinkAccount(EAccoutType accoutType)
|
||||
public async Task<LinkResult> LinkAccount(EAccoutType accoutType)
|
||||
{
|
||||
await Task.Delay(300);
|
||||
return true;
|
||||
return new LinkResult(){code = 1};
|
||||
}
|
||||
#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.linkedAccout.Contains(accoutType)) return true;
|
||||
if (_accountInfo == null) return new LinkResult(){ code = 1};
|
||||
if (_accountInfo.linkedAccout.Contains(accoutType)) return new LinkResult(){ code = 0};
|
||||
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LinkResult>();
|
||||
UnityBridgeFunc.LinkAccount(accoutType);
|
||||
@@ -290,7 +290,7 @@ namespace tysdk
|
||||
try
|
||||
{
|
||||
var result = await task;
|
||||
if (result.isSuccess)
|
||||
if (result.code == 0)
|
||||
{
|
||||
if (_accountInfo == null)
|
||||
_accountInfo = AccountInfo.GetSavedAccoutInfo();
|
||||
@@ -301,20 +301,22 @@ namespace tysdk
|
||||
_accountInfo.Save();
|
||||
}
|
||||
}
|
||||
return result.isSuccess;
|
||||
return result;
|
||||
}
|
||||
catch (Exception 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()
|
||||
{
|
||||
isSuccess = codestr == "1"
|
||||
code = data["code"].Value<int>(),
|
||||
userId = data["userId"].Value<int>()
|
||||
};
|
||||
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace tysdk
|
||||
Apple,
|
||||
none
|
||||
}
|
||||
|
||||
|
||||
public class LoginInfo
|
||||
{
|
||||
@@ -25,7 +24,13 @@ namespace tysdk
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user