diff --git a/Assets/Resources/BillingMode.json b/Assets/Resources/BillingMode.json new file mode 100644 index 0000000..6f4bfb7 --- /dev/null +++ b/Assets/Resources/BillingMode.json @@ -0,0 +1 @@ +{"androidStore":"GooglePlay"} \ No newline at end of file diff --git a/Assets/Resources/BillingMode.json.meta b/Assets/Resources/BillingMode.json.meta new file mode 100644 index 0000000..3d07f03 --- /dev/null +++ b/Assets/Resources/BillingMode.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0acbd98545e2042c7853ae1fe66f1a6b +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/SDKManager/Purchase/IAPEvent.cs b/Assets/Script/SDKManager/Purchase/IAPEvent.cs index 56e41cc..705fd62 100644 --- a/Assets/Script/SDKManager/Purchase/IAPEvent.cs +++ b/Assets/Script/SDKManager/Purchase/IAPEvent.cs @@ -226,6 +226,34 @@ namespace WZ ShuShuEvent.Instance.Track(eventName, para); } + public static void LogChecingOrderBySdk(string _productName, string _productId, string _orderId, string gameExtra01, string gameExtra02) + { + var eventName = "IAP_Checking_Order"; + string price = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.localizedPrice.ToString(); + string currency = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).metadata.isoCurrencyCode; + string productType = IAPPurchaseManager.Instance.GetProductInfoByID(_productId).definition.type.ToString(); + float fPrice; + if (!float.TryParse(price, out fPrice)) + { + fPrice = 0.0f; + } + var para = new Dictionary + { + { "IAP", _productName }, + { "product_id", _productId }, + { "currency", currency }, + { "price", fPrice }, + { "order_id", _orderId }, + { "is_first", PlayerPrefsUtils.GetPlayerPrefsInt(First_Purchase, 0) == 0 }, + { "payment_type", "GooglePlay" }, + { "product_type", productType }, + { "game_extra01", gameExtra01 }, + { "game_extra02", gameExtra02 } + }; + FireBaseAnalyticsManager.Instance.LogEvent(eventName, para); + ShuShuEvent.Instance.Track(eventName, para); + } + public static string First_Purchase = "First_purchase"; public static string PAY_TIME = "PAY_TIME"; public static string PURCHASE_PRICE = "PURCHASE_PRICE"; diff --git a/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs b/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs new file mode 100644 index 0000000..28cdd77 --- /dev/null +++ b/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs @@ -0,0 +1,86 @@ +#if UNITY_PURCHASE +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WZ +{ + public class IAPGoogleJsonInfo + { + public struct GoogleToken + { + public string packageName; + public string productId; + public string token; + public string projectId; + } + + public class ProductData + { + public string productId; + public int checkStatus; + public string timestamp; + public string sign; + } + + public class GooglePurchaseData + { + // INAPP_PURCHASE_DATA + public string inAppPurchaseData; + + // INAPP_DATA_SIGNATURE + public string inAppDataSignature; + + public GooglePurchaseJson json; + + [System.Serializable] + private struct GooglePurchaseReceipt + { + public string Payload; + } + + [System.Serializable] + private struct GooglePurchasePayload + { + public string json; + public string signature; + } + + [System.Serializable] + public struct GooglePurchaseJson + { + public string packageName; + public string productId; + public long purchaseTime; + public int purchaseState; + public string purchaseToken; + public string orderId; + + public bool autoRenewing; + } + + public GooglePurchaseData(string receipt) + { + try + { + var purchaseReceipt = JsonUtility.FromJson(receipt); + var purchasePayload = JsonUtility.FromJson(purchaseReceipt.Payload); + var inAppJsonData = JsonUtility.FromJson(purchasePayload.json); + + inAppPurchaseData = purchasePayload.json; + inAppDataSignature = purchasePayload.signature; + json = inAppJsonData; + } + catch + { + Debug.Log("Could not parse receipt: " + receipt); + inAppPurchaseData = ""; + inAppDataSignature = ""; + } + } + } + } + +} + +#endif diff --git a/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs.meta b/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs.meta new file mode 100644 index 0000000..97c8b2f --- /dev/null +++ b/Assets/Script/SDKManager/Purchase/IAPGoogleJsonInfo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ee6202ee1836a459ab9c0e3311957a1c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/SDKManager/Purchase/IAPOrderManager.cs b/Assets/Script/SDKManager/Purchase/IAPOrderManager.cs index e932413..38e55d6 100644 --- a/Assets/Script/SDKManager/Purchase/IAPOrderManager.cs +++ b/Assets/Script/SDKManager/Purchase/IAPOrderManager.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; +using UnityEditor; using UnityEngine; namespace WZ @@ -12,7 +13,6 @@ namespace WZ { private static string _purchaseOrderMap = "PurchaseOrderMap"; private List NotRetryCode = new List { 0, 430, 900, 901, 902, 903, 904, 905 }; - private Dictionary mRepeatCountDic; #region 订单验证 public void VerifyPurchase(IAPDataConfig args) @@ -21,13 +21,13 @@ namespace WZ if (args.state == IAPDataStateType.def) { // 记录订单处理次数,处理5次还是失败就不处理了 - if (mRepeatCountDic.ContainsKey(args.info["order_id"])) + if (IAPPurchaseManager.Instance._repeatCountDic.ContainsKey(args.info["order_id"])) { - mRepeatCountDic[args.info["order_id"]] = mRepeatCountDic[args.info["order_id"]] + 1; + IAPPurchaseManager.Instance._repeatCountDic[args.info["order_id"]] = IAPPurchaseManager.Instance._repeatCountDic[args.info["order_id"]] + 1; } else { - mRepeatCountDic.Add(args.info["order_id"], 1); + IAPPurchaseManager.Instance._repeatCountDic.Add(args.info["order_id"], 1); } // 开始处理,设置正在处理的状态 @@ -50,14 +50,14 @@ namespace WZ if ((code == 0 || code == 430) && data.illegal_order == 0) { // 将订阅商品信息存储到本地 - if (!IAPPurchaseManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription")) + if (!IAPSubscribeManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription")) { - IAPPurchaseManager.Instance._productArgs.Add(args.info["product_id"].ToString(), requestArgs); + IAPSubscribeManager.Instance._productArgs.Add(args.info["product_id"].ToString(), requestArgs); } - else if (IAPPurchaseManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription")) + else if (IAPSubscribeManager.Instance._productArgs.ContainsKey(args.info["product_id"].ToString()) && args.info["product_type"].ToString().Equals("Subscription")) { - IAPPurchaseManager.Instance._productArgs[args.info["product_id"].ToString()] = requestArgs; + IAPSubscribeManager.Instance._productArgs[args.info["product_id"].ToString()] = requestArgs; } RushSDKManager.Instance.OnPurchaseComplete?.Invoke(new PurchaseInfo( productName: args.info["product_name"], @@ -176,9 +176,31 @@ namespace WZ #endregion #region 重置订单状态 - private void RefreshOrderStatue(IAPDataConfig _productInfo, IAPDataStateType state) + public void RefreshOrderStatue() + { + if (ES3.KeyExists(_purchaseOrderMap)) + { + try + { + List list = ES3.Load("FailOrderCacheData") as List; + if (list.Count > 0) + { + foreach (var data in list) + { + data.state = IAPDataStateType.def; + } + ES3.Save("FailOrderCacheData", list); + } + } + catch (System.Exception) + { + ES3.DeleteKey("FailOrderCacheData"); + } + } + } + public void RefreshOrderStatue(IAPDataConfig _productInfo, IAPDataStateType state) { - if (ES3.KeyExists("FailOrderCacheData")) + if (ES3.KeyExists(_purchaseOrderMap)) { List list = ES3.Load(_purchaseOrderMap) as List; var value = _productInfo.info["order_id"]; @@ -260,7 +282,7 @@ namespace WZ { list.Add(_productInfo); ES3.Save(_purchaseOrderMap, list); - ReadFailOrderId(); + ProgressCacheOrder(); LoggerUtils.Debug("[iap] IAP SaveVerifyFailOrderId 已经有表了,添加失败订单,订单ID:" + _productInfo.info["order_id"] + " 商品类型:" + _productInfo.info["product_type"]); } else @@ -268,7 +290,7 @@ namespace WZ if (!inDealFailOrder) { inDealFailOrder = true; - InvokeRepeating(nameof(ReadFailOrderId), 0, 30); + InvokeRepeating(nameof(ProgressCacheOrder), 0, 30); } } } @@ -279,30 +301,30 @@ namespace WZ _productInfo }; ES3.Save(_purchaseOrderMap, tem); - ReadFailOrderId(); + ProgressCacheOrder(); LoggerUtils.Debug("[iap] IAP SaveVerifyFailOrderId 第一次存储表 添加失败订单 订单个数:" + tem.Count); } } #endregion #region 再次验证订单 - public void ReadFailOrderId() + public void ProgressCacheOrder() { if (ES3.KeyExists(_purchaseOrderMap)) { List list = ES3.Load(_purchaseOrderMap) as List; - LoggerUtils.Debug("[iap] IAP ReadFailOrderId 读取失败订单列表,count:" + list.Count + " mRepeatCountDic" + mRepeatCountDic.Count); + LoggerUtils.Debug("[iap] IAP ProgressCacheOrder 读取失败订单列表,count:" + list.Count + " IAPPurchaseManager.Instance._repeatCountDic" + IAPPurchaseManager.Instance._repeatCountDic.Count); if (list.Count > 0) { // 当前进程每条订单校验5次,如果失败则不再处理 // 重复校验时判断次数是否大于5,大于5则不再处理 IAPDataConfig tempData = null; - if (mRepeatCountDic.Count > 0) + if (IAPPurchaseManager.Instance._repeatCountDic.Count > 0) { foreach (var data in list) { - LoggerUtils.Debug("[iap] iap start verify fail order with repeat dic" + data.info["order_id"] + " count:" + mRepeatCountDic[data.info["order_id"]]); - if (mRepeatCountDic.ContainsKey(data.info["order_id"]) && mRepeatCountDic[data.info["order_id"]] <= 5) + LoggerUtils.Debug("[iap] iap start verify fail order with repeat dic" + data.info["order_id"] + " count:" + IAPPurchaseManager.Instance._repeatCountDic[data.info["order_id"]]); + if (IAPPurchaseManager.Instance._repeatCountDic.ContainsKey(data.info["order_id"]) && IAPPurchaseManager.Instance._repeatCountDic[data.info["order_id"]] <= 5) { tempData = data; break; @@ -312,7 +334,7 @@ namespace WZ // 如果还有次数不超过5次的订单,则继续校验,否则就不再处理 if (tempData != null) { - LoggerUtils.Debug("[iap] iap start verify fail order with repeat temp dic" + tempData.info["order_id"] + " count:" + mRepeatCountDic[tempData.info["order_id"]]); + LoggerUtils.Debug("[iap] iap start verify fail order with repeat temp dic" + tempData.info["order_id"] + " count:" + IAPPurchaseManager.Instance._repeatCountDic[tempData.info["order_id"]]); VerifyPurchase(tempData); IAPEvent.LogStarVerifyOrderBySdk(new PurchaseInfo( productName: tempData.info["product_name"], @@ -330,13 +352,13 @@ namespace WZ else { LoggerUtils.Debug("[iap] iap cancel verify fail order"); - CancelInvoke(nameof(ReadFailOrderId)); + CancelInvoke(nameof(ProgressCacheOrder)); inDealFailOrder = false; } } else { - CancelInvoke(nameof(ReadFailOrderId)); + CancelInvoke(nameof(ProgressCacheOrder)); inDealFailOrder = false; } } @@ -374,12 +396,12 @@ namespace WZ LoggerUtils.Debug("[iap] IAP 订单还剩余:" + list.Count + " 条未校验"); if (list.Count > 0) { - ReadFailOrderId(); + ProgressCacheOrder(); } else { inDealFailOrder = false; - CancelInvoke(nameof(ReadFailOrderId)); + CancelInvoke(nameof(ProgressCacheOrder)); } } } diff --git a/Assets/Script/SDKManager/Purchase/IAPPurchaseManager.cs b/Assets/Script/SDKManager/Purchase/IAPPurchaseManager.cs index 45ba708..bec8784 100644 --- a/Assets/Script/SDKManager/Purchase/IAPPurchaseManager.cs +++ b/Assets/Script/SDKManager/Purchase/IAPPurchaseManager.cs @@ -18,7 +18,7 @@ namespace WZ #region API public void BuyProductByID(string productId, string productName, string gameExtraParam) { -#if !UNITY_EDITOR +#if UNITY_EDITOR RushSDKManager.Instance.OnPurchaseComplete(new PurchaseInfo( productName: productName, productID: productId, @@ -71,7 +71,7 @@ namespace WZ _inPurchaseProgress = true; LoggerUtils.Debug( string.Format("[iap] Purchasing product asychronously: '{0}'", product.definition.id)); - + if (_googlePlayConfiguration != null) { @@ -100,7 +100,7 @@ namespace WZ productType: product.definition.type.ToString())); LoggerUtils.Debug("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase"); - } + } } else { @@ -134,7 +134,24 @@ namespace WZ } #endif } - + + public string GetProductPriceByID(string pID) + { + if (_storeController == null && _storeExtensionProvider == null) + return ""; + + Product[] tProducts = _storeController.products.all; + for (int i = 0; i < tProducts.Length; i++) + { + Product tItem = tProducts[i]; + if (tItem.definition.id.Equals(pID)) + { + return tItem.metadata.GetGoogleProductMetadata().localizedPriceString; + } + } + return ""; + } + public Product GetProductInfoByID(string pID) { if (_storeController == null && _storeExtensionProvider == null) @@ -150,15 +167,23 @@ namespace WZ return null; } - public void AddProducts(Dictionary products, Action onProductsResult = null) + public void AddProductsDynamic(Dictionary products, Action onProductsResult = null) { _initProductDic = products; - FetchAdditionalProducts(products, onProductsResult); } - - + public void DoConfirmPendingPurchaseByID(string productId) + { + Product product = _storeController.products.WithID(productId); + if (null == product) return; + if (string.IsNullOrEmpty(product.transactionID)) return; + if (product != null && product.availableToPurchase) + { + _storeController.ConfirmPendingPurchase(product); + _inPurchaseProgress = false; + } + } #endregion @@ -250,8 +275,7 @@ namespace WZ #endregion #region 动态添加商品 - private void FetchAdditionalProducts(Dictionary ProductDic, - Action onProductsResult = null) + private void FetchAdditionalProducts(Dictionary ProductDic, Action onProductsResult = null) { if (!IsInitialized()) { @@ -376,6 +400,15 @@ namespace WZ _builder ??= ConfigurationBuilder.Instance(_module); int productsNum = 0; + foreach (string tID in StaticProductDic.Keys) + { + productsNum++; + if (!string.IsNullOrEmpty(tID)) + { + LoggerUtils.Debug($"[iap] Add IAPProducts IAPProducts: {tID}"); + _builder.AddProduct(tID, StaticProductDic[tID]); + } + } if (_initProductDic != null && _initProductDic.Count > 0) { @@ -429,7 +462,6 @@ namespace WZ _storeController = controller; _storeExtensionProvider = extensions; - RushSDKManager.Instance.OnGetProductsInfo?.Invoke(_storeController.products.all); foreach (var product in _storeController.products.all) { LoggerUtils.Debug("[iap] " + product.metadata.localizedTitle @@ -440,11 +472,11 @@ namespace WZ + "|" + product.definition.type); } - // CheckSubscribeReceipt(); RushSDKManager.Instance.OnGetProductsInfo?.Invoke(_storeController.products.all); RushSDKManager.Instance.OnPurchaseInitComplete?.Invoke(true, ""); IAPEvent.LogPurchaseInit(true); - + IAPSubscribeManager.Instance.CheckSubscribeReceipt(); + IAPOrderManager.Instance.RefreshOrderStatue(); } #endregion @@ -477,6 +509,8 @@ namespace WZ #region 购买失败 public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription) { + _inPurchaseProgress = false; + IAPOrderManager.Instance.ProgressCacheOrder(); LoggerUtils.Debug("[iap] OnPurchaseFailed productId : " + failureDescription.productId + " , transactionID : " + product.transactionID + " , localizedPrice : " + product.metadata.localizedPriceString @@ -513,11 +547,13 @@ namespace WZ resultType: (IAPResultType)failureDescription.reason, productType: product.definition.type.ToString() )); + } public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) { - // m_PurchaseInProgress = false; + _inPurchaseProgress = false; + IAPOrderManager.Instance.ProgressCacheOrder(); LoggerUtils.Debug("[iap] OnPurchaseFailed productId -> : " + product.definition.id + " , transactionID : " + product.transactionID + " , localizedPrice : " + product.metadata.localizedPriceString @@ -555,26 +591,34 @@ namespace WZ productType: product.definition.type.ToString() )); - // ReadFailOrderId(); } #endregion + #region 添加静态商品 + public static Dictionary StaticProductDic = new Dictionary() + { + + }; + #endregion + #region Properties private StandardPurchasingModule _module; private ConfigurationBuilder _builder; - private static IStoreController _storeController; + public IStoreController _storeController; private static IExtensionProvider _storeExtensionProvider; public string _gameExtraParam = ""; private static string _productName = ""; private bool _inPurchaseProgress = false; - public Dictionary> _productArgs = new Dictionary>(); private bool _serviceInit = false; private Dictionary _addProductsDic; private Dictionary _initProductDic; - private Dictionary _repeatCountDic; + public Dictionary _repeatCountDic; private IGooglePlayConfiguration _googlePlayConfiguration; private bool _isFetchingAdditionalProducts = false; + + #endregion + } } diff --git a/Assets/Script/SDKManager/Purchase/IAPSubscribeInfo.cs b/Assets/Script/SDKManager/Purchase/IAPSubscribeInfo.cs index 7c070c4..6b51ad8 100644 --- a/Assets/Script/SDKManager/Purchase/IAPSubscribeInfo.cs +++ b/Assets/Script/SDKManager/Purchase/IAPSubscribeInfo.cs @@ -5,7 +5,6 @@ using UnityEngine; namespace WZ { - public struct SubscribeInfo { diff --git a/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs b/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs new file mode 100644 index 0000000..ea43fde --- /dev/null +++ b/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs @@ -0,0 +1,106 @@ +#if UNITY_PURCHASE +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Purchasing; + +namespace WZ +{ + public class IAPSubscribeManager : D_MonoSingleton + { + public Dictionary> _productArgs = new Dictionary>(); + + public void CheckSubscribeDataByProductId(string productId) + { + if (_productArgs.ContainsKey(productId)) + { + CheckOrderFromServer(_productArgs[productId],productId); + } + else + { + RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", "")); + } + } + + private void CheckOrderFromServer(Dictionary args,string productId) + { + if (args.Count > 0) + { + ServerMgr.Instance.CheckOrder(args, (code, msg, data) => + { + LoggerUtils.Debug("[iap] ===>CheckOrderFromServer code:"+code+ " illegal_order:"+data.illegal_order + " illegal_msg:" + data.illegal_msg+ " environment:"+data.environment+ + " purchase_time"+data.purchase_time+ " is_subscribed"+ data.is_subscribed+ " is_expired"+data.is_expired+ " is_cancelled:"+ data.is_cancelled+ " is_free_trial:"+ + data.is_free_trial+ " is_auto_renewing:"+data.is_auto_renewing+ " remaining_time:"+data.remaining_time+ " expire_time:"+data.expiry_time+ " latest_order_id:"+data.latest_order_id+ " productId:"+ args["product_id"].ToString()); + + SubscribeInfo resultData = new SubscribeInfo( + data.illegal_order, + data.illegal_msg, + data.environment, + data.purchase_time, + data.is_subscribed, + data.is_expired, + data.is_cancelled, + data.is_free_trial, + data.is_auto_renewing, + data.remaining_time, + data.expiry_time, + data.latest_order_id, + args["product_id"].ToString() + ); + + RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(args["product_id"].ToString(), resultData); + }); + } + else + { + RushSDKManager.Instance.OnSubscriptionQueriedByProductId?.Invoke(productId,new SubscribeInfo(-1, "", "", "", -1, -1, -1, -1, -1, "", "", "", "")); + } + } + + public void CheckSubscribeReceipt() + { + try + { + foreach (var product in IAPPurchaseManager.Instance._storeController.products.all) + { + if (product.availableToPurchase) + { + if (product.receipt != null) + { + if (product.definition.type == ProductType.Subscription) + { + try + { + IAPGoogleJsonInfo.GooglePurchaseData data = new IAPGoogleJsonInfo.GooglePurchaseData(product.receipt); + var args = new Dictionary + { + { "product_type", "Subscription" }, + { "product_id", data.json.productId }, + { "order_id", data.json.orderId }, + { "currency", product.metadata.isoCurrencyCode }, + { "price", product.metadata.localizedPrice.ToString() }, + { "purchase_token", data.json.purchaseToken }, + { "payment_method", "googleplay" } + }; + if (!_productArgs.ContainsKey(data.json.productId)) + { + _productArgs.Add(data.json.productId, args); + } + else + { + _productArgs[data.json.productId] = args; + } + } + catch (Exception e) { } + } + } + } + } + } + catch (Exception exp) { } + } + } +} + +#endif diff --git a/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs.meta b/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs.meta new file mode 100644 index 0000000..d7f752c --- /dev/null +++ b/Assets/Script/SDKManager/Purchase/IAPSubscribeManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1856159555b2343c1a0d38d88d54af66 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Script/SDKManager/Purchase/Server/ServerMgr.cs b/Assets/Script/SDKManager/Purchase/Server/ServerMgr.cs index 9e180e3..c8f322e 100644 --- a/Assets/Script/SDKManager/Purchase/Server/ServerMgr.cs +++ b/Assets/Script/SDKManager/Purchase/Server/ServerMgr.cs @@ -152,7 +152,7 @@ namespace WZ var builder = new StringBuilder(); foreach (var t in hashBytes) { - builder.Append(t.ToString("x2")); // Convert byte to hexadecimal string + builder.Append(t.ToString("x2")); } return builder.ToString(); diff --git a/Assets/Script/SDKManager/RushSDKManager.cs b/Assets/Script/SDKManager/RushSDKManager.cs index 9a39fe6..8efc229 100644 --- a/Assets/Script/SDKManager/RushSDKManager.cs +++ b/Assets/Script/SDKManager/RushSDKManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using AdjustSdk; using AnyThinkAds.ThirdParty.LitJson; using EFSDK; @@ -30,6 +31,9 @@ public class RushSDKManager : D_MonoSingleton public void InitializeSdk(Action action, bool showLog) { LoggerUtils.Enabled = showLog; +#if UNITY_PURCHASE + IAPPurchaseManager.Instance.PreInitialize(); +#endif FireBaseSDKManager.Instance.Init(); ShuShuMangage.Instance.Init(); AdmobAdsManager.Instance.RefreshAdsData(); @@ -37,6 +41,10 @@ public class RushSDKManager : D_MonoSingleton AdjustManager.Instance.Init(); AdsSDKManager.Instance.InitSDK(action); EFSdkManager.Instance.Init(); +#if UNITY_PURCHASE + IAPPurchaseManager.Instance.Initialize(); +#endif + } #if UNITY_PURCHASE @@ -75,6 +83,83 @@ public class RushSDKManager : D_MonoSingleton { OnPurchaseComplete = _action; } + + /// + /// 订阅查询回调 + /// + public Action OnSubscriptionQueriedByProductId; + public void QuerySubscriptionDataByProductId(string _pID,Action _action) + { + OnSubscriptionQueriedByProductId = _action; + IAPSubscribeManager.Instance.CheckSubscribeDataByProductId(_pID); + } + + /// + /// 获取商品价格 + /// + /// + /// + public string GetProductPriceByID(string _pID) + { + return IAPPurchaseManager.Instance.GetProductPriceByID(_pID); + } + + /// + /// 获取商品信息 + /// + /// + /// + public Product GetProductInfoByID(string _pID) + { + return IAPPurchaseManager.Instance.GetProductInfoByID(_pID); + } + + /// + /// 动态添加商品ID + /// + /// Product IDs + public void AddProductsDynamic(Dictionary _products,Action _onProductsResult = null) + { + IAPPurchaseManager.Instance.AddProductsDynamic(_products,_onProductsResult); + } + + /// + /// 初始化前静态添加商品ID + /// + /// Product IDs + public void AddProductsStatic(Dictionary _products) + { + IAPPurchaseManager.StaticProductDic = IAPPurchaseManager.StaticProductDic.Concat(_products).ToDictionary(postParK => postParK.Key, PostParV => PostParV.Value); + } + + /// + /// 点击购买方法 + /// + /// 商品SKU + /// 商品名称 + /// 游戏拓展参数 + public void PurchaseProductById(string _productId, string _productName, string _gameExtraParam = "") + { + IAPPurchaseManager.Instance.BuyProductByID(_productId, _productName,_gameExtraParam); + } + + /// + /// 游戏下发奖励后上报 + /// + /// 商品名称 + /// 商品SKU ID + /// 订单ID + /// 游戏拓展字段-购买商品数量 + /// 游戏拓展字段 + public void LogCheckingOrder(string _productName, string _productId, string _orderId, string gameExtra01, string gameExtra02) + { + +#if !UNITY_EDITOR + IAPOrderManager.Instance.RemoveVerifySuccessOrder(_orderId); + IAPPurchaseManager.Instance.DoConfirmPendingPurchaseByID(_productId); + IAPEvent.LogChecingOrderBySdk(_productName, _productId, _orderId, gameExtra01, gameExtra02); + #endif + } #endregion #endif