Update: 新增保存收据的功能
parent
9936809321
commit
09cf293d2e
|
|
@ -1,5 +1,6 @@
|
||||||
|
|
||||||
using UnityEngine.Networking;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Guru
|
namespace Guru
|
||||||
{
|
{
|
||||||
|
|
@ -30,6 +31,8 @@ namespace Guru
|
||||||
public int b_level = 0;
|
public int b_level = 0;
|
||||||
public int b_play = 0;
|
public int b_play = 0;
|
||||||
public int buy_count = 0;
|
public int buy_count = 0;
|
||||||
|
|
||||||
|
public List<PurchasedProduct> purchased;
|
||||||
//-------------- data ---------------
|
//-------------- data ---------------
|
||||||
|
|
||||||
private float _lastSavedTime = 0;
|
private float _lastSavedTime = 0;
|
||||||
|
|
@ -144,6 +147,8 @@ namespace Guru
|
||||||
_totalPlayed = new BindableProperty<int>(b_play, OnPlayedChanged);
|
_totalPlayed = new BindableProperty<int>(b_play, OnPlayedChanged);
|
||||||
_purchasedCount = new BindableProperty<int>(buy_count, OnPurchasedNumChanged);
|
_purchasedCount = new BindableProperty<int>(buy_count, OnPurchasedNumChanged);
|
||||||
_uid = new BindableProperty<string>(uid, OnUidChanged);
|
_uid = new BindableProperty<string>(uid, OnUidChanged);
|
||||||
|
|
||||||
|
purchased = new List<PurchasedProduct>(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -210,6 +215,71 @@ namespace Guru
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 订单记录
|
||||||
|
|
||||||
|
|
||||||
|
public bool HasPurchasedProduct(string receipt)
|
||||||
|
{
|
||||||
|
if(purchased == null || purchased.Count == 0) return false;
|
||||||
|
return purchased.Exists(p => p.receipt == receipt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加已支付订单
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="receipt"></param>
|
||||||
|
/// <param name="productName"></param>
|
||||||
|
/// <param name="productId"></param>
|
||||||
|
public void AddReceipt(string receipt, string productName, string productId, bool appleProductIsRestored = false)
|
||||||
|
{
|
||||||
|
if (purchased == null) purchased = new List<PurchasedProduct>(20);
|
||||||
|
if (!HasPurchasedProduct(receipt))
|
||||||
|
{
|
||||||
|
purchased.Add(new PurchasedProduct()
|
||||||
|
{
|
||||||
|
receipt = receipt,
|
||||||
|
productName = productName,
|
||||||
|
productId = productId,
|
||||||
|
appleProductIsRestored = appleProductIsRestored
|
||||||
|
});
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] GetReceipts(string productName)
|
||||||
|
{
|
||||||
|
int count = purchased?.Count ?? 0;
|
||||||
|
if (count == 0) count = 20;
|
||||||
|
if (purchased == null) purchased = new List<PurchasedProduct>(count);
|
||||||
|
var receipts = new List<string>(count);
|
||||||
|
receipts.AddRange(from purchasedProduct in purchased where purchasedProduct.productName == productName select purchasedProduct.receipt);
|
||||||
|
return receipts.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string[] GetReceiptsById(string productId)
|
||||||
|
{
|
||||||
|
int count = purchased?.Count ?? 0;
|
||||||
|
if (count == 0) count = 20;
|
||||||
|
if (purchased == null) purchased = new List<PurchasedProduct>(count);
|
||||||
|
var receipts = new List<string>(count);
|
||||||
|
receipts.AddRange(from purchasedProduct in purchased where purchasedProduct.productId == productId select purchasedProduct.receipt);
|
||||||
|
return receipts.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal class PurchasedProduct
|
||||||
|
{
|
||||||
|
public string productName;
|
||||||
|
public string productId;
|
||||||
|
public string receipt;
|
||||||
|
public bool appleProductIsRestored;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -218,6 +288,4 @@ namespace Guru
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ namespace Guru
|
||||||
GuruIAP.Instance.OnBuyStart += OnBuyStart;
|
GuruIAP.Instance.OnBuyStart += OnBuyStart;
|
||||||
GuruIAP.Instance.OnBuyEnd += OnBuyEnd;
|
GuruIAP.Instance.OnBuyEnd += OnBuyEnd;
|
||||||
GuruIAP.Instance.OnBuyFailed += OnBuyFailed;
|
GuruIAP.Instance.OnBuyFailed += OnBuyFailed;
|
||||||
|
GuruIAP.Instance.OnGetProductReceipt += OnGetReceipt;
|
||||||
|
|
||||||
GuruIAP.Instance.InitWithKeys(googleKey, appleRootCerts, IsDebugMode);
|
GuruIAP.Instance.InitWithKeys(googleKey, appleRootCerts, IsDebugMode);
|
||||||
}
|
}
|
||||||
|
|
@ -181,5 +182,16 @@ namespace Guru
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Receipt
|
||||||
|
|
||||||
|
|
||||||
|
private static void OnGetReceipt(string productId, string receipt, bool appleProductIsRestored = false)
|
||||||
|
{
|
||||||
|
var productName = GetProductSettingById(productId).ProductName;
|
||||||
|
Model.AddReceipt(receipt, productName, productId, appleProductIsRestored);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue