update:逻辑更新

This commit is contained in:
2026-05-21 00:37:19 +08:00
parent eecf54c6a4
commit ed6fe668ad
29 changed files with 677 additions and 747 deletions

View File

@@ -8,30 +8,33 @@ using System.Text;
namespace tysdk
{
public partial class TYSdkFacade
public partial class TYSdkFacade : MonoBehaviour
{
/*================================================
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
____ _
| _ \ __ _ _ _ _ __ ___ ___ _ __ | |_
| |_) / _` | | | | '_ ` _ \ / _ \ '_ \| __|
| __/ (_| | |_| | | | | | | __/ | | | |_
| __/ (_| | |_| | | | | | | __/ | | | |_
|_| \__,_|\__, |_| |_| |_|\___|_| |_|\__|
|___/
|___/
=================================================*/
private bool _payFirstNegativeHandled;
//public async Task<PaymentInfo> Pay(string prodId, string prodPrice, string prodName, int count, string pType, string price_amount_micros =null)
public async Task<PaymentInfo> Pay(SKUDetail prod, int count, float usdprice, JObject purchaseInfo)
{
if (!IsLoggedIn) return new PaymentInfo() { code = "-1", msg = "未登录" };
var orderId = System.Guid.NewGuid().ToString();
if (purchaseInfo == null)
if(purchaseInfo == null)
purchaseInfo = new JObject();
purchaseInfo["orderId"] = orderId;
string extraInfo = purchaseInfo.ToString(Newtonsoft.Json.Formatting.None);
//to base64
extraInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(extraInfo));
Debug.Log("[TYSdk] extraInfo: " + extraInfo);
var prodId = prod.ProdID;
@@ -59,7 +62,7 @@ namespace tysdk
var task = TYSDKCallbackManager.Instance.RegisterCallback<PaymentInfo>(TimeSpan.FromSeconds(90));
try
{
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo, pType);
UnityBridgeFunc.UnityKnowNew(prodId, prodPrice, prodName, count.ToString(), orderId, extraInfo,pType);
var result = await task;
result.count = count;
result.orderId = orderId;
@@ -103,6 +106,7 @@ namespace tysdk
#endif
}
//支付的回调
public void PayResult(string json)
{
Debug.Log("[TYSdkFacade] pay callback:" + json);
@@ -110,11 +114,25 @@ namespace tysdk
var result = new PaymentInfo();
result.code = jresult["code"].ToString();
result.msg = jresult["errStr"].ToString();
result.purchaseJson = jresult["purchaseJson"]?.ToString();
result.signature = jresult["signature"]?.ToString();
result.purchaseToken = jresult["purchaseToken"]?.ToString();
var purchaseJson = jresult["purchaseJson"]?.ToString();
var signature = jresult["signature"]?.ToString();
var purchaseToken = jresult["purchaseToken"]?.ToString();
result.purchaseJson = purchaseJson;
result.signature = signature;
result.purchaseToken = purchaseToken;
if (!string.IsNullOrEmpty(purchaseJson) || !string.IsNullOrEmpty(purchaseToken))
{
result.Receipt = new PaymentReceipt
{
Provider = PaymentReceiptProvider.Flexion,
PurchaseJson = purchaseJson,
Signature = signature,
PurchaseToken = purchaseToken
};
}
result.storeOrderId = jresult["orderId"]?.ToString();
result.userId = _accountInfo?.strUserId;
if (result.code == "-1")
if(result.code == "-1")
{
if (!_payFirstNegativeHandled)
{
@@ -128,60 +146,15 @@ namespace tysdk
}
return;
}
var processor = PaymentProcessorFactory.GetProcessor();
if (processor?.verifier != null && !string.IsNullOrEmpty(result.purchaseJson))
{
_VerifyPurchase(result, processor);
}
else
{
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
}
private async void _VerifyPurchase(PaymentInfo result, PaymentProcessor processor)
{
TYSDKCallbackManager.Instance.ResetCallbackTimeout<PaymentInfo>(TimeSpan.FromSeconds(60));
try
{
var verifyResult = await processor.verifier.VerifyAsync(result);
if (verifyResult.success)
{
result.verified = true;
if (!string.IsNullOrEmpty(verifyResult.orderId))
result.serverOrderId = verifyResult.orderId;
if (processor.consumer != null && !string.IsNullOrEmpty(result.purchaseToken))
{
var consumeResult = await processor.consumer.ConsumeAsync(result.purchaseToken);
if (!consumeResult.success)
{
Debug.LogWarning("[TYSdkFacade] Purchase consume failed: " + consumeResult.msg);
}
}
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
else
{
Debug.LogWarning("[TYSdkFacade] Payment verification failed: " + verifyResult.msg);
result.code = "-1";
result.msg = "verification_failed: " + verifyResult.msg;
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
}
catch (Exception e)
{
Debug.LogError("[TYSdkFacade] Verification exception: " + e.Message);
result.code = "-1";
result.msg = "verification_error: " + e.Message;
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
TYSDKCallbackManager.Instance.TryTriggerCallback(result);
}
// Get Pay list
public async Task<ProductListInfo> GetSKUList()
{
if (!IsLoggedIn) return new ProductListInfo() { code = -1, msg = "未登录" };
#if UNITY_EDITOR
#if UNITY_EDITOR
await Task.Yield();
var result = new ProductListInfo();
@@ -194,6 +167,25 @@ namespace tysdk
#endif
}
//通过商品ID列表获取商品详情Flexion 渠道使用)
public async Task<ProductListInfo> GetSKUListByIapIds(string productIds)
{
if (!IsLoggedIn) return new ProductListInfo() { code = -1, msg = "未登录" };
#if UNITY_EDITOR
await Task.Yield();
return new ProductListInfo();
#elif UNITY_ANDROID
var task = TYSDKCallbackManager.Instance.RegisterCallback<ProductListInfo>();
UnityBridgeFunc.GetSKUListByIapIds(productIds);
var result = await task;
return result;
#else
return new ProductListInfo() { code = -1, msg = "unsupported platform" };
#endif
}
//商品列表的回调
public void SKUListResult(string json)
{
Debug.Log("[TYSdkFacade] GetSKUList callback");
@@ -216,3 +208,7 @@ namespace tysdk
}
}
}