gfg 1 年之前
父節點
當前提交
ed8c35b61d

+ 67 - 1
GameClient/Assets/Game/HotUpdate/Platform/QDAppStore.cs

@@ -15,24 +15,88 @@ namespace GFGGame
             IAPManager.Instance.Pay(buyID, count, orderID, Price);
         }
 
+
+        public static void OnEnterGame()
+        {
+            IAPManager.Instance.CheckOrderToDo();
+        }
     }
 
     public class IAPManager : SingletonBase<IAPManager>, IStoreListener
     {
         IStoreController m_StoreController; // The Unity Purchasing system.
+        private string OrderId
+        {
+            get
+            {
+                return PlayerPrefs.GetString(OrderIdLocalkey, null);
+            }
+            set
+            {
+                PlayerPrefs.SetString(OrderIdLocalkey, value);
+            }
+        }
+        private string TransactionId
+        {
+            get
+            {
+                return PlayerPrefs.GetString(TransactionIdLocalkey, null);
+            }
+            set
+            {
+                PlayerPrefs.SetString(TransactionIdLocalkey, value);
+            }
+        }
+
+        private string OrderIdLocalkey
+        {
+            get { return RoleDataManager.roleId + "OrderId"; }
+        }
+
+        private string TransactionIdLocalkey
+        {
+            get { return RoleDataManager.roleId + "transactionID"; }
+        }
+
+        public void CheckOrderToDo()
+        {
+            if (!string.IsNullOrEmpty(this.OrderId) && !string.IsNullOrEmpty(this.TransactionId))
+            {
+                IOSRechargeSProxy.IosVerifyOrder(OrderId, this.TransactionId).Coroutine();
+            }
+        }
 
         public void Pay(int buyID, int count, string orderID, long Price)
         {
             Debug.Log($"Pay {buyID}");
+            if(!string.IsNullOrEmpty(this.OrderId))
+            {
+                PromptController.Instance.ShowFloatTextPrompt("有未完成的订单,请稍后再试!");
+                return;
+            }
+            this.OrderId = orderID;
             m_StoreController.InitiatePurchase(buyID + "");
         }
 
+        public void OnServerSuccess(string OrderId, string TransactionId)
+        {
+            this.OrderId = null;
+            this.TransactionId = null;
+            PlayerPrefs.DeleteKey(OrderIdLocalkey);
+            PlayerPrefs.DeleteKey(TransactionIdLocalkey);
+        }
+
         public void InitializePurchasing()
         {
             Debug.Log("InitializePurchasing");
 
             var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
-            builder.AddProduct("10001", ProductType.Consumable);
+
+            var dataArray = ShopCfgArray.Instance.dataArray;
+            foreach(var shopCfg in dataArray)
+            {
+                builder.AddProduct(shopCfg.id + "", ProductType.Consumable);
+            }
 
             UnityPurchasing.Initialize(this, builder);
         }
@@ -60,6 +124,8 @@ namespace GFGGame
             //Retrieve the purchased product
             var product = args.purchasedProduct;
             Debug.Log($"Purchase Complete - Product: {product.definition.id}");
+            this.TransactionId = product.transactionID;
+            IOSRechargeSProxy.IosVerifyOrder(OrderId, product.transactionID).Coroutine();
 
             //We return Complete, informing IAP that the processing on our side is done and the transaction can be closed.
             return PurchaseProcessingResult.Complete;

+ 3 - 0
GameClient/Assets/Game/HotUpdate/Platform/QDManager.cs

@@ -49,6 +49,9 @@
         {
             switch (LauncherConfig.ChannelId)
             {
+                case (int)ChannelID.AppStore:
+                    QDAppStore.OnEnterGame();
+                    break;
                 default:
 
                     break;

+ 20 - 3
GameClient/Assets/Game/HotUpdate/ServerProxy/IOSRechargeSProxy.cs

@@ -1,7 +1,24 @@
-using System;
-public class IOSRechargeSProxy
+using ET;
+
+namespace GFGGame
 {
-    public static void IosVerifyOrder()
+    public class IOSRechargeSProxy
     {
+        public static async ETTask IosVerifyOrder(string OrderId, string TransactionId)
+        {
+            S2C_IosVerifyOrder response = (S2C_IosVerifyOrder)await MessageHelper.SendToServer(new C2S_IosVerifyOrder()
+            {
+                OrderId = OrderId,
+                TransactionId = TransactionId
+            });
+            if(response != null)
+            {
+                if(response.Error == ErrorCode.ERR_Success)
+                {
+                    IAPManager.Instance.OnServerSuccess(response.OrderId, response.TransactionId);
+                }
+            }
+        }
     }
+
 }