Exemple #1
0
    //解析原生返回数据
    public static void ResolverForNativeMsg(string content)
    {
        // Debug.Log($"ResolverForNativeMsg::{content}");
        NativeMessage  nativeMessage = JsonHelper.FromJson <NativeMessage>(content);
        NativeCallType type          = (NativeCallType)nativeMessage.type;

        switch (type)
        {
        case NativeCallType.GetSafeArea:
            //适配刘海屏
            SafeArea safeArea = JsonHelper.FromJson <SafeArea>(nativeMessage.content);
            NativeManager.Instance.safeArea = safeArea;
            break;

        case NativeCallType.AwakeByURL:
            //URL唤醒
            string awakeContent = nativeMessage.content;
            // Debug.Log($"游戏被唤起,参数为:{awakeContent}");
            Game.Hotfix.OnAwakeByURL?.Invoke(awakeContent);
            break;

        case NativeCallType.GetGPS:
            //获取GPS定位
            GPSInfo gPSInfo = JsonHelper.FromJson <GPSInfo>(nativeMessage.content);
            // Debug.Log($"获取GPS信息返回:statue={gPSInfo.status},lan={gPSInfo.latitude},long={gPSInfo.longitude},name={gPSInfo.locationName}");
            Game.Hotfix.OnGetGPS?.Invoke(string.Format("{0},{1},{2},{3}", gPSInfo.status, gPSInfo.longitude, gPSInfo.latitude, gPSInfo.locationName));
            break;

        case NativeCallType.TakeHeadImage:
            //获取头像图片路径
            // Debug.Log("ongetHead");
            Game.Hotfix.OnGetHeadImagePath?.Invoke(nativeMessage.content);
            break;

        case NativeCallType.InAppPurchase:
            InAppPurchaseInfo purchaseInfo = JsonHelper.FromJson <InAppPurchaseInfo>(nativeMessage.content);
            Game.Hotfix.OnInAppPurchaseCallBack?.Invoke(string.Format("{0},{1},{2},{3},{4}", purchaseInfo.status, purchaseInfo.productId, purchaseInfo.orderId, purchaseInfo.transactionId, purchaseInfo.receiptData));
            break;

        case NativeCallType.IMMes:
            Game.Hotfix.OnGroupMes?.Invoke(nativeMessage.content);
            break;

        case NativeCallType.IMOpearteMes:
            Game.Hotfix.OnOpearteMes?.Invoke(nativeMessage.content);
            break;

        case NativeCallType.IMServerMes:
            Game.Hotfix.OnServerMes?.Invoke(nativeMessage.content);
            break;

        case NativeCallType.EMULATORINFO:
            Game.Hotfix.OnEmulatorInfo?.Invoke(nativeMessage.content);
            break;

        default:
            Debug.Log($"error nativeMessage.type {nativeMessage.type} content = {nativeMessage.content}");
            break;
        }
    }
        public unsafe void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
        {
                        #if !IOS_DISABLE_APPLE_IAP
            if (callback == null)
            {
                return;
            }

            byte **ptr = GetInAppPurchaseProductInfo(native);
            if (ptr == (byte **)0)
            {
                callback(null, false);
                return;
            }

            var products = new List <InAppPurchaseInfo>();
            while (ptr[0] != (byte *)0)
            {
                string id = Marshal.PtrToStringAnsi(new IntPtr(ptr[0]));
                ptr++;

                string price = Marshal.PtrToStringAnsi(new IntPtr(ptr[0]));
                ptr++;

                var product = new InAppPurchaseInfo()
                {
                    ID             = id,
                    FormattedPrice = price
                };
                products.Add(product);
            }

            callback(products.ToArray(), true);
                        #endif
        }
        public void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
        {
            if (callback == null)
            {
                return;
            }

            var priceInfos = new List <InAppPurchaseInfo>();

            foreach (var iapID in InAppIDs)
            {
                int    id          = Common.getpid();
                string windowGroup = id.ToString();
                uint   reqID       = 0;
                if (paymentservice_get_price(iapID.ID, iapID.ID, windowGroup, ref reqID) != 0)
                {
                    callback(null, false);
                    return;
                }

                // wait for event
                while (true)
                {
                    IntPtr _event = IntPtr.Zero;
                    Common.bps_get_event(ref _event, -1);                    // wait here for next event
                    if (_event != IntPtr.Zero)
                    {
                        if (paymentservice_get_domain() == Common.bps_event_get_domain(_event))
                        {
                            if (paymentservice_event_get_response_code(_event) == 0)
                            {
                                IntPtr pricePtr = paymentservice_event_get_price(_event);
                                string price    = Marshal.PtrToStringAnsi(pricePtr);
                                var    product  = new InAppPurchaseInfo()
                                {
                                    ID             = iapID.ID,
                                    FormattedPrice = price
                                };
                                priceInfos.Add(product);
                            }
                            else
                            {
                                IntPtr errorPtr = paymentservice_event_get_error_text(_event);
                                Debug.LogError(Marshal.PtrToStringAnsi(errorPtr));
                                callback(null, false);
                                return;
                            }

                            break;
                        }
                    }
                }
            }

            callback(priceInfos.ToArray(), priceInfos.Count != 0);
        }
        public void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
        {
            if (callback != null)
            {
                var infos = new InAppPurchaseInfo[InAppIDs.Length];
                for (int i = 0; i != infos.Length; ++i)
                {
                    infos[i] = new InAppPurchaseInfo()
                    {
                        ID             = InAppIDs[i].ID,
                        FormattedPrice = InAppIDs[i].CurrencySymbol + InAppIDs[i].Price
                    };
                }

                callback(infos, true);
            }
        }
		public void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
		{
			if (callback != null)
			{
				var infos = new InAppPurchaseInfo[InAppIDs.Length];
				for (int i = 0; i != infos.Length; ++i)
				{
					infos[i] = new InAppPurchaseInfo()
					{
						ID = InAppIDs[i].ID,
						FormattedPrice = InAppIDs[i].CurrencySymbol + InAppIDs[i].Price
					};
				}

				callback(infos, true);
			}
		}
        public void Update()
        {
            // check if init done
            int status = native.CallStatic <int>("CheckInitStatus");

            if (status != 0 && createdCallback != null)
            {
                createdCallback(status == 1);
            }

            // check product callbacks
            if (native.CallStatic <bool>("CheckProductInfoDone"))
            {
                var skus = native.CallStatic <string[]>("GetProductInfoItems");
                if (skus == null || skus.Length == 0)
                {
                    productInfoCallback(null, false);
                }
                else
                {
                    var products = new List <InAppPurchaseInfo>();
                    for (int i = 0; i != skus.Length; i += 2)
                    {
                        var product = new InAppPurchaseInfo()
                        {
                            ID             = skus[i],
                            FormattedPrice = skus[i + 1]
                        };
                        products.Add(product);
                    }

                    productInfoCallback(products.ToArray(), true);
                }
            }

            // check restore callbacks
            if (native.CallStatic <bool>("CheckRestoreDone"))
            {
                var skus = native.CallStatic <string[]>("GetRestoreItems");
                foreach (var inAppID in InAppIDs)
                {
                    bool success = false;
                    foreach (var sku in skus)
                    {
                        if (sku == inAppID.ID)
                        {
                            success = true;
                            break;
                        }
                    }

                    restoreCallback(inAppID.ID, success);
                }
            }

            // check buy callbacks
            if (native.CallStatic <bool>("CheckBuyDone"))
            {
                if (purchasedCallback != null)
                {
                    purchasedCallback(buyInAppID, native.CallStatic <string>("GetBuyReceipt"), native.CallStatic <bool>("CheckBuySuccess"));
                }
            }
        }
