update:更新接口的修改
This commit is contained in:
@@ -106,6 +106,9 @@ namespace tysdk
|
||||
|
||||
private static TYSdkFacade _instance;
|
||||
public static bool IsSdkInited { get; private set; }
|
||||
public static bool IsInitStarted { get; private set; }
|
||||
public static bool HasInitResult { get; private set; }
|
||||
public static string LastInitMessage { get; private set; }
|
||||
public static event System.Action<bool, string> OnInitComplete;
|
||||
|
||||
public static TYSdkFacade Instance
|
||||
@@ -122,7 +125,10 @@ namespace tysdk
|
||||
}
|
||||
public void Init()
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] Init()");
|
||||
Debug.Log("[FLX-INIT] TYSdkFacade Init");
|
||||
IsInitStarted = true;
|
||||
HasInitResult = false;
|
||||
LastInitMessage = string.Empty;
|
||||
#if UNITY_ANDROID
|
||||
UnityBridgeFunc.InitSDK(ChannelConfig.Channel);
|
||||
#endif
|
||||
@@ -131,13 +137,13 @@ namespace tysdk
|
||||
|
||||
public void SetChannelFromNative(string channel)
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] SetChannelFromNative: {channel}");
|
||||
// Debug.Log($"[TYSdkFacade] SetChannelFromNative: {channel}");
|
||||
ChannelConfig.SetChannel(channel);
|
||||
}
|
||||
|
||||
public void InitResult(string json)
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] InitResult: {json}");
|
||||
Debug.Log($"[FLX-INIT] TYSdkFacade InitResult: {json}");
|
||||
var success = false;
|
||||
var msg = string.Empty;
|
||||
|
||||
@@ -154,6 +160,8 @@ namespace tysdk
|
||||
}
|
||||
|
||||
IsSdkInited = success;
|
||||
HasInitResult = true;
|
||||
LastInitMessage = msg;
|
||||
OnInitComplete?.Invoke(success, msg);
|
||||
}
|
||||
|
||||
@@ -173,7 +181,7 @@ namespace tysdk
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
UnityEngine.Debug.Log("Logout");
|
||||
// UnityEngine.Debug.Log("Logout");
|
||||
if (_accountInfo != null)
|
||||
{
|
||||
UnityBridgeFunc.UnityLogOutByChannel(_accountInfo.channel);
|
||||
@@ -253,7 +261,7 @@ namespace tysdk
|
||||
|
||||
public async Task<LoginInfo> LoginBySns()
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] LoginBySns");
|
||||
// Debug.Log("[TYSdkFacade] LoginBySns");
|
||||
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<LoginInfo>(TimeSpan.FromSeconds(30));
|
||||
|
||||
@@ -286,7 +294,7 @@ namespace tysdk
|
||||
|
||||
public void LoginResult(string json)
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] Login callback:");
|
||||
// Debug.Log("[TYSdkFacade] Login callback:");
|
||||
var result = new LoginInfo();
|
||||
var data = JObject.Parse(json);
|
||||
var code = (int)data["code"];
|
||||
@@ -553,7 +561,7 @@ namespace tysdk
|
||||
//对sign进行MD5加密
|
||||
string signMd5 = CalculateMD5Hash(sign);
|
||||
string url = $"{tycs}?{listStr}&sign={signMd5}&isAbroad=1&lan=en";
|
||||
Debug.Log($"[TYSdkFacade:Signout] url \n{url}");
|
||||
// Debug.Log($"[TYSdkFacade:Signout] url \n{url}");
|
||||
Application.OpenURL(url);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace tysdk
|
||||
string extraInfo = purchaseInfo.ToString(Newtonsoft.Json.Formatting.None);
|
||||
//to base64
|
||||
extraInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(extraInfo));
|
||||
Debug.Log("[TYSdk] extraInfo: " + extraInfo);
|
||||
// Debug.Log("[TYSdk] extraInfo: " + extraInfo);
|
||||
var prodId = prod.ProdID;
|
||||
var prodPrice = usdprice.ToString();
|
||||
var prodName = prod.title;
|
||||
@@ -68,7 +68,6 @@ namespace tysdk
|
||||
result.orderId = orderId;
|
||||
result.productId = prodId;
|
||||
result.price = prodPrice;
|
||||
result.Check(orderId, prodId);
|
||||
return result;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -109,7 +108,7 @@ namespace tysdk
|
||||
//支付的回调
|
||||
public void PayResult(string json)
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] pay callback:" + json);
|
||||
// Debug.Log("[TYSdkFacade] pay callback:" + json);
|
||||
var jresult = JObject.Parse(json);
|
||||
var result = new PaymentInfo();
|
||||
result.code = jresult["code"].ToString();
|
||||
@@ -204,20 +203,71 @@ namespace tysdk
|
||||
//商品列表的回调
|
||||
public void SKUListResult(string json)
|
||||
{
|
||||
Debug.Log("[TYSdkFacade] GetSKUList callback");
|
||||
var jresult = JObject.Parse(json);
|
||||
int code = int.Parse(jresult["code"].ToString());
|
||||
// Debug.Log("[TYSdkFacade] GetSKUList callback");
|
||||
var result = new ProductListInfo();
|
||||
if (code == 0)
|
||||
try
|
||||
{
|
||||
string productStr = jresult["respObj"].ToString();
|
||||
var jresult = JObject.Parse(json);
|
||||
int code = jresult["code"]?.Value<int>() ?? 1;
|
||||
result.code = code;
|
||||
if (code == 0)
|
||||
{
|
||||
string productStr = jresult["respObj"]?.ToString();
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
var jsonObjList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SKUDetail>>(productStr);
|
||||
result.products = jsonObjList;
|
||||
var jsonObjList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<SKUDetail>>(productStr);
|
||||
result.products = jsonObjList;
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
result.ReadSKUFromJson(productStr);
|
||||
result.ReadSKUFromJson(productStr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] SKUListResult parse failed: {e.Message}");
|
||||
result.code = 1;
|
||||
result.msg = e.Message;
|
||||
}
|
||||
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
}
|
||||
|
||||
public async Task<PendingPurchaseListInfo> QueryPendingPurchases()
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
var task = TYSDKCallbackManager.Instance.RegisterCallback<PendingPurchaseListInfo>(TimeSpan.FromSeconds(30));
|
||||
UnityBridgeFunc.QueryPendingPurchases();
|
||||
try
|
||||
{
|
||||
return await task;
|
||||
}
|
||||
catch (TaskCanceledException e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] QueryPendingPurchases timeout: {e.Message}");
|
||||
return new PendingPurchaseListInfo { code = 1, msg = "pending_purchase_callback_timeout" };
|
||||
}
|
||||
#else
|
||||
await Task.Yield();
|
||||
return new PendingPurchaseListInfo { code = 0, purchasesJson = "[]" };
|
||||
#endif
|
||||
}
|
||||
|
||||
public void PendingPurchasesResult(string json)
|
||||
{
|
||||
Debug.Log($"[TYSdkFacade] PendingPurchasesResult: {json}");
|
||||
var result = new PendingPurchaseListInfo();
|
||||
try
|
||||
{
|
||||
var jresult = JObject.Parse(json);
|
||||
result.code = jresult["code"]?.Value<int>() ?? 1;
|
||||
result.msg = jresult["errStr"]?.ToString() ?? string.Empty;
|
||||
result.purchasesJson = jresult["respObj"]?.ToString() ?? "[]";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogWarning($"[TYSdkFacade] PendingPurchasesResult parse failed: {e.Message}");
|
||||
result.code = 1;
|
||||
result.msg = e.Message;
|
||||
result.purchasesJson = "[]";
|
||||
}
|
||||
|
||||
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
|
||||
|
||||
@@ -158,6 +158,13 @@ namespace tysdk
|
||||
|
||||
}
|
||||
|
||||
public class PendingPurchaseListInfo
|
||||
{
|
||||
public int code = 1;
|
||||
public string msg = string.Empty;
|
||||
public string purchasesJson = "[]";
|
||||
}
|
||||
|
||||
#if UNITY_IOS
|
||||
public class SKUDetail
|
||||
{
|
||||
|
||||
@@ -46,10 +46,12 @@ namespace tysdk
|
||||
|
||||
public static void ConsumePurchase(string token) { }
|
||||
|
||||
public static string GetPendingPurchases() => "[]";
|
||||
public static void QueryPendingPurchases() { }
|
||||
|
||||
public static void RefreshBillingService() { }
|
||||
|
||||
public static bool IsGooglePlayServicesAvailable() { return true; }
|
||||
|
||||
//打点
|
||||
public static void SetGaUserInfo(string userId){}
|
||||
public static void SetGaCommonInfo(string SetGaCommonInfo){}
|
||||
@@ -218,11 +220,11 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetPendingPurchases()
|
||||
public static void QueryPendingPurchases()
|
||||
{
|
||||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
return sdkManager.CallStatic<string>("GetPendingPurchases");
|
||||
sdkManager.CallStatic("QueryPendingPurchases");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,6 +246,14 @@ namespace tysdk
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsGooglePlayServicesAvailable()
|
||||
{
|
||||
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
|
||||
{
|
||||
return sdkManager.CallStatic<bool>("IsGooglePlayServicesAvailable");
|
||||
}
|
||||
}
|
||||
|
||||
//打点
|
||||
public static void SetGaUserInfo(string userId)
|
||||
{
|
||||
@@ -479,10 +489,12 @@ namespace tysdk
|
||||
|
||||
public static void ConsumePurchase(string token) { }
|
||||
|
||||
public static string GetPendingPurchases() => "[]";
|
||||
public static void QueryPendingPurchases() { }
|
||||
|
||||
public static void RefreshBillingService() { }
|
||||
|
||||
public static bool IsGooglePlayServicesAvailable() { return true; }
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user