update:更新接口的修改

This commit is contained in:
2026-06-05 16:57:07 +08:00
parent 4d3eae1c88
commit ea03c8023f
7 changed files with 566 additions and 193 deletions

View File

@@ -16,6 +16,8 @@ import com.barton.log.logapi.IGASDK;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.MessageDialog;
import com.facebook.share.widget.ShareDialog;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.tasks.Task;
import com.google.android.play.core.review.ReviewException;
import com.google.android.play.core.review.ReviewInfo;
@@ -73,7 +75,7 @@ public class SDKManager {
}
public interface IPendingPurchaseAdapter {
String getPendingPurchases();
void queryPendingPurchases();
}
public interface IBillingLifecycleAdapter {
@@ -91,21 +93,31 @@ public class SDKManager {
}
public static void ConsumePurchase(String token) {
Log.i(TAG, "ConsumePurchase: token=" + token);
// Log.i(TAG, "ConsumePurchase: token=" + token);
if (sdkAdapter instanceof IPaymentAdapter) {
((IPaymentAdapter) sdkAdapter).consume(token);
}
}
public static String GetPendingPurchases() {
public static void QueryPendingPurchases() {
Log.i(TAG, "QueryPendingPurchases");
if (sdkAdapter instanceof IPendingPurchaseAdapter) {
return ((IPendingPurchaseAdapter) sdkAdapter).getPendingPurchases();
((IPendingPurchaseAdapter) sdkAdapter).queryPendingPurchases();
return;
}
try {
JSONObject result = new JSONObject();
result.put("code", 0);
result.put("respObj", "[]");
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
"PendingPurchasesResult", result.toString());
} catch (JSONException e) {
Log.e(TAG, "QueryPendingPurchases fallback json error: " + e.getMessage());
}
return "[]";
}
public static void RefreshBillingService() {
Log.i(TAG, "RefreshBillingService");
// Log.i(TAG, "RefreshBillingService");
if (sdkAdapter instanceof IBillingLifecycleAdapter) {
((IBillingLifecycleAdapter) sdkAdapter).refreshBilling();
}
@@ -116,6 +128,24 @@ public class SDKManager {
// FlexionSDKAdapter.cancelPurchase();
}
public static boolean IsGooglePlayServicesAvailable() {
try {
Activity activity = UnityPlayer.currentActivity;
if (activity == null) {
Log.w(TAG, "IsGooglePlayServicesAvailable: activity is null");
return false;
}
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity);
boolean available = resultCode == ConnectionResult.SUCCESS;
Log.i(TAG, "IsGooglePlayServicesAvailable: available=" + available + " resultCode=" + resultCode);
return available;
} catch (Exception e) {
Log.w(TAG, "IsGooglePlayServicesAvailable exception: " + e.getMessage());
return false;
}
}
// -------------------------------------------------------------------------
// Init — with channel helper support
// -------------------------------------------------------------------------
@@ -124,9 +154,9 @@ public class SDKManager {
channel = ChannelEntry.CHANNEL;
sdkAdapter = ChannelEntry.createSDKAdapter();
Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
+ " fromCSharp=" + ch
+ " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getSimpleName() : "default"));
// Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
// + " fromCSharp=" + ch
// + " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getSimpleName() : "default"));
// Sync channel to C# ChannelConfig
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
@@ -515,13 +545,13 @@ public class SDKManager {
public static void SetGaUserInfo(String userId) {
Log.e(TAG, "SetGaUserInfo : " + userId);
SDKLog.i("SetGaUserInfo : " + userId);
// SDKLog.i("SetGaUserInfo : " + userId);
GetGameGa().setUserId(userId);
}
public static void SetGaCommonInfo(String SetGaCommonInfo) {
Log.e(TAG, "SetGaCommonInfo : " + SetGaCommonInfo);
SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo);
// SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo);
Gson gson = new Gson();
Map<String, Object> map = gson.fromJson(SetGaCommonInfo,
new TypeToken<Map<String, Object>>() {}.getType());

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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
{

View File

@@ -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
}
}