Exemple #7
0
        public async void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
        {
            if (callback == null)
            {
                return;
            }
            var infos = new List <InAppPurchaseInfo>();

            try
            {
                                #if WINDOWS_PHONE
                if (testing)
                {
                    var listingInfo = wp8TestListingInformation;
                    foreach (var l in listingInfo.ProductListings)
                    {
                        var info = new InAppPurchaseInfo()
                        {
                            ID             = l.Value.ProductId,
                            FormattedPrice = l.Value.FormattedPrice
                        };
                        infos.Add(info);
                    }
                }
                else
                {
                    var listingInfo = await CurrentApp.LoadListingInformationAsync();

                    foreach (var l in listingInfo.ProductListings)
                    {
                        var info = new InAppPurchaseInfo()
                        {
                            ID             = l.Value.ProductId,
                            FormattedPrice = l.Value.FormattedPrice
                        };
                        infos.Add(info);
                    }
                }
                                #else
                ListingInformation listingInfo;
                if (testing)
                {
                    listingInfo = await CurrentAppSimulator.LoadListingInformationAsync();
                }
                else
                {
                    listingInfo = await CurrentApp.LoadListingInformationAsync();
                }
                foreach (var l in listingInfo.ProductListings)
                {
                    var info = new InAppPurchaseInfo()
                    {
                        ID             = l.Value.ProductId,
                        FormattedPrice = l.Value.FormattedPrice
                    };
                    infos.Add(info);
                }
                                #endif

                callback(infos.ToArray(), true);
            }
            catch (Exception e)
            {
                Debug.LogError(e.Message);
                callback(null, false);
            }
        }
		public void Update()
		{
			// check if init done
			int status = native.CallStatic<int>("CheckInitStatus");
			if (status != 0 && createdCallback != null) createdCallback(status == 1);

			// check product callbacks
			if (native.CallStatic<bool>("CheckProductInfoDone"))
			{
				var skus = native.CallStatic<string[]>("GetProductInfoItems");
				if (skus == null || skus.Length == 0)
				{
					productInfoCallback(null, false);
				}
				else
				{
					var products = new List<InAppPurchaseInfo>();
					for (int i = 0; i != skus.Length; i += 2)
					{
						var product = new InAppPurchaseInfo()
						{
							ID = skus[i],
							FormattedPrice = skus[i+1]
						};
						products.Add(product);
					}

					productInfoCallback(products.ToArray(), true);
				}
			}

			// check restore callbacks
			if (native.CallStatic<bool>("CheckRestoreDone"))
			{
				var skus = native.CallStatic<string[]>("GetRestoreItems");
				foreach (var inAppID in InAppIDs)
				{
					bool success = false;
					foreach (var sku in skus)
					{
						if (sku == inAppID.ID)
						{
							success = true;
							break;
						}
					}
					
					restoreCallback(inAppID.ID, success);
				}
			}

			// check buy callbacks
			if (native.CallStatic<bool>("CheckBuyDone"))
			{
				if (purchasedCallback != null) purchasedCallback(buyInAppID, native.CallStatic<string>("GetBuyReceipt"), native.CallStatic<bool>("CheckBuySuccess"));
			}
		}
		public unsafe void GetProductInfo (InAppPurchaseGetProductInfoCallbackMethod callback)
		{
			if (callback == null) return;

			byte** ptr = GetInAppPurchaseProductInfo(native);
			if (ptr == (byte**)0)
			{
				callback(null, false);
				return;
			}

			var products = new List<InAppPurchaseInfo>();
			while (ptr[0] != (byte*)0)
			{
				string id = Marshal.PtrToStringAnsi(new IntPtr(ptr[0]));
				ptr++;

				string price = Marshal.PtrToStringAnsi(new IntPtr(ptr[0]));
				ptr++;

				var product = new InAppPurchaseInfo()
				{
					ID = id,
					FormattedPrice = price
				};
				products.Add(product);
			}

			callback(products.ToArray(), true);
		}
		public async void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
		{
			if (callback == null) return;

			#if WINDOWS_PHONE
			WinRTPlugin.Dispatcher.BeginInvoke(async delegate()
			#else
			await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
			#endif
			{
				var infos = new List<InAppPurchaseInfo>();
				try
				{
					#if WINDOWS_PHONE
					if (testing)
					{
						var listingInfo = wp8TestListingInformation;
						foreach (var l in listingInfo.ProductListings)
						{
							var info = new InAppPurchaseInfo()
							{
								ID = l.Value.ProductId,
								FormattedPrice = l.Value.FormattedPrice
							};
							infos.Add(info);
						}
					}
					else
					{
						var listingInfo = await CurrentApp.LoadListingInformationAsync();
						foreach (var l in listingInfo.ProductListings)
						{
							var info = new InAppPurchaseInfo()
							{
								ID = l.Value.ProductId,
								FormattedPrice = l.Value.FormattedPrice
							};
							infos.Add(info);
						}
					}
					#else
					ListingInformation listingInfo;
					if (testing) listingInfo = await CurrentAppSimulator.LoadListingInformationAsync();
					else listingInfo = await CurrentApp.LoadListingInformationAsync();
					foreach (var l in listingInfo.ProductListings)
					{
						var info = new InAppPurchaseInfo()
						{
							ID = l.Value.ProductId,
							FormattedPrice = l.Value.FormattedPrice
						};
						infos.Add(info);
					}
					#endif

					ReignServices.InvokeOnUnityThread(delegate
					{
						callback(infos.ToArray(), true);
					});
				}
				catch (Exception e)
				{
					Debug.LogError(e.Message);
					ReignServices.InvokeOnUnityThread(delegate
					{
						callback(null, false);
					});
				}
			});
		}
        public async void GetProductInfo(InAppPurchaseGetProductInfoCallbackMethod callback)
        {
            if (callback == null)
            {
                return;
            }

                        #if WINDOWS_PHONE
            WinRTPlugin.Dispatcher.BeginInvoke(async delegate()
                        #else
            await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
                        #endif
            {
                var infos = new List <InAppPurchaseInfo>();
                try
                {
                                        #if WINDOWS_PHONE
                    if (testing)
                    {
                        var listingInfo = wp8TestListingInformation;
                        foreach (var l in listingInfo.ProductListings)
                        {
                            var info = new InAppPurchaseInfo()
                            {
                                ID             = l.Value.ProductId,
                                FormattedPrice = l.Value.FormattedPrice
                            };
                            infos.Add(info);
                        }
                    }
                    else
                    {
                        var listingInfo = await CurrentApp.LoadListingInformationAsync();
                        foreach (var l in listingInfo.ProductListings)
                        {
                            var info = new InAppPurchaseInfo()
                            {
                                ID             = l.Value.ProductId,
                                FormattedPrice = l.Value.FormattedPrice
                            };
                            infos.Add(info);
                        }
                    }
                                        #else
                    ListingInformation listingInfo;
                    if (testing)
                    {
                        listingInfo = await CurrentAppSimulator.LoadListingInformationAsync();
                    }
                    else
                    {
                        listingInfo = await CurrentApp.LoadListingInformationAsync();
                    }
                    foreach (var l in listingInfo.ProductListings)
                    {
                        var info = new InAppPurchaseInfo()
                        {
                            ID             = l.Value.ProductId,
                            FormattedPrice = l.Value.FormattedPrice
                        };
                        infos.Add(info);
                    }
                                        #endif

                    ReignServices.InvokeOnUnityThread(delegate
                    {
                        callback(infos.ToArray(), true);
                    });
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                    ReignServices.InvokeOnUnityThread(delegate
                    {
                        callback(null, false);
                    });
                }
            });
        }
		public void GetProductInfo (InAppPurchaseGetProductInfoCallbackMethod callback)
		{
			if (callback == null) return;

			var priceInfos = new List<InAppPurchaseInfo>();
			foreach (var iapID in InAppIDs)
			{
				int id = Common.getpid();
				string windowGroup = id.ToString();
				uint reqID = 0;
				if (paymentservice_get_price(iapID.ID, iapID.ID, windowGroup, ref reqID) != 0)
				{
					callback(null, false);
					return;
				}

				// wait for event
				while (true)
				{
					IntPtr _event = IntPtr.Zero;
					Common.bps_get_event(ref _event, -1);// wait here for next event
					if (_event != IntPtr.Zero)
					{
						if (paymentservice_get_domain() == Common.bps_event_get_domain(_event))
						{
							if (paymentservice_event_get_response_code(_event) == 0)
							{
								IntPtr pricePtr = paymentservice_event_get_price(_event);
								string price = Marshal.PtrToStringAnsi(pricePtr);
								var product = new InAppPurchaseInfo()
								{
									ID = iapID.ID,
									FormattedPrice = price
								};
								priceInfos.Add(product);
							}
							else
							{
								IntPtr errorPtr = paymentservice_event_get_error_text(_event);
								Debug.LogError(Marshal.PtrToStringAnsi(errorPtr));
								callback(null, false);
								return;
							}

							break;
						}
					}
				}
			}

			callback(priceInfos.ToArray(), priceInfos.Count != 0);
		}