fix:1、更换sdk

This commit is contained in:
2026-07-14 09:49:24 +08:00
parent 4187297e82
commit 8435b6e676
667 changed files with 36728 additions and 23022 deletions
+210 -210
View File
@@ -10,7 +10,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using RedHotRoast;
using SDK_IAP;
// using SDK_IAP;
using SGModule.Net;
using UnityEngine;
using UnityEngine.Purchasing;
@@ -70,8 +70,8 @@ namespace RedHotRoast
_instance = this;
// 订阅发货事件(持续监听,全局处理发货逻辑)
IAPManager.OnDeliver += HandleDeliver;
IAPManager.OnInitialized += HandleInitialized;
// IAPManager.OnDeliver += HandleDeliver;
// IAPManager.OnInitialized += HandleInitialized;
}
private void Start()
@@ -94,9 +94,9 @@ namespace RedHotRoast
private void OnDestroy()
{
IAPManager.OnDeliver -= HandleDeliver;
IAPManager.OnInitialized -= HandleInitialized;
IAPManager.Dispose();
// IAPManager.OnDeliver -= HandleDeliver;
// IAPManager.OnInitialized -= HandleInitialized;
// IAPManager.Dispose();
}
// ──────────────────────────────────────────────────────────
@@ -105,30 +105,30 @@ namespace RedHotRoast
private void InitIAP()
{
var products = new List<ProductDefine>
{
// 消耗品
ProductDefine.Simple(PRODUCT_FIRST_GIFT, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_REMOVE_ADS, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_PASS_BONUS, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_SHOP_1, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_SHOP_2, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_SHOP_3, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_SHOP_4, ProductType.Consumable),
ProductDefine.Simple(PRODUCT_SHOP_5, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_THREE_DAY, ProductType.Consumable),
// 非消耗品
ProductDefine.Simple(PRODUCT_SPACE_BONUS, ProductType.NonConsumable),
// 订阅
ProductDefine.Simple(PRODUCT_VIP_WEEK, ProductType.Subscription),
ProductDefine.Simple(PRODUCT_VIP_MONTH, ProductType.Subscription),
ProductDefine.Simple(PRODUCT_VIP_YEAR, ProductType.Subscription),
};
Debug.Log("[IAP IOS] 开始初始化...");
IAPManager.Init(products, OnInitCallback);
// var products = new List<ProductDefine>
// {
// // 消耗品
// ProductDefine.Simple(PRODUCT_FIRST_GIFT, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_REMOVE_ADS, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_PASS_BONUS, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_SHOP_1, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_SHOP_2, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_SHOP_3, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_SHOP_4, ProductType.Consumable),
// ProductDefine.Simple(PRODUCT_SHOP_5, ProductType.Consumable),
// // ProductDefine.Simple(PRODUCT_THREE_DAY, ProductType.Consumable),
//
// // 非消耗品
// ProductDefine.Simple(PRODUCT_SPACE_BONUS, ProductType.NonConsumable),
//
// // 订阅
// ProductDefine.Simple(PRODUCT_VIP_WEEK, ProductType.Subscription),
// ProductDefine.Simple(PRODUCT_VIP_MONTH, ProductType.Subscription),
// ProductDefine.Simple(PRODUCT_VIP_YEAR, ProductType.Subscription),
// };
//
// Debug.Log("[IAP IOS] 开始初始化...");
// IAPManager.Init(products, OnInitCallback);
}
// Init 完成回调(与 OnInitialized 事件等价,二选一即可)
@@ -157,11 +157,11 @@ namespace RedHotRoast
public void ShowProductPrices()
{
var products = IAPManager.GetProducts();
foreach (var p in products)
{
Debug.Log($"[IAP IOS] 商品: {p.definition.id} | 价格: {p.metadata.localizedPriceString}");
}
// var products = IAPManager.GetProducts();
// foreach (var p in products)
// {
// Debug.Log($"[IAP IOS] 商品: {p.definition.id} | 价格: {p.metadata.localizedPriceString}");
// }
}
// ──────────────────────────────────────────────────────────
@@ -173,19 +173,19 @@ namespace RedHotRoast
/// <param name="onSuccess">购买成功后的回调</param>
public void BuyProduct(string productId, string productName, System.Action onSuccess = null)
{
IAPManager.Buy(productId, result =>
{
if (result.success)
{
Debug.Log($"[IAP IOS] 购买成功: {productName} ({result.productId}) | tid={result.transactionId}");
onSuccess?.Invoke();
}
else
{
Debug.LogWarning($"[IAP IOS] 购买失败: {productName} ({result.productId}) - {result.error}");
PurchasingManager.SendEventClickByName(productId, "open");
}
});
// IAPManager.Buy(productId, result =>
// {
// if (result.success)
// {
// Debug.Log($"[IAP IOS] 购买成功: {productName} ({result.productId}) | tid={result.transactionId}");
// onSuccess?.Invoke();
// }
// else
// {
// Debug.LogWarning($"[IAP IOS] 购买失败: {productName} ({result.productId}) - {result.error}");
// PurchasingManager.SendEventClickByName(productId, "open");
// }
// });
}
/// <summary>通用订阅方法 - 适用于订阅类型商品</summary>
@@ -194,20 +194,20 @@ namespace RedHotRoast
/// <param name="onSuccess">订阅成功后的回调</param>
public void SubscribeProduct(string productId, string subscriptionName, System.Action onSuccess = null)
{
IAPManager.Buy(productId, result =>
{
if (result.success)
{
Debug.Log($"[IAP IOS] 订阅成功: {subscriptionName} ({result.productId}) | tid={result.transactionId}");
// ShowSubscriptionInfo();
onSuccess?.Invoke();
}
else
{
Debug.LogWarning($"[IAP IOS] 订阅失败: {subscriptionName} ({result.productId}) - {result.error}");
PurchasingManager.SendEventClickByName(productId, "open");
}
});
// IAPManager.Buy(productId, result =>
// {
// if (result.success)
// {
// Debug.Log($"[IAP IOS] 订阅成功: {subscriptionName} ({result.productId}) | tid={result.transactionId}");
// // ShowSubscriptionInfo();
// onSuccess?.Invoke();
// }
// else
// {
// Debug.LogWarning($"[IAP IOS] 订阅失败: {subscriptionName} ({result.productId}) - {result.error}");
// PurchasingManager.SendEventClickByName(productId, "open");
// }
// });
}
// ──────────────────────────────────────────────────────────
@@ -218,23 +218,23 @@ namespace RedHotRoast
// UI 控制:仅在需要时显示此按钮
// if (!IAPManager.NeedShowRestoreButton()) return;
IAPManager.Restore(result =>
{
if (result.success)
{
Debug.Log("[IAP IOS] 恢复购买流程完成(实际恢复内容通过 OnDeliver 发放)");
Debug.Log("[IAP IOS] restore success: " + result.success);
GameHelper.ShowTips("Restore_pur", true);
// SaveData.GetSaveObject().have_slot = result.success;
// DataMgr.VipLevel.Value = 3;
// DataMgr.VipExpirationTime.Value = ServerClock.GetCurrentServerTime() + 7 * 24 * 60 * 60;
}
else
{
Debug.LogWarning($"[IAP IOS] 恢复购买失败: {result.error}");
GameHelper.ShowTips("recoverable_tips", true);
}
});
// IAPManager.Restore(result =>
// {
// if (result.success)
// {
// Debug.Log("[IAP IOS] 恢复购买流程完成(实际恢复内容通过 OnDeliver 发放)");
// Debug.Log("[IAP IOS] restore success: " + result.success);
// GameHelper.ShowTips("Restore_pur", true);
// // SaveData.GetSaveObject().have_slot = result.success;
// // DataMgr.VipLevel.Value = 3;
// // DataMgr.VipExpirationTime.Value = ServerClock.GetCurrentServerTime() + 7 * 24 * 60 * 60;
// }
// else
// {
// Debug.LogWarning($"[IAP IOS] 恢复购买失败: {result.error}");
// GameHelper.ShowTips("recoverable_tips", true);
// }
// });
}
// ──────────────────────────────────────────────────────────
@@ -246,11 +246,11 @@ namespace RedHotRoast
/// <param name="onResult">检查结果回调</param>
public void CheckEntitlement(string productId, string productName, System.Action<EntitlementStatus> onResult = null)
{
IAPManager.CheckEntitlement(productId, status =>
{
Debug.Log($"[IAP IOS] {productId} 权益状态: {status}");
onResult?.Invoke(status);
});
// IAPManager.CheckEntitlement(productId, status =>
// {
// Debug.Log($"[IAP IOS] {productId} 权益状态: {status}");
// onResult?.Invoke(status);
// });
}
/// <summary>检查加一格礼包权益</summary>
@@ -303,37 +303,37 @@ namespace RedHotRoast
/// <param name="productId">商品ID</param>
public void ShowSubscriptionInfo(string productId)
{
var info = IAPManager.GetSubscriptionInfo(productId);
Debug.Log($"[IAP IOS] VIP 订阅状态 ({productId}):");
Debug.Log($" isSubscribed = {info.isSubscribed}");
Debug.Log($" isExpired = {info.isExpired}");
Debug.Log($" expireDate = {info.expireDate}");
Debug.Log($" isAutoRenewing= {info.isAutoRenewing}");
// var info = IAPManager.GetSubscriptionInfo(productId);
// Debug.Log($"[IAP IOS] VIP 订阅状态 ({productId}):");
// Debug.Log($" isSubscribed = {info.isSubscribed}");
// Debug.Log($" isExpired = {info.isExpired}");
// Debug.Log($" expireDate = {info.expireDate}");
// Debug.Log($" isAutoRenewing= {info.isAutoRenewing}");
if (info.isSubscribed && !info.isExpired)
{
int vipLevel = GetVipLevelByProductId(productId);
if (vipLevel > 0)
{
DataMgr.VipLevel.Value = vipLevel;
Debug.Log($"[IAP IOS] 设置 VIP 等级: {vipLevel}");
}
if (info.expireDate.Year > 1970 && info.expireDate.Year < 10000)
{
var expireTimestamp = ((DateTimeOffset)info.expireDate).ToUnixTimeSeconds();
Debug.Log($"Expire timestamp: {expireTimestamp}");
DataMgr.VipExpirationTime.Value = Math.Max(DataMgr.VipExpirationTime.Value, expireTimestamp);
}
else
{
Debug.LogWarning($"[IAP IOS] 无效的到期时间: {info.expireDate}");
}
}
else
{
Debug.Log($"[IAP IOS] 用户未订阅或订阅已过期");
}
// if (info.isSubscribed && !info.isExpired)
// {
// int vipLevel = GetVipLevelByProductId(productId);
// if (vipLevel > 0)
// {
// DataMgr.VipLevel.Value = vipLevel;
// Debug.Log($"[IAP IOS] 设置 VIP 等级: {vipLevel}");
// }
//
// if (info.expireDate.Year > 1970 && info.expireDate.Year < 10000)
// {
// var expireTimestamp = ((DateTimeOffset)info.expireDate).ToUnixTimeSeconds();
// Debug.Log($"Expire timestamp: {expireTimestamp}");
// DataMgr.VipExpirationTime.Value = Math.Max(DataMgr.VipExpirationTime.Value, expireTimestamp);
// }
// else
// {
// Debug.LogWarning($"[IAP IOS] 无效的到期时间: {info.expireDate}");
// }
// }
// else
// {
// Debug.Log($"[IAP IOS] 用户未订阅或订阅已过期");
// }
}
/// <summary>根据商品ID获取VIP等级</summary>
/// <param name="productId">商品ID</param>
@@ -389,22 +389,22 @@ namespace RedHotRoast
Debug.Log($"[IAP IOS] 开始获取订阅信息: {productId}");
// 先尝试立即获取一次
var immediateInfo = IAPManager.GetSubscriptionInfo(productId);
// 检查是否是无效数据
bool isInvalid = immediateInfo.expireDate == default(DateTime) ||
(immediateInfo.expireDate.Year == 1 && !immediateInfo.isSubscribed);
if (!isInvalid && immediateInfo.isSubscribed)
{
// 立即获取到了有效数据,直接处理
bool success = ProcessSubscriptionInfo(immediateInfo, productId);
if (success)
{
DispatchPaySuccess(productId);
}
yield break;
}
// var immediateInfo = IAPManager.GetSubscriptionInfo(productId);
//
// // 检查是否是无效数据
// bool isInvalid = immediateInfo.expireDate == default(DateTime) ||
// (immediateInfo.expireDate.Year == 1 && !immediateInfo.isSubscribed);
//
// if (!isInvalid && immediateInfo.isSubscribed)
// {
// // 立即获取到了有效数据,直接处理
// bool success = ProcessSubscriptionInfo(immediateInfo, productId);
// if (success)
// {
// DispatchPaySuccess(productId);
// }
// yield break;
// }
// 无效数据,开始重试
Debug.Log($"[IAP IOS] 订阅信息未就绪,开始重试...");
@@ -415,20 +415,20 @@ namespace RedHotRoast
{
yield return new WaitForSeconds(waitTime); // 每次等待0.5秒
var info = IAPManager.GetSubscriptionInfo(productId);
if (info.isSubscribed && !info.isExpired && info.expireDate.Year > 1970)
{
Debug.Log($"[IAP IOS] 订阅信息获取成功 (重试 {i + 1} 次)");
bool success = ProcessSubscriptionInfo(info, productId);
if (success)
{
DispatchPaySuccess(productId);
}
yield break;
}
Debug.Log($"[IAP IOS] 第 {i + 1} 次重试: isSubscribed={info.isSubscribed}, isExpired={info.isExpired}, expireDate={info.expireDate}");
// var info = IAPManager.GetSubscriptionInfo(productId);
//
// if (info.isSubscribed && !info.isExpired && info.expireDate.Year > 1970)
// {
// Debug.Log($"[IAP IOS] 订阅信息获取成功 (重试 {i + 1} 次)");
// bool success = ProcessSubscriptionInfo(info, productId);
// if (success)
// {
// DispatchPaySuccess(productId);
// }
// yield break;
// }
//
// Debug.Log($"[IAP IOS] 第 {i + 1} 次重试: isSubscribed={info.isSubscribed}, isExpired={info.isExpired}, expireDate={info.expireDate}");
}
// 所有重试都失败了,使用降级方案
@@ -451,72 +451,72 @@ namespace RedHotRoast
/// 处理订阅信息,设置VIP等级和过期时间
/// </summary>
/// <returns>是否设置成功</returns>
private bool ProcessSubscriptionInfo(SubscriptionInfoLite info, string productId)
{
try
{
Debug.Log($"[IAP IOS] VIP 订阅状态 ({productId}):");
Debug.Log($" isSubscribed = {info.isSubscribed}");
Debug.Log($" isExpired = {info.isExpired}");
Debug.Log($" expireDate = {info.expireDate}");
Debug.Log($" isAutoRenewing= {info.isAutoRenewing}");
// 获取VIP等级
int vipLevel = GetVipLevelByProductId(productId);
if (vipLevel <= 0)
{
Debug.LogError($"[IAP IOS] 无法获取VIP等级,商品ID: {productId}");
return false;
}
// 获取过期时间戳
long expireTimestamp = 0;
if (info.expireDate.Year > 1970 && info.expireDate.Year < 10000)
{
expireTimestamp = ((DateTimeOffset)info.expireDate).ToUnixTimeSeconds();
}
else
{
Debug.LogWarning($"[IAP IOS] 无效的到期时间: {info.expireDate},使用预估时间");
expireTimestamp = GetEstimatedExpireTimestamp(productId);
}
if (expireTimestamp <= 0)
{
Debug.LogError($"[IAP IOS] 无法获取有效的过期时间戳");
return false;
}
// 保存数据(使用前后对比,确保设置成功)
int oldVipLevel = DataMgr.VipLevel.Value;
long oldExpireTime = DataMgr.VipExpirationTime.Value;
DataMgr.VipLevel.Value = Math.Max(DataMgr.VipLevel.Value, vipLevel);
DataMgr.VipExpirationTime.Value = Math.Max(DataMgr.VipExpirationTime.Value, expireTimestamp);
// 验证设置是否成功
bool vipLevelSuccess = DataMgr.VipLevel.Value >= vipLevel;
bool expireTimeSuccess = DataMgr.VipExpirationTime.Value >= expireTimestamp;
if (vipLevelSuccess && expireTimeSuccess)
{
Debug.Log($"[IAP IOS] VIP设置成功 - 等级: {vipLevel} (原:{oldVipLevel}), 过期时间: {expireTimestamp} (原:{oldExpireTime})");
// 可选:触发VIP状态更新事件
return true;
}
else
{
Debug.LogError($"[IAP IOS] VIP设置失败 - 等级设置: {vipLevelSuccess}, 过期时间设置: {expireTimeSuccess}");
return false;
}
}
catch (Exception e)
{
Debug.LogError($"[IAP IOS] 处理订阅信息时发生异常: {e.Message}\n{e.StackTrace}");
return false;
}
}
// private bool ProcessSubscriptionInfo(SubscriptionInfoLite info, string productId)
// {
// try
// {
// Debug.Log($"[IAP IOS] VIP 订阅状态 ({productId}):");
// Debug.Log($" isSubscribed = {info.isSubscribed}");
// Debug.Log($" isExpired = {info.isExpired}");
// Debug.Log($" expireDate = {info.expireDate}");
// Debug.Log($" isAutoRenewing= {info.isAutoRenewing}");
//
// // 获取VIP等级
// int vipLevel = GetVipLevelByProductId(productId);
// if (vipLevel <= 0)
// {
// Debug.LogError($"[IAP IOS] 无法获取VIP等级,商品ID: {productId}");
// return false;
// }
//
// // 获取过期时间戳
// long expireTimestamp = 0;
// if (info.expireDate.Year > 1970 && info.expireDate.Year < 10000)
// {
// expireTimestamp = ((DateTimeOffset)info.expireDate).ToUnixTimeSeconds();
// }
// else
// {
// Debug.LogWarning($"[IAP IOS] 无效的到期时间: {info.expireDate},使用预估时间");
// expireTimestamp = GetEstimatedExpireTimestamp(productId);
// }
//
// if (expireTimestamp <= 0)
// {
// Debug.LogError($"[IAP IOS] 无法获取有效的过期时间戳");
// return false;
// }
//
// // 保存数据(使用前后对比,确保设置成功)
// int oldVipLevel = DataMgr.VipLevel.Value;
// long oldExpireTime = DataMgr.VipExpirationTime.Value;
//
// DataMgr.VipLevel.Value = Math.Max(DataMgr.VipLevel.Value, vipLevel);
// DataMgr.VipExpirationTime.Value = Math.Max(DataMgr.VipExpirationTime.Value, expireTimestamp);
//
// // 验证设置是否成功
// bool vipLevelSuccess = DataMgr.VipLevel.Value >= vipLevel;
// bool expireTimeSuccess = DataMgr.VipExpirationTime.Value >= expireTimestamp;
//
// if (vipLevelSuccess && expireTimeSuccess)
// {
// Debug.Log($"[IAP IOS] VIP设置成功 - 等级: {vipLevel} (原:{oldVipLevel}), 过期时间: {expireTimestamp} (原:{oldExpireTime})");
//
// // 可选:触发VIP状态更新事件
// return true;
// }
// else
// {
// Debug.LogError($"[IAP IOS] VIP设置失败 - 等级设置: {vipLevelSuccess}, 过期时间设置: {expireTimeSuccess}");
// return false;
// }
// }
// catch (Exception e)
// {
// Debug.LogError($"[IAP IOS] 处理订阅信息时发生异常: {e.Message}\n{e.StackTrace}");
// return false;
// }
// }
/// <summary>
/// 降级方案:当无法从商店获取订阅信息时,根据商品类型估算VIP信息